KickJava   Java API By Example, From Geeks To Geeks.

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


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: DIGQuerySubsumesTranslator.java,v $
10  * Revision $Revision: 1.10 $
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 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
33
34
35
36 /**
37  * <p>
38  * Translator that generates DIG allconcepts queries in response to a find query:
39  * <pre>
40  * :x rdf:subClassOf :y
41  * </pre>
42  * or similar.
43  * </p>
44  *
45  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
46  * @version CVS $Id: DIGQuerySubsumesTranslator.java,v 1.10 2005/03/16 18:52:27 ian_dickinson Exp $
47  */

48 public class DIGQuerySubsumesTranslator
49     extends DIGQueryTranslator
50 {
51
52     // Constants
53
//////////////////////////////////
54

55     // Static variables
56
//////////////////////////////////
57

58     // Instance variables
59
//////////////////////////////////
60

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

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

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

76
77     /**
78      * <p>Answer a query that will test subsumption between two classes</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         Element subsumes = da.createQueryElement( query, DIGProfile.SUBSUMES );
84         
85         // note reversal of subject-object: x rdfs:subClassOf y --> y dig:subsumes x
86
da.addClassDescription( subsumes, pattern.getObject() );
87         da.addClassDescription( subsumes, pattern.getSubject() );
88
89         return query;
90     }
91
92
93     /**
94      * <p>Answer a query that will test subsumption between two classes, given that either one
95      * or both may be defined as an expression given the premises</p>
96      */

97     public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) {
98         DIGConnection dc = da.getConnection();
99         Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() );
100         Element subsumes = da.createQueryElement( query, DIGProfile.SUBSUMES );
101         
102         // note reversal of subject-object: x rdfs:subClassOf y --> y dig:subsumes x
103
if (pattern.getObject().isBlank()) {
104             da.addClassDescription( subsumes, pattern.getObject(), premises );
105         }
106         else {
107             da.addClassDescription( subsumes, pattern.getObject() );
108         }
109         
110         if (pattern.getSubject().isBlank()) {
111             da.addClassDescription( subsumes, pattern.getSubject(), premises );
112         }
113         else {
114             da.addClassDescription( subsumes, pattern.getSubject() );
115         }
116         
117         return query;
118     }
119
120
121     /**
122      * <p>Answer an iterator of triples that match the original find query.</p>
123      */

124     public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) {
125         return isTrue( response ) ? (ExtendedIterator) new SingletonIterator( query.asTriple() ) : NullIterator.instance;
126     }
127     
128     public boolean checkSubject( com.hp.hpl.jena.graph.Node subject, DIGAdapter da, Model premises ) {
129         boolean isSubjectConcept = da.isConcept( subject, premises );
130         return isSubjectConcept;
131     }
132     
133     public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) {
134         boolean isObjectConcept = da.isConcept( object, premises );
135         return isObjectConcept;
136     }
137
138     // Internal implementation methods
139
//////////////////////////////////
140

141     //==============================================================================
142
// Inner class definitions
143
//==============================================================================
144

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

174
Popular Tags