001: /******************************************************************
002: * File: TestRDFS9.java
003: * Created by: Dave Reynolds
004: * Created on: 24-Jun-2003
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: TestRDFS9.java,v 1.8 2008/01/02 12:08:19 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.test;
010:
011: import com.hp.hpl.jena.graph.*;
012: import com.hp.hpl.jena.graph.compose.Union;
013: import com.hp.hpl.jena.reasoner.*;
014: import com.hp.hpl.jena.reasoner.test.TestUtil;
015: import com.hp.hpl.jena.vocabulary.*;
016:
017: import java.util.*;
018:
019: import junit.framework.TestCase;
020: import junit.framework.TestSuite;
021:
022: /**
023: * Test harness used in debugging some issues with execution
024: * of modified versions of rule rdfs9.
025: *
026: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
027: * @version $Revision: 1.8 $ on $Date: 2008/01/02 12:08:19 $
028: */
029: public class TestRDFS9 extends TestCase {
030:
031: /**
032: * Boilerplate for junit
033: */
034: public TestRDFS9(String name) {
035: super (name);
036: }
037:
038: /**
039: * Boilerplate for junit.
040: * This is its own test suite
041: */
042: public static TestSuite suite() {
043: return new TestSuite(TestRDFS9.class);
044: }
045:
046: /**
047: * Test a type inheritance example.
048: */
049: public void testRDFSInheritance() {
050: Node C1 = Node.createURI("C1");
051: Node C2 = Node.createURI("C2");
052: Node C3 = Node.createURI("C3");
053: Node C4 = Node.createURI("C4");
054: Node D = Node.createURI("D");
055: Node a = Node.createURI("a");
056: Node b = Node.createURI("b");
057: Node p = Node.createURI("p");
058: Node q = Node.createURI("q");
059: Node r = Node.createURI("r");
060: Node sC = RDFS.subClassOf.asNode();
061: Node ty = RDF.type.asNode();
062:
063: Graph tdata = Factory.createGraphMem();
064: tdata.add(new Triple(C1, sC, C2));
065: tdata.add(new Triple(C2, sC, C3));
066: tdata.add(new Triple(p, RDFS.subPropertyOf.asNode(), q));
067: tdata.add(new Triple(q, RDFS.subPropertyOf.asNode(), r));
068: tdata.add(new Triple(r, RDFS.domain.asNode(), D));
069: Graph data = Factory.createGraphMem();
070: data.add(new Triple(a, p, b));
071: InfGraph igraph = ReasonerRegistry.getRDFSReasoner().bind(
072: new Union(tdata, data));
073: TestUtil.assertIteratorValues(this , igraph.find(a, ty, null),
074: new Object[] { new Triple(a, ty, D),
075: new Triple(a, ty, RDFS.Resource.asNode()), });
076: // Check if first of these is in the wildcard listing
077: boolean ok = false;
078: Triple target = new Triple(a, ty, D);
079: for (Iterator i = igraph.find(null, ty, null); i.hasNext();) {
080: Triple t = (Triple) i.next();
081: if (t.equals(target)) {
082: ok = true;
083: break;
084: }
085: }
086: assertTrue(ok);
087: igraph = ReasonerRegistry.getRDFSReasoner().bindSchema(tdata)
088: .bind(data);
089: TestUtil.assertIteratorValues(this , igraph.find(a, ty, null),
090: new Object[] { new Triple(a, ty, D),
091: new Triple(a, ty, RDFS.Resource.asNode()), });
092: // Check if first of these is in the wildcard listing
093: ok = false;
094: target = new Triple(a, ty, D);
095: for (Iterator i = igraph.find(null, ty, null); i.hasNext();) {
096: Triple t = (Triple) i.next();
097: if (t.equals(target)) {
098: ok = true;
099: break;
100: }
101: }
102: assertTrue(ok);
103: }
104: }
105:
106: /*
107: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
108: All rights reserved.
109:
110: Redistribution and use in source and binary forms, with or without
111: modification, are permitted provided that the following conditions
112: are met:
113:
114: 1. Redistributions of source code must retain the above copyright
115: notice, this list of conditions and the following disclaimer.
116:
117: 2. Redistributions in binary form must reproduce the above copyright
118: notice, this list of conditions and the following disclaimer in the
119: documentation and/or other materials provided with the distribution.
120:
121: 3. The name of the author may not be used to endorse or promote products
122: derived from this software without specific prior written permission.
123:
124: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
125: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
126: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
127: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
128: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
129: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
130: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
131: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
132: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
133: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
134: */
|