1 10 package com.hp.hpl.jena.reasoner.rulesys.test; 11 12 import com.hp.hpl.jena.reasoner.*; 13 import com.hp.hpl.jena.reasoner.test.*; 14 import com.hp.hpl.jena.util.FileManager; 15 import com.hp.hpl.jena.vocabulary.OWL; 17 import com.hp.hpl.jena.vocabulary.RDF; 18 import com.hp.hpl.jena.vocabulary.RDFS; 19 import com.hp.hpl.jena.reasoner.rdfsReasoner1.RDFSReasonerFactory; 20 import com.hp.hpl.jena.reasoner.rulesys.*; 21 import com.hp.hpl.jena.rdf.model.*; 22 23 import junit.framework.TestCase; 24 import junit.framework.TestSuite; 25 import java.io.IOException ; 26 import java.util.Iterator ; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 35 public class TestRDFSRules extends TestCase { 36 37 public static final String NAMESPACE = "http://www.hpl.hp.com/semweb/2003/query_tester/"; 38 39 protected static Log logger = LogFactory.getLog(TestRDFSRules.class); 40 41 44 public TestRDFSRules( String name ) { 45 super( name ); 46 } 47 48 52 public static TestSuite suite() { 53 return new TestSuite(TestRDFSRules.class); 54 } 58 59 62 public void hiddenTestRDFSReasonerDebug() throws IOException { 63 ReasonerTester tester = new ReasonerTester("rdfs/manifest-nodirect-noresource.rdf"); 64 ReasonerFactory rf = RDFSRuleReasonerFactory.theInstance(); 65 66 assertTrue("RDFS hybrid-tgc reasoner test", tester.runTest("http://www.hpl.hp.com/semweb/2003/query_tester/rdfs/test11", rf, this, null)); 67 } 68 69 72 public void testRDFSFBReasoner() throws IOException { 73 ReasonerTester tester = new ReasonerTester("rdfs/manifest-nodirect-noresource.rdf"); 74 ReasonerFactory rf = RDFSFBRuleReasonerFactory.theInstance(); 75 assertTrue("RDFS hybrid reasoner tests", tester.runTests(rf, this, null)); 76 } 77 78 81 public void testRDFSExptReasoner() throws IOException { 82 ReasonerTester tester = new ReasonerTester("rdfs/manifest-nodirect-noresource.rdf"); 83 ReasonerFactory rf = RDFSRuleReasonerFactory.theInstance(); 84 assertTrue("RDFS experimental (hybrid+tgc) reasoner tests", tester.runTests(rf, this, null)); 85 } 86 87 90 public void testRDFSDescription() { 91 ReasonerFactory rf = RDFSFBRuleReasonerFactory.theInstance(); 92 Reasoner r = rf.create(null); 93 assertTrue(r.supportsProperty(RDFS.subClassOf)); 94 assertTrue(r.supportsProperty(RDFS.domain)); 95 assertTrue( ! r.supportsProperty(OWL.allValuesFrom)); 96 } 97 98 101 private static void doTiming(Reasoner r, Model tbox, Model data, String name, int loop) { 102 Resource C1 = ResourceFactory.createResource("http://www.hpl.hp.com/semweb/2003/eg#C1"); 103 Resource C2 = ResourceFactory.createResource("http://www.hpl.hp.com/semweb/2003/eg#C2"); 104 105 long t1 = System.currentTimeMillis(); 106 int count = 0; 107 for (int lp = 0; lp < loop; lp++) { 108 Model m = ModelFactory.createModelForGraph(r.bindSchema(tbox.getGraph()).bind(data.getGraph())); 109 count = 0; 110 for (Iterator i = m.listStatements(null, RDF.type, C1); i.hasNext(); i.next()) count++; 111 } 112 long t2 = System.currentTimeMillis(); 113 long time10 = (t2-t1)*10/loop; 114 long time = time10/10; 115 long timeFraction = time10 - (time*10); 116 System.out.println(name + ": " + count +" results in " + time + "." + timeFraction +"ms"); 117 } 125 126 134 public static void main(String [] args) { 135 try { 136 Model tbox = FileManager.get().loadModel("testing/reasoners/rdfs/timing-tbox.rdf"); 137 Model data = FileManager.get().loadModel("testing/reasoners/rdfs/timing-data.rdf"); 138 Reasoner rdfsFBRule = RDFSFBRuleReasonerFactory.theInstance().create(null); 139 Reasoner rdfs1 = RDFSReasonerFactory.theInstance().create(null); 140 Reasoner rdfsFinal = RDFSRuleReasonerFactory.theInstance().create(null); 141 142 doTiming(rdfs1, tbox, data, "RDFS1", 1); 143 doTiming(rdfsFBRule, tbox, data, "RDFS FB rule", 1); 144 doTiming(rdfsFinal, tbox, data, "RDFS final rule", 1); 145 doTiming(rdfs1, tbox, data, "RDFS1", 50); 146 doTiming(rdfsFBRule, tbox, data, "RDFS FB rule", 50); 147 doTiming(rdfsFinal, tbox, data, "RDFS final rule", 50); 148 149 } catch (Exception e) { 150 System.out.println("Problem: " + e.toString()); 151 e.printStackTrace(); 152 } 153 } 154 155 } 156 157 186 187 | Popular Tags |