KickJava   Java API By Example, From Geeks To Geeks.

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


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 09-Dec-2003
9  * Filename $RCSfile: DIGQueryDisjointTranslator.java,v $
10  * Revision $Revision: 1.10 $
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 import java.util.*;
25 import java.util.List JavaDoc;
26
27 import org.w3c.dom.*;
28 import org.w3c.dom.Document 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.*;
33 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
34
35
36 // Imports
37
///////////////
38

39 /**
40  * <p>
41  * Translator for queries about the disjoint-ness of two ground concepts
42  * </p>
43  *
44  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
45  * @version CVS $Id: DIGQueryDisjointTranslator.java,v 1.10 2005/03/16 18:52:28 ian_dickinson Exp $
46  */

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

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

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

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

63     /**
64      * <p>Construct a translator to test whether two concepts are disjoint</p>
65      * @param predicate The predicate we are matching on
66      */

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

75     /**
76      * <p>Answer a query that will test disjointness between two classes</p>
77      */

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

92     public ExtendedIterator translateResponseHook( Document JavaDoc response, TriplePattern query, DIGAdapter da ) {
93         List JavaDoc answer = new ArrayList();
94         if (isTrue( response )) {
95             // if response is true, the subsumption relationship holds
96
answer.add( query.asTriple() );
97         }
98         
99         return WrappedIterator.create( answer.iterator() );
100     }
101     
102     public Document JavaDoc translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) {
103         return translatePattern( pattern, da );
104     }
105
106     public boolean checkSubject( com.hp.hpl.jena.graph.Node subject, DIGAdapter da, Model premises ) {
107         return da.isConcept( subject, premises );
108     }
109     
110     public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) {
111         return da.isConcept( object, premises );
112     }
113
114
115     // Internal implementation methods
116
//////////////////////////////////
117

118     //==============================================================================
119
// Inner class definitions
120
//==============================================================================
121

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

151
Popular Tags