KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > impl > TopLevelTripleMatchFrame


1 /******************************************************************
2  * File: TopLeveTripleMatchFrame.java
3  * Created by: Dave Reynolds
4  * Created on: 11-Aug-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: TopLevelTripleMatchFrame.java,v 1.4 2005/02/21 12:18:00 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.impl;
11
12 import com.hp.hpl.jena.graph.*;
13 import com.hp.hpl.jena.reasoner.TriplePattern;
14 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
15
16 /**
17  *
18  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
19  * @version $Revision: 1.4 $ on $Date: 2005/02/21 12:18:00 $
20  */

21 public class TopLevelTripleMatchFrame extends GenericChoiceFrame {
22
23     /** The last returned triple */
24     protected Triple lastMatch;
25     
26     /** An iterator over triples matching a goal */
27     ExtendedIterator matchIterator;
28
29     /** Used for debug/tracing only */
30     protected TriplePattern goal;
31         
32     /**
33      * Constructor.
34      * Initialize the triple match to preserve the current context of the given
35      * LPInterpreter and search for the match defined by the current argument registers
36      * @param intepreter the interpreter instance whose env, trail and arg values are to be preserved
37      */

38     public TopLevelTripleMatchFrame(LPInterpreter interpreter, TriplePattern goal) {
39         init(interpreter);
40         this.matchIterator = interpreter.getEngine().getInfGraph().findDataMatches(goal);
41         this.goal = goal;
42     }
43
44     /**
45      * Find the next result triple and bind the result vars appropriately.
46      * @param interpreter the calling interpreter whose trail should be used
47      * @return false if there are no more matches in the iterator.
48      */

49     public boolean nextMatch(LPInterpreter interpreter) {
50         if (matchIterator.hasNext()) {
51             lastMatch = (Triple)matchIterator.next();
52             return true;
53         } else {
54             return false;
55         }
56     }
57         
58     /**
59      * Override close method to reclaim the iterator.
60      */

61     public void close() {
62         if (matchIterator != null) matchIterator.close();
63     }
64         
65 }
66
67
68 /*
69     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
70     All rights reserved.
71
72     Redistribution and use in source and binary forms, with or without
73     modification, are permitted provided that the following conditions
74     are met:
75
76     1. Redistributions of source code must retain the above copyright
77        notice, this list of conditions and the following disclaimer.
78
79     2. Redistributions in binary form must reproduce the above copyright
80        notice, this list of conditions and the following disclaimer in the
81        documentation and/or other materials provided with the distribution.
82
83     3. The name of the author may not be used to endorse or promote products
84        derived from this software without specific prior written permission.
85
86     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
87     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
88     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
89     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
90     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
91     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
92     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
93     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
94     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
95     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96 */
Popular Tags