KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > dig > DIGQueryIsIndividualTranslator


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email Ian.Dickinson@hp.com
6  * Package Jena 2
7  * Web http://sourceforge.net/projects/jena/
8  * Created July 19th 2003
9  * Filename $RCSfile: DIGQueryIsIndividualTranslator.java,v $
10  * Revision $Revision: 1.5 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/03/16 18:52:27 $
14  * by $Author: ian_dickinson $
15  *
16  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * [See end of file]
18  * ****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.reasoner.dig;
23
24
25 // Imports
26
///////////////
27
import java.util.*;
28
29 import org.w3c.dom.Document JavaDoc;
30
31 import com.hp.hpl.jena.graph.Node;
32 import com.hp.hpl.jena.graph.Node_Concrete;
33 import com.hp.hpl.jena.rdf.model.Model;
34 import com.hp.hpl.jena.reasoner.TriplePattern;
35 import com.hp.hpl.jena.util.iterator.*;
36 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
37 import com.hp.hpl.jena.vocabulary.RDF;
38
39
40 /**
41  * <p>
42  * Translator that generates a DIG query to test whether a ground name is an individual atom
43  * <pre>
44  * x rdf:type owl:Thing, or
45  * x rdf:type y /\ isConcept( y )
46  * </pre>
47  * or similar.
48  * </p>
49  *
50  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
51  * @version Release @release@ ($Id: DIGQueryIsIndividualTranslator.java,v 1.5 2005/03/16 18:52:27 ian_dickinson Exp $)
52  */

53 public class DIGQueryIsIndividualTranslator
54     extends DIGQueryTranslator
55 {
56
57     // Constants
58
//////////////////////////////////
59

60     // Static variables
61
//////////////////////////////////
62

63     // Instance variables
64
//////////////////////////////////
65

66     // Constructors
67
//////////////////////////////////
68

69     /**
70      * <p>Construct a translator for the DIG for an individual name.</p>
71      */

72     public DIGQueryIsIndividualTranslator() {
73         super( null, RDF.type.getURI(), null );
74     }
75     
76
77     // External signature methods
78
//////////////////////////////////
79

80
81     /**
82      * <p>Since known concept names are cached by the adapter, we can just look up the
83      * current set and map directly to triples</p>
84      * @param pattern The pattern to translate to a DIG query
85      * @param da The DIG adapter through which we communicate with a DIG reasoner
86      */

87     public ExtendedIterator find( TriplePattern pattern, DIGAdapter da ) {
88         List result = new ArrayList();
89         if (da.isIndividual( pattern.getSubject() )) {
90             result.add( pattern.asTriple() );
91         }
92         
93         return WrappedIterator.create( result.iterator() );
94     }
95     
96     
97     /** For this translation, we ignore premises */
98     public ExtendedIterator find( TriplePattern pattern, DIGAdapter da, Model premises ) {
99         return find( pattern, da );
100     }
101     
102     
103     public Document JavaDoc translatePattern( TriplePattern pattern, DIGAdapter da ) {
104         // not used
105
return null;
106     }
107
108
109     public Document JavaDoc translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) {
110         // not used
111
return null;
112     }
113
114     public ExtendedIterator translateResponseHook( Document JavaDoc response, TriplePattern query, DIGAdapter da ) {
115         // not used
116
return null;
117     }
118
119     /**
120      * <p>Additional test on the object of the incoming find pattern.</p>
121      * @param object The object resource from the incoming pattern
122      * @param da The current dig adapter
123      * @param premises A model that conveys additional information about the premises
124      * of the query, which might assist the check to suceed or fail. By default it
125      * is ignored.
126      * @return True if this object matches the trigger condition expressed by this translator instance
127      */

128     public boolean checkObject( Node object, DIGAdapter da, Model premises ) {
129         return da.getOntLanguage().THING().getNode().equals( object ) ||
130                da.isConcept( object, premises );
131     }
132     
133
134     public boolean checkSubject( Node subject, DIGAdapter da, Model premises ) {
135         return subject instanceof Node_Concrete;
136     }
137     
138     
139
140     // Internal implementation methods
141
//////////////////////////////////
142

143     //==============================================================================
144
// Inner class definitions
145
//==============================================================================
146

147 }
148
149
150 /*
151  * (c) Copyright 2001-2004, 2005 Hewlett-Packard Development Company, LP
152  * All rights reserved.
153  *
154  * Redistribution and use in source and binary forms, with or without
155  * modification, are permitted provided that the following conditions
156  * are met:
157  * 1. Redistributions of source code must retain the above copyright
158  * notice, this list of conditions and the following disclaimer.
159  * 2. Redistributions in binary form must reproduce the above copyright
160  * notice, this list of conditions and the following disclaimer in the
161  * documentation and/or other materials provided with the distribution.
162  * 3. The name of the author may not be used to endorse or promote products
163  * derived from this software without specific prior written permission.
164  *
165  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
166  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
167  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
168  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
169  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
170  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
171  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
172  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
173  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
174  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
175  */

176
Popular Tags