Source Code Cross Referenced for TestComplexTerm.java in  » Rule-Engine » Mandarax » test » org » mandarax » reference » 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 » Rule Engine » Mandarax » test.org.mandarax.reference 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 1999-2004 <a href="mailto:paschke@in.tum.de">Adrian Paschke</a>
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package test.org.mandarax.reference;
020:
021:        import java.util.Iterator;
022:        import org.mandarax.kernel.*;
023:        import org.mandarax.lib.math.IntArithmetic;
024:        import org.mandarax.reference.AdvancedKnowledgeBase;
025:        import org.mandarax.reference.ResolutionInferenceEngine4;
026:        import org.mandarax.util.LogicFactorySupport;
027:        import org.apache.log4j.*;
028:
029:        /**
030:         * Test complex terms.  
031:         * @author <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
032:         * @version 3.4 <7 March 05>
033:         * @since 3.3.1
034:         */
035:        public class TestComplexTerm extends MandaraxTestCase {
036:            private KnowledgeBase kb = null;
037:            private InferenceEngine ie = null;
038:            private Predicate result1 = null;
039:            private Predicate result2 = null;
040:
041:            /**
042:             * Constructor.
043:             * @param testName the name of the test
044:             */
045:            public TestComplexTerm(String testName,
046:                    KnowledgeBase aKnowledgeBase,
047:                    InferenceEngine anInferenceEngine) {
048:                super (testName);
049:                kb = aKnowledgeBase;
050:                ie = anInferenceEngine;
051:            }
052:
053:            /**
054:             * Constructor.
055:             * @param testName the name of the test
056:             */
057:            public TestComplexTerm(String testName) {
058:                this (testName, new AdvancedKnowledgeBase(),
059:                        new ResolutionInferenceEngine4());
060:            }
061:
062:            /**
063:             * Set up the test case.
064:             */
065:            public void setUp() throws Exception {
066:                super .setUp();
067:
068:                // init kb		
069:                LogicFactorySupport lfs = new LogicFactorySupport();
070:
071:                Predicate input = new SimplePredicate("input",
072:                        new Class[] { Integer.class });
073:                result1 = new SimplePredicate("result1",
074:                        new Class[] { Integer.class });
075:                result2 = new SimplePredicate("result2", new Class[] {
076:                        Integer.class, Integer.class });
077:
078:                // input(1)
079:                Fact f = lfs.fact(input, new Integer(1));
080:                kb.add(f);
081:
082:                // result1(plus(N,N)) <-- input(N)
083:                Rule rule1 = lfs.rule(lfs.prereq(input, lfs.variable("N",
084:                        Integer.class)),
085:                // -->					
086:                        lfs.fact(result1, lfs.cplx(IntArithmetic.PLUS, lfs
087:                                .variable("N", Integer.class), lfs.variable(
088:                                "N", Integer.class))));
089:                kb.add(rule1);
090:
091:                // result2(N,plus(N,N)) <-- input(N)
092:                Rule rule2 = lfs.rule(lfs.prereq(input, lfs.variable("N",
093:                        Integer.class)),
094:                // -->					
095:                        lfs.fact(result2, lfs.variable("N", Integer.class), lfs
096:                                .cplx(IntArithmetic.PLUS, lfs.variable("N",
097:                                        Integer.class), lfs.variable("N",
098:                                        Integer.class))));
099:                kb.add(rule2);
100:
101:                LOG_TEST.debug("Setup test case " + this );
102:                LOG_TEST.debug("kb contains:");
103:                for (Iterator iter = kb.getClauseSets().iterator(); iter
104:                        .hasNext();) {
105:                    LOG_TEST.debug(iter.next().toString());
106:                }
107:            }
108:
109:            /**
110:             * Test method 1 - WARNING: this is not supported by current IE implementations (Jens, March 05) !!	 
111:             */
112:            public void testComplexTerm1() throws Exception {
113:                LogicFactorySupport lfs = new LogicFactorySupport();
114:                // query ? result1(2)
115:                Query q = lfs.query(lfs.fact(result1, new Integer(2)),
116:                        "?result1(2)");
117:                LOG_TEST.debug("Query is : " + q.getFacts()[0]);
118:                ResultSet rs = ie.query(q, kb, InferenceEngine.ONE,
119:                        InferenceEngine.BUBBLE_EXCEPTIONS);
120:                if (!rs.next())
121:                    assertTrue("Query " + q.getName() + " failed ", false);
122:                assertTrue(true);
123:            }
124:
125:            /**
126:             * Test method 2.
127:             */
128:            public void testComplexTerm2() throws Exception {
129:                LogicFactorySupport lfs = new LogicFactorySupport();
130:                // query ? result1(N)
131:                Query q = lfs.query(lfs.fact(result1, lfs.variable("N",
132:                        Integer.class)), "?result1(N)");
133:                LOG_TEST.debug("Query is : " + q.getFacts()[0]);
134:                ResultSet rs = ie.query(q, kb, InferenceEngine.ONE,
135:                        InferenceEngine.BUBBLE_EXCEPTIONS);
136:                if (!rs.next())
137:                    assertTrue("Query " + q.getName() + " failed ", false);
138:                assertTrue(((Integer) rs.getResult(Integer.class, "N"))
139:                        .intValue() == 2);
140:            }
141:
142:            /**
143:             * Test method 3.
144:             */
145:            public void testComplexTerm3() throws Exception {
146:                LogicFactorySupport lfs = new LogicFactorySupport();
147:                // query ? result2(1,N)
148:                Query q = lfs.query(lfs.fact(result2, new Integer(1), lfs
149:                        .variable("N", Integer.class)), "?result2(1,N)");
150:                LOG_TEST.debug("Query is : " + q.getFacts()[0]);
151:                ResultSet rs = ie.query(q, kb, InferenceEngine.ONE,
152:                        InferenceEngine.BUBBLE_EXCEPTIONS);
153:                if (!rs.next())
154:                    assertTrue("Query " + q.getName() + " failed ", false);
155:                assertTrue(((Integer) rs.getResult(Integer.class, "N"))
156:                        .intValue() == 2);
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.