KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************
2  * File: EnvironmentFrameWithDerivation.java
3  * Created by: Dave Reynolds
4  * Created on: 18-Aug-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: EnvironmentFrameWithDerivation.java,v 1.5 2005/02/21 12:17:40 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
15 import java.util.*;
16
17 /**
18  * Extension of the normal AND-stack environment frame to support
19  * incremental derivation logging.
20  *
21  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
22  * @version $Revision: 1.5 $ on $Date: 2005/02/21 12:17:40 $
23  */

24 public class EnvironmentFrameWithDerivation extends EnvironmentFrame {
25
26     /** The initial starting arguments for the call */
27     Node[] argVars = new Node[RuleClauseCode.MAX_ARGUMENT_VARS];
28         
29     /** The set of instantiated subgoals processed so far */
30     Triple[] matches;
31         
32     /**
33      * Constructor
34      * @param clause the compiled code being interpreted by this env frame
35      */

36     public EnvironmentFrameWithDerivation(RuleClauseCode clause) {
37         super(clause);
38         if (clause.getRule() != null) {
39             matches = new Triple[clause.getRule().bodyLength()];
40         }
41     }
42     
43     /** Instantiate and record a matched subgoal */
44     public void noteMatch(TriplePattern pattern, int pc) {
45         Triple match = new Triple(LPInterpreter.deref(pattern.getSubject()),
46                                     LPInterpreter.deref(pattern.getPredicate()),
47                                     LPInterpreter.deref(pattern.getObject()));
48         int term = clause.termIndex(pc);
49         if (term >= 0) {
50             matches[term] = match;
51         }
52     }
53
54     /**
55      * Return the final instantiated goal given the current binding state.
56      */

57     public Triple getResult() {
58         return new Triple(
59                     LPInterpreter.deref(argVars[0]),
60                     LPInterpreter.deref(argVars[1]),
61                     LPInterpreter.derefPossFunctor(argVars[2]));
62     }
63     
64     /**
65      * Return a safe copy of the list of matched subgoals in this subderivation.
66      */

67     public List getMatchList() {
68         ArrayList matchList = new ArrayList();
69         for (int i = 0; i < matches.length; i++) {
70             matchList.add(matches[i]);
71         }
72         return matchList;
73     }
74     /**
75      * Create an initial derivation record for this frame, based on the given
76      * argument registers.
77      */

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