KickJava   Java API By Example, From Geeks To Geeks.

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


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: DIGQueryDifferentFromTranslator.java,v $
10  * Revision $Revision: 1.5 $
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 as to whether two ground individuals are different-from each other.
42  * This does not have a direct translation in DIG at the moment; instead we ask if the
43  * class expressions formed from the set of each single individual are disjoint.
44  * </p>
45  *
46  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
47  * @version CVS $Id: DIGQueryDifferentFromTranslator.java,v 1.5 2005/03/16 18:52:28 ian_dickinson Exp $
48  */

49 public class DIGQueryDifferentFromTranslator
50     extends DIGQueryTranslator
51 {
52
53     // Constants
54
//////////////////////////////////
55

56     // Static variables
57
//////////////////////////////////
58

59     // Instance variables
60
//////////////////////////////////
61

62     // Constructors
63
//////////////////////////////////
64

65     /**
66      * <p>Construct a translator to test whether two individuals are different</p>
67      * @param predicate The predicate we are matching on
68      */

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

77     /**
78      * <p>Answer a query that will test difference between two individuals</p>
79      */

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

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

125     //==============================================================================
126
// Inner class definitions
127
//==============================================================================
128

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

158
Popular Tags