1 10 package com.hp.hpl.jena.reasoner.rulesys.test; 11 12 import com.hp.hpl.jena.graph.*; 13 import com.hp.hpl.jena.graph.compose.Union; 14 import com.hp.hpl.jena.mem.GraphMem; 15 import com.hp.hpl.jena.reasoner.*; 16 import com.hp.hpl.jena.reasoner.test.TestUtil; 17 import com.hp.hpl.jena.vocabulary.*; 18 19 import java.util.*; 20 21 import junit.framework.TestCase; 22 import junit.framework.TestSuite; 23 24 31 public class TestRDFS9 extends TestCase { 32 33 36 public TestRDFS9( String name ) { 37 super( name ); 38 } 39 40 44 public static TestSuite suite() { 45 return new TestSuite(TestRDFS9.class); 46 } 47 48 51 public void testRDFSInheritance() { 52 Node C1 = Node.createURI("C1"); 53 Node C2 = Node.createURI("C2"); 54 Node C3 = Node.createURI("C3"); 55 Node C4 = Node.createURI("C4"); 56 Node D = Node.createURI("D"); 57 Node a = Node.createURI("a"); 58 Node b = Node.createURI("b"); 59 Node p = Node.createURI("p"); 60 Node q = Node.createURI("q"); 61 Node r = Node.createURI("r"); 62 Node sC = RDFS.subClassOf.asNode(); 63 Node ty = RDF.type.asNode(); 64 65 Graph tdata = new GraphMem(); 66 tdata.add(new Triple(C1, sC, C2)); 67 tdata.add(new Triple(C2, sC, C3)); 68 tdata.add(new Triple(p, RDFS.subPropertyOf.asNode(), q)); 69 tdata.add(new Triple(q, RDFS.subPropertyOf.asNode(), r)); 70 tdata.add(new Triple(r, RDFS.domain.asNode(), D)); 71 Graph data = new GraphMem(); 72 data.add(new Triple(a, p, b)); 73 InfGraph igraph = ReasonerRegistry.getRDFSReasoner().bind(new Union(tdata, data)); 74 TestUtil.assertIteratorValues(this, igraph.find(a, ty, null), 75 new Object [] { 76 new Triple(a, ty, D), 77 new Triple(a, ty, RDFS.Resource.asNode()), 78 }); 79 boolean ok = false; 81 Triple target = new Triple(a,ty,D); 82 for (Iterator i = igraph.find(null,ty,null); i.hasNext(); ) { 83 Triple t = (Triple)i.next(); 84 if (t.equals(target)) { 85 ok = true; 86 break; 87 } 88 } 89 assertTrue(ok); 90 igraph = ReasonerRegistry.getRDFSReasoner().bindSchema(tdata).bind(data); 91 TestUtil.assertIteratorValues(this, igraph.find(a, ty, null), 92 new Object [] { 93 new Triple(a, ty, D), 94 new Triple(a, ty, RDFS.Resource.asNode()), 95 }); 96 ok = false; 98 target = new Triple(a,ty,D); 99 for (Iterator i = igraph.find(null,ty,null); i.hasNext(); ) { 100 Triple t = (Triple)i.next(); 101 if (t.equals(target)) { 102 ok = true; 103 break; 104 } 105 } 106 assertTrue(ok); 107 } 108 } 109 110 111 | Popular Tags |