01: /*
02: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package test.org.mandarax.reference;
19:
20: import org.mandarax.kernel.Fact;
21: import org.mandarax.kernel.InferenceEngine;
22: import org.mandarax.kernel.KnowledgeBase;
23: import org.mandarax.kernel.Query;
24: import org.mandarax.kernel.Rule;
25:
26: /**
27: * Very simple test to show how to derive from rules having their prerequisites connected by OR.
28: * @see org.mandarax.reference.ResolutionInferenceEngine
29: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
30: * @version 3.4 <7 March 05>
31: * @since 1.3
32: */
33: public class TestInferenceEngine9 extends TestInferenceEngine {
34:
35: /**
36: * Constructor.
37: * @param aKnowledgeBase a new, uninitialized knowledge base that will be used
38: * @param anInferenceEngine the inference engine that will be tested
39: */
40: public TestInferenceEngine9(KnowledgeBase aKnowledgeBase,
41: InferenceEngine anInferenceEngine) {
42: super (aKnowledgeBase, anInferenceEngine);
43: }
44:
45: /**
46: * Add facts and rules to the knowledge base.
47: * @param knowledge org.mandarax.kernel.KnowledgeBase
48: */
49: public void feedKnowledgeBase(KnowledgeBase knowledge) {
50: knowledge.removeAll();
51:
52: Fact prereq1 = Person.getFact("isBrotherOf", "x", "y");
53: Fact prereq2 = Person.getFact("isFatherOf", "x", "y");
54: Fact concl = Person.getFact("isRelativeOf", "x", "y");
55: Rule rule = (new org.mandarax.util.LogicFactorySupport())
56: .orRule(prereq1, prereq2, concl);
57:
58: knowledge.add(rule);
59: knowledge.add(Person.getFact("isBrotherOf", "Klaus", "Lutz"));
60: }
61:
62: /**
63: * Get a description of this test case.
64: * This is used by the <code>org.mandarax.demo</code>
65: * package to display the test cases.
66: * @return a brief description of the test case
67: */
68: public String getDescription() {
69: return "Simple derivation using a rule that has prerequisites connected by OR";
70: }
71:
72: /**
73: * Get the name of the person we are looking for.
74: * More precisely, this is the name of the person expected to
75: * replace the query variable as a result of the query.
76: * @return the name of the person
77: */
78: String getPersonName() {
79: return "Lutz";
80: }
81:
82: /**
83: * Get the query.
84: * @return a query
85: */
86: public Query getQuery() {
87: return Person.getQuery("isRelativeOf", "Klaus", QUERY_VARIABLE);
88: }
89: }
|