KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > RETERuleInfGraph


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

10 package com.hp.hpl.jena.reasoner.rulesys;
11
12 import com.hp.hpl.jena.graph.*;
13 import com.hp.hpl.jena.reasoner.*;
14 import com.hp.hpl.jena.reasoner.rulesys.impl.*;
15
16 import java.util.*;
17
18 /**
19  * RETE implementation of the forward rule infernce graph.
20  *
21  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
22  * @version $Revision: 1.8 $ on $Date: 2005/02/21 12:17:04 $
23  */

24 public class RETERuleInfGraph extends BasicForwardRuleInfGraph {
25
26     /**
27      * Constructor. Creates a new inference graph to which a (compiled) rule set
28      * and a data graph can be attached. This separation of binding is useful to allow
29      * any configuration parameters (such as logging) to be set before the data is added.
30      * Note that until the data is added using {@link #rebind rebind} then any operations
31      * like add, remove, find will result in errors.
32      *
33      * @param reasoner the parent reasoner
34      * @param schema the (optional) schema data which is being processed
35      */

36     public RETERuleInfGraph(Reasoner reasoner, Graph schema) {
37         super(reasoner, schema);
38     }
39
40     /**
41      * Constructor. Creates a new inference graph based on the given rule set.
42      * No data graph is attached at this stage. This is to allow
43      * any configuration parameters (such as logging) to be set before the data is added.
44      * Note that until the data is added using {@link #rebind rebind} then any operations
45      * like add, remove, find will result in errors.
46      *
47      * @param reasoner the parent reasoner
48      * @param rules the list of rules to use this time
49      * @param schema the (optional) schema or preload data which is being processed
50      */

51     public RETERuleInfGraph(Reasoner reasoner, List rules, Graph schema) {
52         super(reasoner, rules, schema);
53     }
54
55      /**
56       * Constructor. Creates a new inference graph based on the given rule set
57       * then processes the initial data graph. No precomputed deductions are loaded.
58       *
59       * @param reasoner the parent reasoner
60       * @param rules the list of rules to use this time
61       * @param schema the (optional) schema or preload data which is being processed
62       * @param data the data graph to be processed
63       */

64      public RETERuleInfGraph(Reasoner reasoner, List rules, Graph schema, Graph data) {
65          super(reasoner, rules, schema, data);
66      }
67
68     /**
69      * Instantiate the forward rule engine to use.
70      * Subclasses can override this to switch to, say, a RETE imlementation.
71      * @param rules the rule set or null if there are not rules bound in yet.
72      */

73     protected void instantiateRuleEngine(List rules) {
74         if (rules != null) {
75             engine = new RETEEngine(this, rules);
76         } else {
77             engine = new RETEEngine(this);
78         }
79     }
80
81     /**
82      * Add one triple to the data graph, run any rules triggered by
83      * the new data item, recursively adding any generated triples.
84      */

85     public synchronized void performAdd(Triple t) {
86         if (!isPrepared) prepare();
87         fdata.getGraph().add(t);
88         engine.add(t);
89     }
90     
91     /**
92      * Removes the triple t (if possible) from the set belonging to this graph.
93      */

94     public void performDelete(Triple t) {
95         if (!isPrepared) prepare();
96         if (fdata != null) {
97             Graph data = fdata.getGraph();
98             if (data != null) {
99                 data.delete(t);
100             }
101         }
102         engine.delete(t);
103         fdeductions.getGraph().delete(t);
104     }
105
106 }
107
108
109 /*
110     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
111     All rights reserved.
112
113     Redistribution and use in source and binary forms, with or without
114     modification, are permitted provided that the following conditions
115     are met:
116
117     1. Redistributions of source code must retain the above copyright
118        notice, this list of conditions and the following disclaimer.
119
120     2. Redistributions in binary form must reproduce the above copyright
121        notice, this list of conditions and the following disclaimer in the
122        documentation and/or other materials provided with the distribution.
123
124     3. The name of the author may not be used to endorse or promote products
125        derived from this software without specific prior written permission.
126
127     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
128     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
129     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
130     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
131     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
132     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
133     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
134     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
135     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
136     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
137 */
Popular Tags