01: /******************************************************************
02: * File: TopLeveTripleMatchFrame.java
03: * Created by: Dave Reynolds
04: * Created on: 11-Aug-2003
05: *
06: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
07: * [See end of file]
08: * $Id: TopLevelTripleMatchFrame.java,v 1.7 2008/01/02 12:06:15 andy_seaborne Exp $
09: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.impl;
10:
11: import com.hp.hpl.jena.graph.*;
12: import com.hp.hpl.jena.reasoner.TriplePattern;
13: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
14:
15: /**
16: *
17: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
18: * @version $Revision: 1.7 $ on $Date: 2008/01/02 12:06:15 $
19: */
20: public class TopLevelTripleMatchFrame extends GenericChoiceFrame {
21:
22: /** The last returned triple */
23: protected Triple lastMatch;
24:
25: /** An iterator over triples matching a goal */
26: ExtendedIterator matchIterator;
27:
28: /** Used for debug/tracing only */
29: protected TriplePattern goal;
30:
31: /**
32: * Constructor.
33: * Initialize the triple match to preserve the current context of the given
34: * LPInterpreter and search for the match defined by the current argument registers
35: * @param intepreter the interpreter instance whose env, trail and arg values are to be preserved
36: */
37: public TopLevelTripleMatchFrame(LPInterpreter interpreter,
38: TriplePattern goal) {
39: init(interpreter);
40: this .matchIterator = interpreter.getEngine().getInfGraph()
41: .findDataMatches(goal);
42: this .goal = goal;
43: }
44:
45: /**
46: * Find the next result triple and bind the result vars appropriately.
47: * @param interpreter the calling interpreter whose trail should be used
48: * @return false if there are no more matches in the iterator.
49: */
50: public boolean nextMatch(LPInterpreter interpreter) {
51: if (matchIterator.hasNext()) {
52: lastMatch = (Triple) matchIterator.next();
53: return true;
54: } else {
55: return false;
56: }
57: }
58:
59: /**
60: * Override close method to reclaim the iterator.
61: */
62: public void close() {
63: if (matchIterator != null)
64: matchIterator.close();
65: }
66:
67: }
68:
69: /*
70: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
71: All rights reserved.
72:
73: Redistribution and use in source and binary forms, with or without
74: modification, are permitted provided that the following conditions
75: are met:
76:
77: 1. Redistributions of source code must retain the above copyright
78: notice, this list of conditions and the following disclaimer.
79:
80: 2. Redistributions in binary form must reproduce the above copyright
81: notice, this list of conditions and the following disclaimer in the
82: documentation and/or other materials provided with the distribution.
83:
84: 3. The name of the author may not be used to endorse or promote products
85: derived from this software without specific prior written permission.
86:
87: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97: */
|