01: /*
02: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens
03: * Dietrich </a>
04: *
05: * This library is free software; you can redistribute it and/or modify it under
06: * the terms of the GNU Lesser General Public License as published by the Free
07: * Software Foundation; either version 2 of the License, or (at your option) any
08: * later version.
09: *
10: * This library is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13: * details.
14: *
15: * You should have received a copy of the GNU Lesser General Public License
16: * along with this library; if not, write to the Free Software Foundation, Inc.,
17: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package test.org.mandarax.rdf;
20:
21: import java.net.URL;
22: import java.util.List;
23: import org.mandarax.kernel.ClauseSet;
24: import org.mandarax.kernel.KnowledgeBase;
25: import org.mandarax.kernel.Predicate;
26: import org.mandarax.rdf.RDFClauseSet;
27: import org.mandarax.rdf.RDFUtils;
28: import org.mandarax.reference.AdvancedKnowledgeBase;
29:
30: /**
31: * Test case for the integration of RDFClauseSets into knowledge bases. In
32: * particular, we test here whether indexing works correctly (unlike
33: * SQLClauseSets, RDFClauseSets contain generally more than one predicates).
34: * @author <A HREF="mailto:j.b.dietrich@massey.ac.nz">Jens Dietrich </A> <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
35: * @version 1.1 <01 August 2004>
36: * @since 0.1
37: */
38: public class RDFClauseSetKBIntegrationTestCase extends
39: AbstractRDFTestCase {
40: /**
41: * Check whether the clause set is correctly indexed for all of the
42: * predicates it contains.
43: * @throws an exception (indicating that the test case has failed)
44: */
45: public void test1() throws Exception {
46: KnowledgeBase kb = new AdvancedKnowledgeBase();
47: URL url = this .getClass().getResource(
48: TEST_DATA_ROOT + "chap0302.rdf");
49: RDFClauseSet clauseSet = new RDFClauseSet(url);
50: // this line is ok for testing, but should not be used for
51: // with large amounts real world
52: clauseSet.setPredicates(RDFUtils.findPredicates(url));
53: kb.add(clauseSet);
54: // the predicates in clauseSet
55: Predicate p1 = p(PSTCN, "author");
56: Predicate p2 = p(PSTCN, "title");
57: Predicate p3 = p(PSTCN, "series");
58: Predicate p4 = p(PSTCN, "contains");
59: Predicate p5 = p(PSTCN, "alsoContains");
60: Predicate p6 = p(PSTCN, "seriesTitle");
61: testMembership(kb.getClauseSets(p1), clauseSet);
62: testMembership(kb.getClauseSets(p2), clauseSet);
63: testMembership(kb.getClauseSets(p3), clauseSet);
64: testMembership(kb.getClauseSets(p4), clauseSet);
65: testMembership(kb.getClauseSets(p5), clauseSet);
66: testMembership(kb.getClauseSets(p6), clauseSet);
67: assertTrue(true);
68: }
69:
70: /**
71: * Test whether a clause set is the only clause set in a list.
72: * @param cs a clause set
73: * @param list a list
74: * @exception an assertion error is thrown if there is none or more than one clause set in the list
75: */
76: private void testMembership(List list, ClauseSet cs)
77: throws Exception {
78: if (list.size() > 1)
79: assertTrue(
80: "More than one clause set found when only one clause set was expected",
81: false);
82: if (list.size() == 0)
83: assertTrue(
84: "No clause set found when one clause set was expected",
85: false);
86: if (list.get(0) != cs)
87: assertTrue("Wrong clause set found", false);
88: }
89:
90: }
|