KickJava   Java API By Example, From Geeks To Geeks.

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


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: DIGIteratedQueryTranslator.java,v $
10  * Revision $Revision: 1.6 $
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
26 // Imports
27
///////////////
28
import java.util.Iterator JavaDoc;
29
30 import org.w3c.dom.Document JavaDoc;
31
32 import com.hp.hpl.jena.rdf.model.Model;
33 import com.hp.hpl.jena.reasoner.TriplePattern;
34 import com.hp.hpl.jena.util.iterator.*;
35
36
37 /**
38  * <p>
39  * A specialisation of DIG query translator that aggregates iterated queries
40  * </p>
41  *
42  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
43  * @version CVS $Id: DIGIteratedQueryTranslator.java,v 1.6 2005/03/16 18:52:28 ian_dickinson Exp $
44  */

45 public abstract class DIGIteratedQueryTranslator
46     extends DIGQueryTranslator
47 {
48
49     // Constants
50
//////////////////////////////////
51

52     // Static variables
53
//////////////////////////////////
54

55     // Instance variables
56
//////////////////////////////////
57

58     // Constructors
59
//////////////////////////////////
60

61     /**
62      * <p>Construct a query translator for the given query parameters.</p>
63      * @param subject Represents the incoming subject to trigger against
64      * @param predicate Represents the incoming predicate to trigger against
65      * @param object Represents the incoming object to trigger against
66      */

67     public DIGIteratedQueryTranslator( String JavaDoc subject, String JavaDoc predicate, String JavaDoc object ) {
68         super( subject, predicate, object );
69     }
70
71
72
73     // External signature methods
74
//////////////////////////////////
75

76     /**
77      * <p>Takes the incoming query pattern and expands it out to a series of subsidary
78      * triple patterns that will be taken as queries in their own right.</p>
79      * @param pattern The incomimg query pattern
80      * @param da The DIG adapter currently being used to communicate with the DIG reasoner
81      * @return An iterator over a series of {@link TriplePattern}'s that represent
82      * the expanded query
83      */

84     protected abstract Iterator JavaDoc expandQuery( TriplePattern pattern, DIGAdapter da );
85     
86     
87     /**
88      * <p>Expand the given pattern to a series of more grounded patterns, and collate
89      * the results of querying with each of these expanded patterns. This is used in
90      * cases where the incoming query is too ungrounded to pass to DIG in one go, e.g.
91      * <code>*&nbsp;rdfs:subClassOf&nbsp;*</code>. The strategy is to expand one of
92      * the ungrounded terms to form a series of queries, then solve each of these
93      * queries separately.</p>
94      * @param pattern The pattern to translate to a DIG query
95      * @param da The DIG adapter through which we communicate with a DIG reasoner
96      */

97     public ExtendedIterator find( TriplePattern pattern, DIGAdapter da ) {
98         ExtendedIterator all = null;
99         
100         for (Iterator JavaDoc i = expandQuery( pattern, da ); i.hasNext(); ) {
101             ExtendedIterator results = da.find( (TriplePattern) i.next() );
102             all = (all == null) ? results : all.andThen( results );
103         }
104         
105         return UniqueExtendedIterator.create( all );
106     }
107     
108     
109     /**
110      * Not needed in this class - delegated to the specific query handlers
111      */

112     public Document JavaDoc translatePattern( TriplePattern query, DIGAdapter da ) {
113         return null;
114     }
115
116     public Document JavaDoc translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) {
117         // not used
118
return null;
119     }
120
121     /**
122      * Not needed in this class - delegated to the specific query handlers
123      */

124     public ExtendedIterator translateResponseHook(Document JavaDoc Response, TriplePattern query, DIGAdapter da) {
125         return null;
126     }
127     
128
129     // Internal implementation methods
130
//////////////////////////////////
131

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

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

165
Popular Tags