KickJava   Java API By Example, From Geeks To Geeks.

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


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: DIGQueryRoleFillersTranslator.java,v $
10  * Revision $Revision: 1.9 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/03/16 18:52:28 $
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.rdf.model.Resource;
31 import com.hp.hpl.jena.reasoner.TriplePattern;
32 import com.hp.hpl.jena.util.iterator.*;
33 import com.hp.hpl.jena.vocabulary.*;
34 import com.hp.hpl.jena.vocabulary.RDF;
35
36
37
38 /**
39  * <p>
40  * Translator that generates DIG roleFillers queries in response to a find queries:
41  * <pre>
42  * :a :r *
43  * </pre>
44  * or similar.
45  * </p>
46  *
47  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
48  * @version CVS $Id: DIGQueryRoleFillersTranslator.java,v 1.9 2005/03/16 18:52:28 ian_dickinson Exp $
49  */

50 public class DIGQueryRoleFillersTranslator
51     extends DIGQueryTranslator
52 {
53
54     // Constants
55
//////////////////////////////////
56

57     // Static variables
58
//////////////////////////////////
59

60     // Instance variables
61
//////////////////////////////////
62

63     
64     // Constructors
65
//////////////////////////////////
66

67     /**
68      * <p>Construct a translator for the DIG query 'roleFillers'.</p>
69      */

70     public DIGQueryRoleFillersTranslator() {
71         super( null, null, ALL );
72     }
73     
74
75     // External signature methods
76
//////////////////////////////////
77

78
79     /**
80      * <p>Answer a query that will list the role fillers for an individual-role pair</p>
81      */

82     public Document translatePattern( TriplePattern pattern, DIGAdapter da ) {
83         DIGConnection dc = da.getConnection();
84         Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() );
85         
86         Element instances = da.createQueryElement( query, DIGProfile.ROLE_FILLERS );
87         da.addNamedElement( instances, DIGProfile.INDIVIDUAL, da.getNodeID( pattern.getSubject() ) );
88         da.addNamedElement( instances, DIGProfile.RATOM, da.getNodeID( pattern.getPredicate() ) );
89         
90         return query;
91     }
92
93
94     /**
95      * <p>Answer an iterator of triples that match the original find query.</p>
96      */

97     public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) {
98         // translate the concept set to triples, but then we must add :a rdfs:subClassOf :a to match owl semantics
99
return translateIndividualSetResponse( response, query, true );
100     }
101     
102     
103     public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) {
104         // not used
105
return null;
106     }
107
108     public boolean checkSubject( com.hp.hpl.jena.graph.Node subject, DIGAdapter da, Model premises ) {
109         return subject.isConcrete() && da.isIndividual( subject );
110     }
111
112     public boolean checkPredicate( com.hp.hpl.jena.graph.Node predicate, DIGAdapter da, Model premises ) {
113         // check that the predicate is not a datatype property
114
if (predicate.isConcrete()) {
115             Resource p = (Resource) da.m_sourceData.getRDFNode( predicate );
116             String JavaDoc pNS = p.getNameSpace();
117             return !(da.m_sourceData.contains( p, RDF.type, da.m_sourceData.getProfile().DATATYPE_PROPERTY() ) ||
118                      RDFS.getURI().equals( pNS ) ||
119                      RDF.getURI().equals( pNS ) ||
120                      OWL.getURI().equals( pNS ));
121         }
122         else {
123             return false;
124         }
125     }
126
127
128     // Internal implementation methods
129
//////////////////////////////////
130

131     //==============================================================================
132
// Inner class definitions
133
//==============================================================================
134

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

164
Popular Tags