Source Code Cross Referenced for RETERuleContext.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » reasoner » rulesys » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.reasoner.rulesys.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************
002:         * File:        RETERuleContext.java
003:         * Created by:  Dave Reynolds
004:         * Created on:  09-Jun-2003
005:         * 
006:         * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007:         * [See end of file]
008:         * $Id: RETERuleContext.java,v 1.11 2008/01/02 12:06:15 andy_seaborne Exp $
009:         *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.impl;
010:
011:        import com.hp.hpl.jena.reasoner.*;
012:        import com.hp.hpl.jena.reasoner.rulesys.*;
013:        import com.hp.hpl.jena.util.iterator.ClosableIterator;
014:        import com.hp.hpl.jena.graph.*;
015:
016:        /**
017:         * An implementation of the generic RuleContext for use in the RETE implementation.
018:         * The RuleContext is used to supply context information to the builtin operations.
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:06:15 $
022:         */
023:        public class RETERuleContext implements  RuleContext {
024:
025:            /** The binding environment which represents the state of the current rule execution. */
026:            protected BindingEnvironment env;
027:
028:            /** The rule current being executed. */
029:            protected Rule rule;
030:
031:            /** The enclosing inference graph. */
032:            protected ForwardRuleInfGraphI graph;
033:
034:            /** The RETE engine associated with the inference graph */
035:            protected RETEEngine engine;
036:
037:            /**
038:             * Constructor.
039:             * @param graph the inference graph which owns this context.
040:             */
041:            public RETERuleContext(ForwardRuleInfGraphI graph, RETEEngine engine) {
042:                this .graph = graph;
043:                this .engine = engine;
044:            }
045:
046:            /**
047:             * Returns the current variable binding environment for the current rule.
048:             * @return BindingEnvironment
049:             */
050:            public BindingEnvironment getEnv() {
051:                return env;
052:            }
053:
054:            /**
055:             * Returns the graph.
056:             * @return InfGraph
057:             */
058:            public InfGraph getGraph() {
059:                return graph;
060:            }
061:
062:            /**
063:             * Returns the RETE engine associated with this context.
064:             */
065:            public RETEEngine getEngine() {
066:                return engine;
067:            }
068:
069:            /**
070:             * Returns the rule.
071:             * @return Rule
072:             */
073:            public Rule getRule() {
074:                return rule;
075:            }
076:
077:            /**
078:             * Sets the rule.
079:             * @param rule The rule to set
080:             */
081:            public void setRule(Rule rule) {
082:                this .rule = rule;
083:            }
084:
085:            /**
086:             * Sets the current binding environment for this context.
087:             * @param env the binding environment so far
088:             */
089:            public void setEnv(BindingEnvironment env) {
090:                this .env = env;
091:            }
092:
093:            /**
094:             * Return true if the triple is already in either the graph or the stack.
095:             * I.e. it has already been deduced.
096:             */
097:            public boolean contains(Triple t) {
098:                // Can't use stackCache.contains because that does not do semantic equality
099:                return contains(t.getSubject(), t.getPredicate(), t.getObject());
100:            }
101:
102:            /**
103:             * Return true if the triple pattern is already in either the graph or the stack.
104:             * I.e. it has already been deduced.
105:             */
106:            public boolean contains(Node s, Node p, Node o) {
107:                ClosableIterator it = find(s, p, o);
108:                boolean result = it.hasNext();
109:                it.close();
110:                return result;
111:            }
112:
113:            /**
114:             * In some formulations the context includes deductions that are not yet
115:             * visible to the underlying graph but need to be checked for.
116:             * However, currently this calls the graph find directly.
117:             */
118:            public ClosableIterator find(Node s, Node p, Node o) {
119:                //return graph.find(s, p, o).andThen(pendingCache.find(s, p, o));
120:                return graph.findDataMatches(s, p, o);
121:            }
122:
123:            /**
124:             * Assert a new triple in the deduction graph, bypassing any processing machinery.
125:             */
126:            public void silentAdd(Triple t) {
127:                ((SilentAddI) graph).silentAdd(t);
128:            }
129:
130:            /**
131:             * Remove a triple from the deduction graph (and the original graph if relevant).
132:             */
133:            public void remove(Triple t) {
134:                graph.getRawGraph().delete(t);
135:                engine.deleteTriple(t, true);
136:            }
137:
138:            /**
139:             * Assert a new triple in the deduction graph, triggering any consequent processing as appropriate.
140:             */
141:            public void add(Triple t) {
142:                engine.addTriple(t, true);
143:            }
144:
145:            /**
146:             * Check whether the rule should fire in this context.
147:             */
148:            public boolean shouldFire(boolean allowUnsafe) {
149:                // Check any non-pattern clauses 
150:                for (int i = 0; i < rule.bodyLength(); i++) {
151:                    Object clause = rule.getBodyElement(i);
152:                    if (clause instanceof  Functor) {
153:                        // Fire a built in
154:                        if (allowUnsafe) {
155:                            if (!((Functor) clause).evalAsBodyClause(this )) {
156:                                // Failed guard so just discard and return
157:                                return false;
158:                            }
159:                        } else {
160:                            // Don't re-run side-effectful clause on a re-run
161:                            if (!((Functor) clause).safeEvalAsBodyClause(this )) {
162:                                // Failed guard so just discard and return
163:                                return false;
164:                            }
165:                        }
166:                    }
167:                }
168:                return true;
169:            }
170:
171:            /**
172:             * Check if a rule from the conflict set is still OK to fire.
173:             * Just checks the non-monotonic guards such as noValue.
174:             */
175:            public boolean shouldStillFire() {
176:                // Check any non-pattern clauses 
177:                for (int i = 0; i < rule.bodyLength(); i++) {
178:                    Object clause = rule.getBodyElement(i);
179:                    if (clause instanceof  Functor) {
180:                        Builtin builtin = ((Functor) clause).getImplementor();
181:                        if (builtin != null && !builtin.isMonotonic()) {
182:                            if (!((Functor) clause).evalAsBodyClause(this )) {
183:                                return false;
184:                            }
185:                        }
186:                    }
187:                }
188:                return true;
189:            }
190:
191:        }
192:
193:        /*
194:         (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
195:         All rights reserved.
196:
197:         Redistribution and use in source and binary forms, with or without
198:         modification, are permitted provided that the following conditions
199:         are met:
200:
201:         1. Redistributions of source code must retain the above copyright
202:         notice, this list of conditions and the following disclaimer.
203:
204:         2. Redistributions in binary form must reproduce the above copyright
205:         notice, this list of conditions and the following disclaimer in the
206:         documentation and/or other materials provided with the distribution.
207:
208:         3. The name of the author may not be used to endorse or promote products
209:         derived from this software without specific prior written permission.
210:
211:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
212:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
213:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
214:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
215:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
216:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
217:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
218:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
219:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
220:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
221:         */
w__w___w.___j__a___v_a2_s.___co_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.