001: /******************************************************************
002: * File: RETERuleInfGraph.java
003: * Created by: Dave Reynolds
004: * Created on: 12-Jun-2003
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: RETERuleInfGraph.java,v 1.11 2008/01/02 12:07:47 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys;
010:
011: import com.hp.hpl.jena.graph.*;
012: import com.hp.hpl.jena.reasoner.*;
013: import com.hp.hpl.jena.reasoner.rulesys.impl.*;
014:
015: import java.util.*;
016:
017: /**
018: * RETE implementation of the forward rule infernce graph.
019: *
020: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
021: * @version $Revision: 1.11 $ on $Date: 2008/01/02 12:07:47 $
022: */
023: public class RETERuleInfGraph extends BasicForwardRuleInfGraph {
024:
025: /**
026: * Constructor. Creates a new inference graph to which a (compiled) rule set
027: * and a data graph can be attached. This separation of binding is useful to allow
028: * any configuration parameters (such as logging) to be set before the data is added.
029: * Note that until the data is added using {@link #rebind rebind} then any operations
030: * like add, remove, find will result in errors.
031: *
032: * @param reasoner the parent reasoner
033: * @param schema the (optional) schema data which is being processed
034: */
035: public RETERuleInfGraph(Reasoner reasoner, Graph schema) {
036: super (reasoner, schema);
037: }
038:
039: /**
040: * Constructor. Creates a new inference graph based on the given rule set.
041: * No data graph is attached at this stage. This is to allow
042: * any configuration parameters (such as logging) to be set before the data is added.
043: * Note that until the data is added using {@link #rebind rebind} then any operations
044: * like add, remove, find will result in errors.
045: *
046: * @param reasoner the parent reasoner
047: * @param rules the list of rules to use this time
048: * @param schema the (optional) schema or preload data which is being processed
049: */
050: public RETERuleInfGraph(Reasoner reasoner, List rules, Graph schema) {
051: super (reasoner, rules, schema);
052: }
053:
054: /**
055: * Constructor. Creates a new inference graph based on the given rule set
056: * then processes the initial data graph. No precomputed deductions are loaded.
057: *
058: * @param reasoner the parent reasoner
059: * @param rules the list of rules to use this time
060: * @param schema the (optional) schema or preload data which is being processed
061: * @param data the data graph to be processed
062: */
063: public RETERuleInfGraph(Reasoner reasoner, List rules,
064: Graph schema, Graph data) {
065: super (reasoner, rules, schema, data);
066: }
067:
068: /**
069: * Instantiate the forward rule engine to use.
070: * Subclasses can override this to switch to, say, a RETE imlementation.
071: * @param rules the rule set or null if there are not rules bound in yet.
072: */
073: protected void instantiateRuleEngine(List rules) {
074: if (rules != null) {
075: engine = new RETEEngine(this , rules);
076: } else {
077: engine = new RETEEngine(this );
078: }
079: }
080:
081: /**
082: * Add one triple to the data graph, run any rules triggered by
083: * the new data item, recursively adding any generated triples.
084: */
085: public synchronized void performAdd(Triple t) {
086: if (!isPrepared)
087: prepare();
088: fdata.getGraph().add(t);
089: engine.add(t);
090: }
091:
092: /**
093: * Removes the triple t (if possible) from the set belonging to this graph.
094: */
095: public void performDelete(Triple t) {
096: if (!isPrepared)
097: prepare();
098: if (fdata != null) {
099: Graph data = fdata.getGraph();
100: if (data != null) {
101: data.delete(t);
102: }
103: }
104: engine.delete(t);
105: fdeductions.getGraph().delete(t);
106: }
107:
108: }
109:
110: /*
111: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
112: All rights reserved.
113:
114: Redistribution and use in source and binary forms, with or without
115: modification, are permitted provided that the following conditions
116: are met:
117:
118: 1. Redistributions of source code must retain the above copyright
119: notice, this list of conditions and the following disclaimer.
120:
121: 2. Redistributions in binary form must reproduce the above copyright
122: notice, this list of conditions and the following disclaimer in the
123: documentation and/or other materials provided with the distribution.
124:
125: 3. The name of the author may not be used to endorse or promote products
126: derived from this software without specific prior written permission.
127:
128: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
129: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
130: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
131: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
132: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
133: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
134: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
135: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
136: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
137: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
138: */
|