KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************
2  * File: TripleMatchFrame.java
3  * Created by: Dave Reynolds
4  * Created on: 23-Jul-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: TripleMatchFrame.java,v 1.4 2005/02/21 12:18:01 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.util.iterator.ExtendedIterator;
14
15 /**
16  * Frame on the choice point stack used to represent the state of a direct
17  * graph triple match.
18  * <p>
19  * This is used in the inner loop of the interpreter and so is a pure data structure
20  * not an abstract data type and assumes privileged access to the interpreter state.
21  * </p>
22  *
23  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
24  * @version $Revision: 1.4 $ on $Date: 2005/02/21 12:18:01 $
25  */

26 public class TripleMatchFrame extends GenericTripleMatchFrame {
27     
28     /** An iterator over triples matching a goal */
29     ExtendedIterator matchIterator;
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 TripleMatchFrame(LPInterpreter interpreter) {
38         init(interpreter);
39     }
40
41     /**
42      * Find the next result triple and bind the result vars appropriately.
43      * @param interpreter the calling interpreter whose trail should be used
44      * @return false if there are no more matches in the iterator.
45      */

46     public boolean nextMatch(LPInterpreter interpreter) {
47         while (matchIterator.hasNext()) {
48             if (bindResult((Triple)matchIterator.next(), interpreter)) {
49                 return true;
50             }
51         }
52         return false;
53     }
54     
55     /**
56      * Initialize the triple match to preserve the current context of the given
57      * LPInterpreter and search for the match defined by the current argument registers
58      * @param intepreter the interpreter instance whose env, trail and arg values are to be preserved
59      */

60     public void init(LPInterpreter interpreter) {
61         super.init(interpreter);
62         this.matchIterator = interpreter.getEngine().getInfGraph().findDataMatches(goal);
63     }
64     
65     /**
66      * Override close method to reclaim the iterator.
67      */

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