KickJava   Java API By Example, From Geeks To Geeks.

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


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: DIGQueryInstancesTranslator.java,v $
10  * Revision $Revision: 1.7 $
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 org.w3c.dom.*;
28
29 import com.hp.hpl.jena.rdf.model.Model;
30 import com.hp.hpl.jena.reasoner.TriplePattern;
31 import com.hp.hpl.jena.util.iterator.*;
32
33
34
35 /**
36  * <p>
37  * Translator that generates DIG instances queries in response to a find queries:
38  * <pre>
39  * * rdf:type :C
40  * </pre>
41  * or similar.
42  * </p>
43  *
44  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
45  * @version CVS $Id: DIGQueryInstancesTranslator.java,v 1.7 2005/03/16 18:52:27 ian_dickinson Exp $
46  */

47 public class DIGQueryInstancesTranslator
48     extends DIGQueryTranslator
49 {
50
51     // Constants
52
//////////////////////////////////
53

54     // Static variables
55
//////////////////////////////////
56

57     // Instance variables
58
//////////////////////////////////
59

60     
61     // Constructors
62
//////////////////////////////////
63

64     /**
65      * <p>Construct a translator for the DIG query 'instances'.</p>
66      * @param predicate The predicate URI to trigger on
67      */

68     public DIGQueryInstancesTranslator( String JavaDoc predicate ) {
69         super( ALL, predicate, null );
70     }
71     
72
73     // External signature methods
74
//////////////////////////////////
75

76
77     /**
78      * <p>Answer a query that will list the instances of a concept</p>
79      */

80     public Document translatePattern( TriplePattern pattern, DIGAdapter da ) {
81         DIGConnection dc = da.getConnection();
82         Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() );
83         
84         Element instances = da.createQueryElement( query, DIGProfile.INSTANCES );
85         da.addClassDescription( instances, pattern.getObject() );
86         
87         return query;
88     }
89
90     /**
91      * <p>Answer a query that will list the instances of a given concept, optionally defined
92      * as a class expression in the premises.</p>
93      */

94     public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) {
95         DIGConnection dc = da.getConnection();
96         Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() );
97         
98         Element instances = da.createQueryElement( query, DIGProfile.INSTANCES );
99         
100         if (pattern.getObject().isBlank()) {
101             da.addClassDescription( instances, pattern.getObject(), premises );
102         }
103         else {
104             da.addClassDescription( instances, pattern.getObject() );
105         }
106         
107         return query;
108     }
109
110     /**
111      * <p>Answer an iterator of triples that match the original find query.</p>
112      */

113     public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) {
114         // translate the concept set to triples, but then we must add :a rdfs:subClassOf :a to match owl semantics
115
return translateIndividualSetResponse( response, query, false );
116     }
117     
118     
119     public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) {
120         return da.isConcept( object, premises );
121     }
122
123
124     // Internal implementation methods
125
//////////////////////////////////
126

127     //==============================================================================
128
// Inner class definitions
129
//==============================================================================
130

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

160
Popular Tags