Source Code Cross Referenced for GenericTripleMatchFrame.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:        GenericTripleMatchFrame.java
003:         * Created by:  Dave Reynolds
004:         * Created on:  07-Aug-2003
005:         * 
006:         * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007:         * [See end of file]
008:         * $Id: GenericTripleMatchFrame.java,v 1.8 2008/01/02 12:06:17 andy_seaborne Exp $
009:         *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.impl;
010:
011:        import com.hp.hpl.jena.graph.*;
012:        import com.hp.hpl.jena.reasoner.TriplePattern;
013:        import com.hp.hpl.jena.reasoner.rulesys.Functor;
014:        import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable;
015:
016:        /**
017:         * Frame on the choice point stack used to represent the state of some form of triple
018:         * match - this is either a direct graph query or a query to a cached set of results.
019:         * <p>
020:         * This is used in the inner loop of the interpreter and so is a pure data structure
021:         * not an abstract data type and assumes privileged access to the interpreter state.
022:         * </p>
023:         *  
024:         * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
025:         * @version $Revision: 1.8 $ on $Date: 2008/01/02 12:06:17 $
026:         */
027:        public class GenericTripleMatchFrame extends GenericChoiceFrame {
028:
029:            /** The variable to the subject of the triple, null if no binding required */
030:            Node_RuleVariable subjectVar;
031:
032:            /** The variable to the predicate of the triple, null if no binding required */
033:            Node_RuleVariable predicateVar;
034:
035:            /** The variable to the subject of the triple, null if no binding required */
036:            Node_RuleVariable objectVar;
037:
038:            /** The functor variable structure to explode the object into, null if not required */
039:            Functor objectFunctor;
040:
041:            /** The goal state being evaluated */
042:            TriplePattern goal;
043:
044:            /**
045:             * Bind the goal variables to the given result triple.
046:             * Returns false if the triple doesn't match the goal (due to a functor match failure).
047:             */
048:            public boolean bindResult(Triple triple, LPInterpreter interpreter) {
049:                if (objectVar != null)
050:                    interpreter.bind(objectVar, triple.getObject());
051:                int mark = interpreter.trail.size();
052:                if (objectFunctor != null) {
053:                    if (!functorMatch(triple, interpreter)) {
054:                        interpreter.unwindTrail(mark);
055:                        return false;
056:                    }
057:                }
058:                if (subjectVar != null) {
059:                    if (!interpreter.unify(subjectVar, triple.getSubject())) {
060:                        interpreter.unwindTrail(mark);
061:                        return false;
062:                    }
063:                }
064:                if (predicateVar != null) {
065:                    if (!interpreter.unify(predicateVar, triple.getPredicate())) {
066:                        interpreter.unwindTrail(mark);
067:                        return false;
068:                    }
069:
070:                }
071:                return true;
072:            }
073:
074:            /**
075:             * Check that the object of a triple match corresponds to the given functor pattern.
076:             * Side effects the variable bindings.
077:             */
078:            public boolean functorMatch(Triple t, LPInterpreter interpreter) {
079:                Node o = t.getObject();
080:                if (!Functor.isFunctor(o))
081:                    return false;
082:                Functor f = (Functor) o.getLiteralValue();
083:                if (!f.getName().equals(objectFunctor.getName()))
084:                    return false;
085:                if (f.getArgLength() != objectFunctor.getArgLength())
086:                    return false;
087:                Node[] fargs = f.getArgs();
088:                Node[] oFargs = objectFunctor.getArgs();
089:                for (int i = 0; i < fargs.length; i++) {
090:                    if (!interpreter.unify(oFargs[i], fargs[i]))
091:                        return false;
092:                }
093:                return true;
094:            }
095:
096:            /**
097:             * Initialize the triple match to preserve the current context of the given
098:             * LPInterpreter and search for the match defined by the current argument registers
099:             * @param intepreter the interpreter instance whose env, trail and arg values are to be preserved
100:             */
101:            public void init(LPInterpreter interpreter) {
102:                super .init(interpreter);
103:                Node s = LPInterpreter.deref(interpreter.argVars[0]);
104:                subjectVar = (s instanceof  Node_RuleVariable) ? (Node_RuleVariable) s
105:                        : null;
106:                Node p = LPInterpreter.deref(interpreter.argVars[1]);
107:                predicateVar = (p instanceof  Node_RuleVariable) ? (Node_RuleVariable) p
108:                        : null;
109:                Node o = LPInterpreter.deref(interpreter.argVars[2]);
110:                objectVar = (o instanceof  Node_RuleVariable) ? (Node_RuleVariable) o
111:                        : null;
112:                if (Functor.isFunctor(o)) {
113:                    objectFunctor = (Functor) o.getLiteralValue();
114:                    goal = new TriplePattern(s, p, null);
115:                } else {
116:                    objectFunctor = null;
117:                    goal = new TriplePattern(s, p, o);
118:                }
119:            }
120:
121:        }
122:
123:        /*
124:         (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
125:         All rights reserved.
126:
127:         Redistribution and use in source and binary forms, with or without
128:         modification, are permitted provided that the following conditions
129:         are met:
130:
131:         1. Redistributions of source code must retain the above copyright
132:         notice, this list of conditions and the following disclaimer.
133:
134:         2. Redistributions in binary form must reproduce the above copyright
135:         notice, this list of conditions and the following disclaimer in the
136:         documentation and/or other materials provided with the distribution.
137:
138:         3. The name of the author may not be used to endorse or promote products
139:         derived from this software without specific prior written permission.
140:
141:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
142:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
143:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
144:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
145:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
146:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
147:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
148:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
149:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
150:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
151:         */
ww___w.j___a_v__a___2__s___.___c__o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.