KickJava   Java API By Example, From Geeks To Geeks.

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


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 10-Dec-2003
9  * Filename $RCSfile: DIGQueryEquivalentsTranslator.java,v $
10  * Revision $Revision: 1.11 $
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.Document JavaDoc;
28 import org.w3c.dom.Element JavaDoc;
29
30 import com.hp.hpl.jena.rdf.model.Model;
31 import com.hp.hpl.jena.reasoner.TriplePattern;
32 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
33
34
35 /**
36  * <p>
37  * Translator to map owl:equivalentClass to the DIG &lt;equivalents&gt; query.
38  * </p>
39  *
40  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
41  * @version CVS $Id: DIGQueryEquivalentsTranslator.java,v 1.11 2005/03/16 18:52:27 ian_dickinson Exp $
42  */

43 public class DIGQueryEquivalentsTranslator
44     extends DIGQueryTranslator
45 {
46     // Constants
47
//////////////////////////////////
48

49     // Static variables
50
//////////////////////////////////
51

52     // Instance variables
53
//////////////////////////////////
54

55     /** Flag for whether the free variable is on the lhs or the rhs */
56     protected boolean m_subjectFree;
57
58
59     // Constructors
60
//////////////////////////////////
61

62     /**
63      * <p>Construct a translator for the DIG query 'equivalents'.</p>
64      * @param predicate The predicate URI to trigger on
65      * @param subjectFree If true, the free variable is the subject of the triple
66      */

67     public DIGQueryEquivalentsTranslator( String JavaDoc predicate, boolean subjectFree ) {
68         super( null, predicate, null );
69         m_subjectFree = subjectFree;
70     }
71
72
73     // External signature methods
74
//////////////////////////////////
75

76     /**
77      * <p>Answer a query that will generate the class hierachy for a concept</p>
78      */

79     public Document JavaDoc translatePattern( TriplePattern pattern, DIGAdapter da ) {
80         DIGConnection dc = da.getConnection();
81         Document JavaDoc query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() );
82
83         Element JavaDoc equivalents = da.createQueryElement( query, DIGProfile.EQUIVALENTS );
84         da.addClassDescription( equivalents, m_subjectFree ? pattern.getObject() : pattern.getSubject() );
85
86         return query;
87     }
88
89
90     /**
91      * <p>Answer an iterator of triples that match the original find query.</p>
92      */

93     public ExtendedIterator translateResponseHook( Document JavaDoc response, TriplePattern query, DIGAdapter da ) {
94         return translateConceptSetResponse( response, query, !m_subjectFree, da );
95     }
96
97     public Document JavaDoc translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) {
98         // not used
99
return null;
100     }
101
102
103     public boolean checkSubject( com.hp.hpl.jena.graph.Node subject, DIGAdapter da, Model premises ) {
104         return (m_subjectFree && !subject.isConcrete()) || da.isConcept( subject, premises );
105     }
106
107     public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) {
108         return (!m_subjectFree && !object.isConcrete()) || da.isConcept( object, premises );
109     }
110
111     public boolean checkTriple( TriplePattern pattern, DIGAdapter da, Model premises ) {
112         return super.checkTriple( pattern, da, premises ) &&
113                (!pattern.getSubject().isConcrete() || !pattern.getObject().isConcrete());
114
115     }
116
117     // Internal implementation methods
118
//////////////////////////////////
119

120     //==============================================================================
121
// Inner class definitions
122
//==============================================================================
123

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

153
Popular Tags