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


001:        /*
002:         * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</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.jdbc;
020:
021:        import java.io.*;
022:        import org.mandarax.kernel.*;
023:        import org.mandarax.reference.AdvancedKnowledgeBase;
024:        import org.mandarax.util.*;
025:        import org.mandarax.xkb.XKBManager;
026:        import org.mandarax.xkb.framework.XKBDriver_2_1;
027:        import org.mandarax.xkb.ruleml.RuleML0_8_1Driver;
028:        import org.mandarax.zkb.ZKBManager;
029:        import test.org.mandarax.testsupport.TestUtils;
030:
031:        /**
032:         * Utility class to create test knowledge bases.
033:         * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
034:         * @version 3.3.2 <29 December 2004>
035:         * @since 3.0
036:         */
037:
038:        public class TestKB {
039:            static LogicFactorySupport lfs = new LogicFactorySupport();
040:            static String XKB_FILE = TestUtils.getFileName("_family.xkb");
041:            static String ZKB_FILE = TestUtils.getFileName("_family.zkb");
042:            static String RULE_ML_FILE = TestUtils
043:                    .getFileName("_family.ruleml");
044:            private static KnowledgeBase kb = null;
045:            static boolean initialized = false;
046:
047:            /**
048:             * Main method - can be used to create the kbs.
049:             */
050:            public static void main(String[] args) throws Exception {
051:                setup();
052:            }
053:
054:            /**
055:             * Build the knowledge base.
056:             * @return a knowledge base
057:             */
058:            static KnowledgeBase createKB() {
059:                if (kb != null)
060:                    return kb;
061:
062:                kb = new AdvancedKnowledgeBase();
063:
064:                // create predicates
065:                Class[] struct = { String.class, String.class };
066:                Predicate predicate_is_brother = new SimplePredicate(
067:                        "is_brother_of", struct);
068:                Predicate predicate_is_oncle = new SimplePredicate(
069:                        "is_oncle_of", struct);
070:                Predicate predicate_is_son = new SimplePredicate("is_son_of",
071:                        struct);
072:                Predicate predicate_is_grandfather = new SimplePredicate(
073:                        "is_grandfather_of", struct);
074:                Predicate predicate_is_father = new SimplePredicate(
075:                        "is_father_of", struct);
076:
077:                // add rules and facts
078:
079:                Rule rule1 = lfs.rule(lfs.prereq(predicate_is_father, lfs
080:                        .variable("person 1"), lfs.variable("person 2")), lfs
081:                        .fact(predicate_is_son, lfs.variable("person 2"), lfs
082:                                .variable("person 1")));
083:                kb.add(rule1);
084:                Rule rule2 = lfs.rule(lfs.prereq(predicate_is_father, lfs
085:                        .variable("person 1"), lfs.variable("person 2")), lfs
086:                        .prereq(predicate_is_father, lfs.variable("person 2"),
087:                                lfs.variable("person 3")), lfs.fact(
088:                        predicate_is_grandfather, lfs.variable("person 1"), lfs
089:                                .variable("person 3")));
090:                kb.add(rule2);
091:                Rule rule3 = lfs
092:                        .rule(
093:                                lfs.prereq(predicate_is_father, lfs
094:                                        .variable("person 1"), lfs
095:                                        .variable("person 3")),
096:                                lfs.prereq(predicate_is_father, lfs
097:                                        .variable("person 2"), lfs
098:                                        .variable("person 3")),
099:                                lfs
100:                                        .prereq(
101:                                                org.mandarax.lib.text.StringArithmetic.NOT_EQUAL,
102:                                                lfs.variable("person 1"), lfs
103:                                                        .variable("person 2")),
104:                                lfs.fact(predicate_is_brother, lfs
105:                                        .variable("person 1"), lfs
106:                                        .variable("person 2")));
107:                kb.add(rule3);
108:                Rule rule4 = lfs.rule(lfs.prereq(predicate_is_father, lfs
109:                        .variable("person 1"), lfs.variable("person 2")), lfs
110:                        .prereq(predicate_is_brother, lfs.variable("person 2"),
111:                                lfs.variable("person 3")), lfs.fact(
112:                        predicate_is_oncle, lfs.variable("person 1"), lfs
113:                                .variable("person 3")));
114:                kb.add(rule4);
115:                kb.add(lfs.fact(predicate_is_father, "Frank", "Lutz"));
116:                kb.add(lfs.fact(predicate_is_father, "Guenther", "Otto"));
117:                kb.add(lfs.fact(predicate_is_father, "Jens", "Klaus"));
118:                kb.add(lfs.fact(predicate_is_father, "Klaus", "Otto"));
119:                kb.add(lfs.fact(predicate_is_father, "Lutz", "Otto"));
120:                kb.add(lfs.fact(predicate_is_father, "Max", "Jens"));
121:                kb.add(lfs.fact(predicate_is_father, "Ralf", "Lutz"));
122:                kb.add(lfs.fact(predicate_is_father, "Werner", "Otto"));
123:
124:                return kb;
125:            }
126:
127:            /**
128:             * Create the xkb file if it does not exist.
129:             */
130:            static void createXKB() throws Exception {
131:                File file = new File(XKB_FILE);
132:                if (!initialized || !file.exists()) {
133:                    KnowledgeBase kb = createKB();
134:                    XKBManager xkbManager = new XKBManager();
135:                    xkbManager.setDriver(new XKBDriver_2_1());
136:                    xkbManager.exportKnowledgeBase(file, kb);
137:                }
138:            }
139:
140:            /**
141:             * Create the ruleml file if it does not exist.
142:             */
143:            static void createRULE_ML() throws Exception {
144:                File file = new File(RULE_ML_FILE);
145:                if (!initialized || !file.exists()) {
146:                    KnowledgeBase kb = createKB();
147:                    XKBManager xkbManager = new XKBManager();
148:                    xkbManager.setDriver(new RuleML0_8_1Driver());
149:                    xkbManager.exportKnowledgeBase(file, kb);
150:                }
151:            }
152:
153:            /**
154:             * Create the zkb file if it does not exist.
155:             */
156:            static void createZKB() throws Exception {
157:                File file = new File(ZKB_FILE);
158:                if (!initialized || !file.exists()) {
159:                    KnowledgeBase kb = createKB();
160:                    ZKBManager zkbManager = new ZKBManager();
161:                    zkbManager.exportKnowledgeBase(file, kb);
162:                }
163:            }
164:
165:            /**
166:             * Setup - create all files.
167:             */
168:            public static void setup() throws Exception {
169:                createXKB();
170:                createZKB();
171:                createRULE_ML();
172:                initialized = true;
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.