Source Code Cross Referenced for RuleDerivation.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » reasoner » rulesys » 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 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************
002:         * File:        RuleDerivation.java
003:         * Created by:  Dave Reynolds
004:         * Created on:  06-Apr-03
005:         * 
006:         * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007:         * [See end of file]
008:         * $Id: RuleDerivation.java,v 1.12 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.Derivation;
013:        import com.hp.hpl.jena.reasoner.InfGraph;
014:        import com.hp.hpl.jena.util.PrintUtil;
015:        import java.io.PrintWriter;
016:        import java.util.*;
017:
018:        /**
019:         * Derivation records are used to determine how an inferred triple
020:         * was derived from a set of source triples and a reasoner. SubClasses
021:         * provide more specific information.
022:         * 
023:         * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
024:         * @version $Revision: 1.12 $ on $Date: 2008/01/02 12:07:47 $
025:         */
026:        public class RuleDerivation implements  Derivation {
027:
028:            /** The rule which asserted this triple */
029:            protected Rule rule;
030:
031:            /** The triple which was asserted */
032:            protected Triple conclusion;
033:
034:            /** The list of triple matches that fired the rule */
035:            protected List matches;
036:
037:            /** The InfGraph which produced this derivation */
038:            protected InfGraph infGraph;
039:
040:            /**
041:             * Constructor
042:             * @param rule the rule which created this derivation
043:             * @param conclusion the triple which the rule created
044:             * @param matches a list of matching Triples corresponding to the rule body patterns
045:             * @param infGraph the parent infGraph which was controlling the derivation
046:             */
047:            public RuleDerivation(Rule rule, Triple conclusion, List matches,
048:                    InfGraph infGraph) {
049:                this .rule = rule;
050:                this .conclusion = conclusion;
051:                this .matches = matches;
052:                this .infGraph = infGraph;
053:            }
054:
055:            /**
056:             * Return a short-form description of this derivation.
057:             */
058:            public String toString() {
059:                if (rule == null) {
060:                    return "DUMMY";
061:                } else {
062:                    return "Rule " + rule.toShortString();
063:                }
064:            }
065:
066:            /**
067:             * Print a deep traceback of this derivation back to axioms and 
068:             * source assertions.
069:             * @param out the stream to print the trace out to
070:             * @param bindings set to true to print intermediate variable bindings for
071:             * each stage in the derivation
072:             */
073:            public void printTrace(PrintWriter out, boolean bindings) {
074:                printTrace(out, bindings, 0, new HashSet());
075:            }
076:
077:            /**
078:             * Print a deep traceback of this derivation back to axioms and 
079:             * source assertions.
080:             * @param out the stream to print the trace out to
081:             * @param bindings set to true to print intermediate variable bindings for
082:             * each stage in the derivation
083:             * @param indent the number of indent spaces to use
084:             * @param seen a HashSet of derviations that have already been listed
085:             */
086:            protected void printTrace(PrintWriter out, boolean bindings,
087:                    int indent, HashSet seen) {
088:                PrintUtil.printIndent(out, indent);
089:                out.print(this .toString());
090:                if (bindings) {
091:                    out.print(" concluded " + PrintUtil.print(conclusion));
092:                }
093:                out.println(" <-");
094:                int margin = indent + 4;
095:                for (int i = 0; i < matches.size(); i++) {
096:                    Triple match = (Triple) matches.get(i);
097:                    Iterator derivations = infGraph.getDerivation(match);
098:                    if (derivations == null || !derivations.hasNext()) {
099:                        PrintUtil.printIndent(out, margin);
100:                        if (match == null) {
101:                            // A primitive
102:                            ClauseEntry term = rule.getBodyElement(i);
103:                            if (term instanceof  Functor) {
104:                                out.println(((Functor) term).getName() + "()");
105:                            } else {
106:                                out.println("call to built in");
107:                            }
108:                        } else {
109:                            out.println("Fact " + PrintUtil.print(match));
110:                        }
111:                    } else {
112:                        RuleDerivation derivation = (RuleDerivation) derivations
113:                                .next();
114:                        if (seen.contains(derivation)) {
115:                            PrintUtil.printIndent(out, margin);
116:                            out.println("Known " + PrintUtil.print(match)
117:                                    + " - already shown");
118:                        } else {
119:                            seen.add(derivation);
120:                            derivation.printTrace(out, bindings, margin, seen);
121:                        }
122:                    }
123:                }
124:            }
125:
126:            /**
127:             * @return the triple concluded by the derivation
128:             */
129:            public Triple getConclusion() {
130:                return conclusion;
131:            }
132:
133:            /**
134:             * @return the set of triples which were used in firing this rule derivation
135:             */
136:            public List getMatches() {
137:                return matches;
138:            }
139:
140:            /**
141:             * @return the rule which fired to create this derivation
142:             */
143:            public Rule getRule() {
144:                return rule;
145:            }
146:
147:            /**
148:             * Compare two derivations. This is a shallow comparison, two derivations 
149:             * are the same if they contain the same conclusion, rule and match list. 
150:             * They do not need to be derived from the same (or any) infGraph.
151:             */
152:            public boolean equals(Object other) {
153:                if (other instanceof  RuleDerivation) {
154:                    RuleDerivation otherD = (RuleDerivation) other;
155:                    return conclusion.equals(otherD.getConclusion())
156:                            && matches.equals(otherD.getMatches())
157:                            && rule.equals(otherD.getRule());
158:                } else {
159:                    return false;
160:                }
161:            }
162:        }
163:
164:        /*
165:         (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
166:         All rights reserved.
167:
168:         Redistribution and use in source and binary forms, with or without
169:         modification, are permitted provided that the following conditions
170:         are met:
171:
172:         1. Redistributions of source code must retain the above copyright
173:         notice, this list of conditions and the following disclaimer.
174:
175:         2. Redistributions in binary form must reproduce the above copyright
176:         notice, this list of conditions and the following disclaimer in the
177:         documentation and/or other materials provided with the distribution.
178:
179:         3. The name of the author may not be used to endorse or promote products
180:         derived from this software without specific prior written permission.
181:
182:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
183:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
184:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
185:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
186:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
187:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
188:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
189:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
190:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
191:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
192:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.