001: /*
002: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens
003: * Dietrich </a>
004: *
005: * This library is free software; you can redistribute it and/or modify it under
006: * the terms of the GNU Lesser General Public License as published by the Free
007: * Software Foundation; either version 2 of the License, or (at your option) any
008: * later version.
009: *
010: * This library is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
012: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
013: * details.
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software Foundation, Inc.,
017: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package test.org.mandarax.rdf;
020:
021: import java.net.URL;
022: import org.mandarax.kernel.*;
023: import org.mandarax.rdf.RDFClauseSet;
024: import org.mandarax.rdf.RDFUtils;
025: import org.mandarax.reference.AdvancedKnowledgeBase;
026: import org.mandarax.reference.ResolutionInferenceEngine2;
027: import com.hp.hpl.jena.rdf.model.RDFNode;
028: import com.hp.hpl.jena.rdf.model.Resource;
029:
030: /**
031: * Test case to test the interaction with IE. This tests in particular the <code>clauses(Clause,Object)</code> method
032: * which is called by the IE when knowledge is requested to proof a certain goal.
033: * @author <A HREF="mailto:j.b.dietrich@massey.ac.nz">Jens Dietrich </A> <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
034: * @version 1.1 <01 August 2004>
035: * @since 0.1
036: */
037: public class RDFClauseSetIEIntegrationTestCase extends
038: AbstractRDFTestCase {
039: /**
040: * Generic test. Add clause set, and query IE with this kb.
041: * @param predicateNS a predicate name space
042: * @param predicateLN a predicate local name
043: * @param expectedSubject the expected subject (a resource)
044: * @param expectedObject the expected object (a resource or literal)
045: * @throws an exception (indicating that the test case has failed)
046: */
047: private void test(String predicateNS, String predicateLN,
048: Object expectedSubject, Object expectedObject)
049: throws Exception {
050: KnowledgeBase kb = new AdvancedKnowledgeBase();
051: InferenceEngine ie = new ResolutionInferenceEngine2();
052: // add knowledge
053: URL url = this .getClass().getResource(
054: TEST_DATA_ROOT + "chap0302.rdf");
055: RDFClauseSet clauseSet = new RDFClauseSet(url);
056: // this line is ok for testing, but should not be used for
057: // with large amounts real world
058: clauseSet.setPredicates(RDFUtils.findPredicates(url));
059: kb.add(clauseSet);
060: // build query
061: Predicate p = p(predicateNS, predicateLN);
062: Query query = lfactory.createQuery(lfactory.createFact(p,
063: new Term[] {
064: lfactory.createVariableTerm("subject",
065: Resource.class),
066: lfactory.createVariableTerm("object",
067: RDFNode.class) }), "query");
068: // issue query and compare results
069: ResultSet rs = ie.query(query, kb, InferenceEngine.ALL,
070: InferenceEngine.BUBBLE_EXCEPTIONS);
071:
072: if (!rs.next())
073: assertTrue(
074: "No result found when one result was expected, predicate: "
075: + p, false);
076: Object foundSubject = rs.getResult(Resource.class, "subject");
077: Object foundObject = rs.getResult(RDFNode.class, "object");
078: if (rs.next())
079: assertTrue(
080: "More than one result found when one result was expected, predicate: "
081: + p, false);
082: assertTrue(expectedSubject.equals(foundSubject)
083: && expectedObject.equals(foundObject));
084:
085: }
086:
087: /**
088: * Test 1.
089: * @throws an exception (indicating that the test case has failed)
090: */
091: public void test1() throws Exception {
092: test(PSTCN, "author",
093: sub("http://burningbird.net/articles/monster3.htm"),
094: lit("Shelley Powers"));
095: }
096:
097: /**
098: * Test 2.
099: * @throws an exception (indicating that the test case has failed)
100: */
101: public void test2() throws Exception {
102: test(PSTCN, "title",
103: sub("http://burningbird.net/articles/monster3.htm"),
104: lit("Architeuthis Dux"));
105: }
106:
107: /**
108: * Test 3.
109: * @throws an exception (indicating that the test case has failed)
110: */
111: public void test3() throws Exception {
112: test(PSTCN, "series",
113: sub("http://burningbird.net/articles/monster3.htm"),
114: obj("http://burningbird.net/articles/monsters.htm"));
115: }
116:
117: /**
118: * Test 4.
119: * @throws an exception (indicating that the test case has failed)
120: */
121: public void test4() throws Exception {
122: test(PSTCN, "contains",
123: sub("http://burningbird.net/articles/monster3.htm"),
124: lit("Physical description of giant squids"));
125: }
126:
127: /**
128: * Test 5.
129: * @throws an exception (indicating that the test case has failed)
130: */
131: public void test5() throws Exception {
132: test(PSTCN, "alsoContains",
133: sub("http://burningbird.net/articles/monster3.htm"),
134: lit("Tale of the Legendary Kraken"));
135: }
136:
137: /**
138: * Test 6.
139: * @throws an exception (indicating that the test case has failed)
140: */
141: public void test6() throws Exception {
142: test(PSTCN, "seriesTitle",
143: sub("http://burningbird.net/articles/monsters.htm"),
144: lit("A Tale of Two Monsters"));
145: }
146:
147: }
|