001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email Ian.Dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created July 19th 2003
009: * Filename $RCSfile: DIGQueryIsIndividualTranslator.java,v $
010: * Revision $Revision: 1.9 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:07:12 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * [See end of file]
018: * ****************************************************************************/package com.hp.hpl.jena.reasoner.dig;
019:
020: // Imports
021: ///////////////
022: import java.util.*;
023:
024: import org.w3c.dom.Document;
025:
026: import com.hp.hpl.jena.graph.Node;
027: import com.hp.hpl.jena.graph.Node_Concrete;
028: import com.hp.hpl.jena.rdf.model.Model;
029: import com.hp.hpl.jena.reasoner.TriplePattern;
030: import com.hp.hpl.jena.util.iterator.*;
031: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
032: import com.hp.hpl.jena.vocabulary.RDF;
033:
034: /**
035: * <p>
036: * Translator that generates a DIG query to test whether a ground name is an individual atom
037: * <pre>
038: * x rdf:type owl:Thing, or
039: * x rdf:type y /\ isConcept( y )
040: * </pre>
041: * or similar.
042: * </p>
043: *
044: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
045: * @version Release @release@ ($Id: DIGQueryIsIndividualTranslator.java,v 1.9 2008/01/02 12:07:12 andy_seaborne Exp $)
046: */
047: public class DIGQueryIsIndividualTranslator extends DIGQueryTranslator {
048:
049: // Constants
050: //////////////////////////////////
051:
052: // Static variables
053: //////////////////////////////////
054:
055: // Instance variables
056: //////////////////////////////////
057:
058: // Constructors
059: //////////////////////////////////
060:
061: /**
062: * <p>Construct a translator for the DIG for an individual name.</p>
063: */
064: public DIGQueryIsIndividualTranslator() {
065: super (null, RDF.type.getURI(), null);
066: }
067:
068: // External signature methods
069: //////////////////////////////////
070:
071: /**
072: * <p>Since known concept names are cached by the adapter, we can just look up the
073: * current set and map directly to triples</p>
074: * @param pattern The pattern to translate to a DIG query
075: * @param da The DIG adapter through which we communicate with a DIG reasoner
076: */
077: public ExtendedIterator find(TriplePattern pattern, DIGAdapter da) {
078: List result = new ArrayList();
079: if (da.isIndividual(pattern.getSubject())) {
080: result.add(pattern.asTriple());
081: }
082:
083: return WrappedIterator.create(result.iterator());
084: }
085:
086: /** For this translation, we ignore premises */
087: public ExtendedIterator find(TriplePattern pattern, DIGAdapter da,
088: Model premises) {
089: return find(pattern, da);
090: }
091:
092: public Document translatePattern(TriplePattern pattern,
093: DIGAdapter da) {
094: // not used
095: return null;
096: }
097:
098: public Document translatePattern(TriplePattern pattern,
099: DIGAdapter da, Model premises) {
100: // not used
101: return null;
102: }
103:
104: public ExtendedIterator translateResponseHook(Document response,
105: TriplePattern query, DIGAdapter da) {
106: // not used
107: return null;
108: }
109:
110: /**
111: * <p>Additional test on the object of the incoming find pattern.</p>
112: * @param object The object resource from the incoming pattern
113: * @param da The current dig adapter
114: * @param premises A model that conveys additional information about the premises
115: * of the query, which might assist the check to suceed or fail. By default it
116: * is ignored.
117: * @return True if this object matches the trigger condition expressed by this translator instance
118: */
119: public boolean checkObject(Node object, DIGAdapter da,
120: Model premises) {
121: return da.getOntLanguage().THING().asNode().equals(object)
122: || da.isConcept(object, premises);
123: }
124:
125: public boolean checkSubject(Node subject, DIGAdapter da,
126: Model premises) {
127: return subject instanceof Node_Concrete;
128: }
129:
130: // Internal implementation methods
131: //////////////////////////////////
132:
133: //==============================================================================
134: // Inner class definitions
135: //==============================================================================
136:
137: }
138:
139: /*
140: * (c) Copyright 2001-2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
141: * All rights reserved.
142: *
143: * Redistribution and use in source and binary forms, with or without
144: * modification, are permitted provided that the following conditions
145: * are met:
146: * 1. Redistributions of source code must retain the above copyright
147: * notice, this list of conditions and the following disclaimer.
148: * 2. Redistributions in binary form must reproduce the above copyright
149: * notice, this list of conditions and the following disclaimer in the
150: * documentation and/or other materials provided with the distribution.
151: * 3. The name of the author may not be used to endorse or promote products
152: * derived from this software without specific prior written permission.
153: *
154: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
155: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
156: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
157: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
158: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
159: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
160: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
161: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
162: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
163: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
164: */
|