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: import org.mandarax.reference.AbstractResolutionInferenceEngine;
024:
025: /**
026: * Combines functions and loop checking.
027: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
028: * @version 3.4 <7 March 05>
029: * @since 1.3
030: */
031: public class TestInferenceEngine10 extends TestInferenceEngine {
032:
033: /**
034: * Constructor.
035: * @param aKnowledgeBase a new, uninitialized knowledge base that will be used
036: * @param anInferenceEngine the inference engine that will be tested
037: */
038: public TestInferenceEngine10(KnowledgeBase aKnowledgeBase,
039: InferenceEngine anInferenceEngine) {
040: super (aKnowledgeBase, anInferenceEngine);
041: }
042:
043: /**
044: * Add facts and rules to the knowledge base.
045: * @param knowledge org.mandarax.kernel.KnowledgeBase
046: */
047: public void feedKnowledgeBase(KnowledgeBase knowledge) {
048: knowledge.removeAll();
049: knowledge.add(Person.getRule("equals", "y", "father(x)",
050: "equals", "x", "son(y)"));
051: knowledge.add(Person.getRule("equals", "y", "son(x)", "equals",
052: "x", "father(y)"));
053:
054: // facts
055: knowledge.add(Person.getFact("equals", "Jens", "father(Max)"));
056: }
057:
058: /**
059: * Get a description of this test case.
060: * This is used by the <code>org.mandarax.demo</code>
061: * package to display the test cases.
062: * @return a brief description of the test case
063: */
064: public String getDescription() {
065: return "Testing loop checking with functions";
066: }
067:
068: /**
069: * Get the name of the person we are looking for.
070: * More precisely, this is the name of the person expected to
071: * replace the query variable as a result of the query.
072: * @return the name of the person
073: */
074: String getPersonName() {
075: return "Jens";
076: }
077:
078: /**
079: * Get the query.
080: * @return a query
081: */
082: public Query getQuery() {
083: return Person.getQuery("equals", "Max", "son(" + QUERY_VARIABLE
084: + ")");
085: }
086:
087: /**
088: * Sets up the fixture.
089: */
090: protected void setUp() {
091: super .setUp();
092:
093: if (ie instanceof AbstractResolutionInferenceEngine) {
094: AbstractResolutionInferenceEngine rie = (AbstractResolutionInferenceEngine) ie;
095:
096: rie
097: .setLoopCheckingAlgorithm(new org.mandarax.reference.DefaultLoopCheckingAlgorithm(
098: 5, 5, 5));
099: } else {
100: LOG_TEST
101: .warn("Loop checks are currently only supported by the AbstractResolutionInferenceEngine !");
102: }
103: }
104: }
|