001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email ian.dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created 09-Dec-2003
009: * Filename $RCSfile: DIGIteratedQueryTranslator.java,v $
010: * Revision $Revision: 1.9 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:07:09 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * [See end of file]
018: *****************************************************************************/package com.hp.hpl.jena.reasoner.dig;
019:
020: // Imports
021: ///////////////
022: import java.util.Iterator;
023:
024: import org.w3c.dom.Document;
025:
026: import com.hp.hpl.jena.rdf.model.Model;
027: import com.hp.hpl.jena.reasoner.TriplePattern;
028: import com.hp.hpl.jena.util.iterator.*;
029:
030: /**
031: * <p>
032: * A specialisation of DIG query translator that aggregates iterated queries
033: * </p>
034: *
035: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
036: * @version CVS $Id: DIGIteratedQueryTranslator.java,v 1.9 2008/01/02 12:07:09 andy_seaborne Exp $
037: */
038: public abstract class DIGIteratedQueryTranslator extends
039: DIGQueryTranslator {
040:
041: // Constants
042: //////////////////////////////////
043:
044: // Static variables
045: //////////////////////////////////
046:
047: // Instance variables
048: //////////////////////////////////
049:
050: // Constructors
051: //////////////////////////////////
052:
053: /**
054: * <p>Construct a query translator for the given query parameters.</p>
055: * @param subject Represents the incoming subject to trigger against
056: * @param predicate Represents the incoming predicate to trigger against
057: * @param object Represents the incoming object to trigger against
058: */
059: public DIGIteratedQueryTranslator(String subject, String predicate,
060: String object) {
061: super (subject, predicate, object);
062: }
063:
064: // External signature methods
065: //////////////////////////////////
066:
067: /**
068: * <p>Takes the incoming query pattern and expands it out to a series of subsidary
069: * triple patterns that will be taken as queries in their own right.</p>
070: * @param pattern The incomimg query pattern
071: * @param da The DIG adapter currently being used to communicate with the DIG reasoner
072: * @return An iterator over a series of {@link TriplePattern}'s that represent
073: * the expanded query
074: */
075: protected abstract Iterator expandQuery(TriplePattern pattern,
076: DIGAdapter da);
077:
078: /**
079: * <p>Expand the given pattern to a series of more grounded patterns, and collate
080: * the results of querying with each of these expanded patterns. This is used in
081: * cases where the incoming query is too ungrounded to pass to DIG in one go, e.g.
082: * <code>* rdfs:subClassOf *</code>. The strategy is to expand one of
083: * the ungrounded terms to form a series of queries, then solve each of these
084: * queries separately.</p>
085: * @param pattern The pattern to translate to a DIG query
086: * @param da The DIG adapter through which we communicate with a DIG reasoner
087: */
088: public ExtendedIterator find(TriplePattern pattern, DIGAdapter da) {
089: ExtendedIterator all = null;
090:
091: for (Iterator i = expandQuery(pattern, da); i.hasNext();) {
092: ExtendedIterator results = da
093: .find((TriplePattern) i.next());
094: all = (all == null) ? results : all.andThen(results);
095: }
096:
097: return UniqueExtendedIterator.create(all);
098: }
099:
100: /**
101: * Not needed in this class - delegated to the specific query handlers
102: */
103: public Document translatePattern(TriplePattern query, DIGAdapter da) {
104: return null;
105: }
106:
107: public Document translatePattern(TriplePattern pattern,
108: DIGAdapter da, Model premises) {
109: // not used
110: return null;
111: }
112:
113: /**
114: * Not needed in this class - delegated to the specific query handlers
115: */
116: public ExtendedIterator translateResponseHook(Document Response,
117: TriplePattern query, DIGAdapter da) {
118: return null;
119: }
120:
121: // Internal implementation methods
122: //////////////////////////////////
123:
124: //==============================================================================
125: // Inner class definitions
126: //==============================================================================
127:
128: }
129:
130: /*
131: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
132: * All rights reserved.
133: *
134: * Redistribution and use in source and binary forms, with or without
135: * modification, are permitted provided that the following conditions
136: * are met:
137: * 1. Redistributions of source code must retain the above copyright
138: * notice, this list of conditions and the following disclaimer.
139: * 2. Redistributions in binary form must reproduce the above copyright
140: * notice, this list of conditions and the following disclaimer in the
141: * documentation and/or other materials provided with the distribution.
142: * 3. The name of the author may not be used to endorse or promote products
143: * derived from this software without specific prior written permission.
144: *
145: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
146: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
147: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
148: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
149: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
150: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
151: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
152: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
153: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
154: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155: */
|