001: /*
002: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">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: package test.org.mandarax.reference;
019:
020: import org.mandarax.kernel.InferenceEngine;
021: import org.mandarax.kernel.KnowledgeBase;
022: import org.mandarax.kernel.Query;
023:
024: /**
025: * Combination of sample 1 and 2. The basic structure is taken from 1,
026: * but we use functions like in 2.
027: * @see test.org.mandarax.reference.TestInferenceEngine1
028: * @see test.org.mandarax.reference.TestInferenceEngine2
029: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
030: * @version 3.4 <7 March 05>
031: * @since 1.1
032: */
033: public class TestInferenceEngine5 extends TestInferenceEngine {
034:
035: /**
036: * Constructor.
037: * @param aKnowledgeBase a new, uninitialized knowledge base that will be used
038: * @param anInferenceEngine the inference engine that will be tested
039: */
040: public TestInferenceEngine5(KnowledgeBase aKnowledgeBase,
041: InferenceEngine anInferenceEngine) {
042: super (aKnowledgeBase, anInferenceEngine);
043: }
044:
045: /**
046: * Add facts and rules to the knowledge base.
047: * @param knowledge org.mandarax.kernel.KnowledgeBase
048: */
049: public void feedKnowledgeBase(KnowledgeBase knowledge) {
050: knowledge.removeAll();
051:
052: // the actual inference rules
053: knowledge.add(Person.getRule("isGrandFatherOf", "x", "z",
054: "isFatherOf", "y", "z", "isFatherOf", "x", "y"));
055: knowledge.add(Person.getRule("isOncleOf", "x", "z",
056: "isFatherOf", "y", "z", "isBrotherOf", "x", "y"));
057: knowledge.add(Person.getRule("isOncleOf", "x", "z",
058: "isGrandFatherOf", "y", "z", "isBrotherOf", "x", "y"));
059: knowledge.add(Person.getRule("isGrandFatherOf", "z", "x",
060: "isFatherOf", "y", "x", "isFatherOf", "z", "y"));
061:
062: // rules defining predicates
063: knowledge.add(Person.getRule("isFatherOf", "x", "y", "equals",
064: "x", "father(y)"));
065: knowledge.add(Person.getRule("isBrotherOf", "x", "y", "equals",
066: "z", "father(y)", "equals", "z", "father(x)",
067: "equalsNot", "x", "y"));
068:
069: // facts
070: knowledge
071: .add(Person.getFact("equals", "Klaus", "father(Jens)"));
072: knowledge
073: .add(Person.getFact("equals", "Otto", "father(Klaus)"));
074: knowledge.add(Person.getFact("equals", "Otto", "father(Lutz)"));
075: knowledge.add(Person.getFact("equals", "Jens", "father(Max)"));
076:
077: // facts just loop and add for all possible combinations either an equal or equals not fact
078: String[] names1 = { "Max", "Jens", "Klaus", "Otto", "Lutz" };
079: String[] names2 = { "Max", "Jens", "Klaus", "Otto", "Lutz" };
080: Person p1, p2 = null;
081:
082: for (int i = 0; i < names1.length; i++) {
083: p1 = Person.get(names1[i]);
084:
085: for (int j = 0; j < i; j++) {
086: p2 = Person.get(names2[j]);
087:
088: if (p1.equalsNot(p2)) {
089: knowledge.add(Person.getFact("equalsNot",
090: names1[i], names2[j]));
091: }
092: }
093: }
094:
095: // knowledge.add(Person.getFact("isBrotherOf","Lutz","Klaus"));
096: }
097:
098: /**
099: * Get a description of this test case.
100: * This is used by the <code>org.mandarax.demo</code>
101: * package to display the test cases.
102: * @return a brief description of the test case
103: */
104: public String getDescription() {
105: return "Combination of sample 1 and 2.\nThe basic structure is taken from 1,\nbut we use functions like in 2.";
106: }
107:
108: /**
109: * Get the name of the person we are looking for.
110: * More precisely, this is the name of the person expected to
111: * replace the query variable as a result of the query.
112: * @return the name of the person
113: */
114: String getPersonName() {
115: return "Lutz";
116: }
117:
118: /**
119: * Get the query.
120: * @return a query
121: */
122: public Query getQuery() {
123: return Person.getQuery("isOncleOf", QUERY_VARIABLE, "Max");
124: }
125: }
|