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: import org.mandarax.reference.DefaultLoopCheckingAlgorithm;
025:
026: /**
027: * Simple test to show how to handle loops.
028: * @see org.mandarax.reference.ResolutionInferenceEngine
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 TestInferenceEngine8 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 TestInferenceEngine8(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: knowledge.add(Person.getRule("isBrotherOf", "x", "y",
052: "isBrotherOf", "y", "x"));
053: knowledge.add(Person.getFact("isBrotherOf", "Lutz", "Klaus"));
054: }
055:
056: /**
057: * Get a description of this test case.
058: * This is used by the <code>org.mandarax.demo</code>
059: * package to display the test cases.
060: * @return a brief description of the test case
061: */
062: public String getDescription() {
063: StringBuffer buf = new StringBuffer();
064:
065: buf.append("Very simple test to show how to handle loops.");
066:
067: return new String(buf);
068: }
069:
070: /**
071: * Get the name of the person we are looking for.
072: * More precisely, this is the name of the person expected to
073: * replace the query variable as a result of the query.
074: * @return the name of the person
075: */
076: String getPersonName() {
077: return "Lutz";
078: }
079:
080: /**
081: * Get the query.
082: * @return a query
083: */
084: public Query getQuery() {
085: return Person.getQuery("isBrotherOf", "Klaus", QUERY_VARIABLE);
086: }
087:
088: /**
089: * Sets up the fixture.
090: */
091: protected void setUp() {
092: super .setUp();
093:
094: if (ie instanceof AbstractResolutionInferenceEngine) {
095: AbstractResolutionInferenceEngine rie = (AbstractResolutionInferenceEngine) ie;
096:
097: rie
098: .setLoopCheckingAlgorithm(new DefaultLoopCheckingAlgorithm(
099: 5, 5, 5));
100: } else {
101: LOG_TEST
102: .warn("Loop checks are currently only supported by the ResolutionInferenceEngine !");
103: }
104: }
105: }
|