KickJava   Java API By Example, From Geeks To Geeks.

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


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: DIGQueryRoleAncestorsTranslator.java,v $
10  * Revision $Revision: 1.8 $
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 role ancestors/desendants queries in response to a find queries:
38  * <pre>
39  * :X rdf:subPropertyOf *
40  * * rdf:subPropertyOf :X
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: DIGQueryRoleAncestorsTranslator.java,v 1.8 2005/03/16 18:52:27 ian_dickinson Exp $
47  */

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

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

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

61     /** Flag for querying for ancestors */
62     protected boolean m_ancestors;
63     
64     
65     // Constructors
66
//////////////////////////////////
67

68     /**
69      * <p>Construct a translator for the DIG query 'rparents'.</p>
70      * @param predicate The predicate URI to trigger on
71      * @param ancestors If true, we are searching for parents of the class; if false, the descendants
72      */

73     public DIGQueryRoleAncestorsTranslator( String JavaDoc predicate, boolean ancestors ) {
74         super( (ancestors ? null : ALL), predicate, (ancestors ? ALL : null) );
75         m_ancestors = ancestors;
76     }
77     
78
79     // External signature methods
80
//////////////////////////////////
81

82
83     /**
84      * <p>Answer a query that will generate the class hierachy for a concept</p>
85      */

86     public Document translatePattern( TriplePattern pattern, DIGAdapter da ) {
87         DIGConnection dc = da.getConnection();
88         Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() );
89         
90         if (m_ancestors) {
91             Element parents = da.createQueryElement( query, DIGProfile.RANCESTORS );
92             da.addClassDescription( parents, pattern.getSubject() );
93         }
94         else {
95             Element descendants = da.createQueryElement( query, DIGProfile.RDESCENDANTS );
96             da.addClassDescription( descendants, pattern.getObject() );
97         }
98         
99         return query;
100     }
101
102
103     /**
104      * <p>Answer an iterator of triples that match the original find query.</p>
105      */

106     public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) {
107         // translate the concept set to triples, but then we must add :a rdfs:subPropertyOf :a to match owl semantics
108
return translateRoleSetResponse( response, query, m_ancestors );
109     }
110     
111     
112     public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) {
113         // not used
114
return null;
115     }
116
117     public boolean checkSubject( com.hp.hpl.jena.graph.Node subject, DIGAdapter da, Model premises ) {
118         return !m_ancestors || da.isRole( subject, premises );
119     }
120     
121     public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) {
122         return m_ancestors || da.isRole( object, premises );
123     }
124
125
126     // Internal implementation methods
127
//////////////////////////////////
128

129     //==============================================================================
130
// Inner class definitions
131
//==============================================================================
132

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

162
Popular Tags