001: /******************************************************************
002: * File: TestRDFSRules.java
003: * Created by: Dave Reynolds
004: * Created on: 08-Apr-03
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: TestRDFSRules.java,v 1.24 2008/01/02 12:08:20 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.test;
010:
011: import com.hp.hpl.jena.reasoner.*;
012: import com.hp.hpl.jena.reasoner.test.*;
013: import com.hp.hpl.jena.util.FileManager; // import com.hp.hpl.jena.util.PrintUtil;
014: import com.hp.hpl.jena.vocabulary.OWL;
015: import com.hp.hpl.jena.vocabulary.RDF;
016: import com.hp.hpl.jena.vocabulary.RDFS;
017: import com.hp.hpl.jena.reasoner.rdfsReasoner1.RDFSReasonerFactory;
018: import com.hp.hpl.jena.reasoner.rulesys.*;
019: import com.hp.hpl.jena.rdf.model.*;
020:
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023: import java.io.IOException;
024: import java.util.Iterator;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: /** * Test suite to test the production rule version of the RDFS implementation.
029: * <p> The tests themselves have been replaced by an updated version
030: * of the top level TestRDFSReasoners but this file is maintained for now since
031: * the top level timing test can sometimes be useful. </p>
032: * * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a> * @version $Revision: 1.24 $ on $Date: 2008/01/02 12:08:20 $ */
033: public class TestRDFSRules extends TestCase {
034: /** Base URI for the test names */
035: public static final String NAMESPACE = "http://www.hpl.hp.com/semweb/2003/query_tester/";
036:
037: protected static Log logger = LogFactory
038: .getLog(TestRDFSRules.class);
039:
040: /**
041: * Boilerplate for junit
042: */
043: public TestRDFSRules(String name) {
044: super (name);
045: }
046:
047: /**
048: * Boilerplate for junit.
049: * This is its own test suite
050: */
051: public static TestSuite suite() {
052: return new TestSuite(TestRDFSRules.class);
053: // TestSuite suite = new TestSuite();
054: // suite.addTest(new TestRDFSRules( "hiddenTestRDFSReasonerDebug" ));
055: // return suite;
056: }
057:
058: /**
059: * Test a single RDFS case.
060: */
061: public void hiddenTestRDFSReasonerDebug() throws IOException {
062: ReasonerTester tester = new ReasonerTester(
063: "rdfs/manifest-nodirect-noresource.rdf");
064: ReasonerFactory rf = RDFSRuleReasonerFactory.theInstance();
065:
066: assertTrue(
067: "RDFS hybrid-tgc reasoner test",
068: tester
069: .runTest(
070: "http://www.hpl.hp.com/semweb/2003/query_tester/rdfs/test11",
071: rf, this , null));
072: }
073:
074: /**
075: * Test the basic functioning of the hybrid RDFS rule reasoner
076: */
077: public void testRDFSFBReasoner() throws IOException {
078: ReasonerTester tester = new ReasonerTester(
079: "rdfs/manifest-nodirect-noresource.rdf");
080: ReasonerFactory rf = RDFSFBRuleReasonerFactory.theInstance();
081: assertTrue("RDFS hybrid reasoner tests", tester.runTests(rf,
082: this , null));
083: }
084:
085: /**
086: * Test the basic functioning of the hybrid RDFS rule reasoner with TGC cache
087: */
088: public void testRDFSExptReasoner() throws IOException {
089: ReasonerTester tester = new ReasonerTester(
090: "rdfs/manifest-nodirect-noresource.rdf");
091: ReasonerFactory rf = RDFSRuleReasonerFactory.theInstance();
092: assertTrue("RDFS experimental (hybrid+tgc) reasoner tests",
093: tester.runTests(rf, this , null));
094: }
095:
096: /**
097: * Test the capabilities description.
098: */
099: public void testRDFSDescription() {
100: ReasonerFactory rf = RDFSFBRuleReasonerFactory.theInstance();
101: Reasoner r = rf.create(null);
102: assertTrue(r.supportsProperty(RDFS.subClassOf));
103: assertTrue(r.supportsProperty(RDFS.domain));
104: assertTrue(!r.supportsProperty(OWL.allValuesFrom));
105: }
106:
107: /**
108: * Time a trial list of results from an inf graph.
109: */
110: private static void doTiming(Reasoner r, Model tbox, Model data,
111: String name, int loop) {
112: Resource C1 = ResourceFactory
113: .createResource("http://www.hpl.hp.com/semweb/2003/eg#C1");
114: Resource C2 = ResourceFactory
115: .createResource("http://www.hpl.hp.com/semweb/2003/eg#C2");
116:
117: long t1 = System.currentTimeMillis();
118: int count = 0;
119: for (int lp = 0; lp < loop; lp++) {
120: Model m = ModelFactory.createModelForGraph(r.bindSchema(
121: tbox.getGraph()).bind(data.getGraph()));
122: count = 0;
123: for (Iterator i = m.listStatements(null, RDF.type, C1); i
124: .hasNext(); i.next())
125: count++;
126: }
127: long t2 = System.currentTimeMillis();
128: long time10 = (t2 - t1) * 10 / loop;
129: long time = time10 / 10;
130: long timeFraction = time10 - (time * 10);
131: System.out.println(name + ": " + count + " results in " + time
132: + "." + timeFraction + "ms");
133: // t1 = System.currentTimeMillis();
134: // for (int j = 0; j < 10; j++) {
135: // count = 0;
136: // for (Iterator i = m.listStatements(null, RDF.type, C1); i.hasNext(); i.next()) count++;
137: // }
138: // t2 = System.currentTimeMillis();
139: // System.out.println(name + ": " + count + " results in " + (t2-t1)/10 +"ms");
140: }
141:
142: /**
143: * Simple timing test used to just a broad feel for how performance of the
144: * pure FPS rules compares with the hand-crafted version.
145: * The test ontology and data is very small. The test query is designed to
146: * require an interesting fraction of the inferences to be made but not all of them.
147: * The bigger the query the more advantage the FPS (which eagerly computes everything)
148: * would have over the normal approach.
149: */
150: public static void main(String[] args) {
151: try {
152: Model tbox = FileManager.get().loadModel(
153: "testing/reasoners/rdfs/timing-tbox.rdf");
154: Model data = FileManager.get().loadModel(
155: "testing/reasoners/rdfs/timing-data.rdf");
156: Reasoner rdfsFBRule = RDFSFBRuleReasonerFactory
157: .theInstance().create(null);
158: Reasoner rdfs1 = RDFSReasonerFactory.theInstance().create(
159: null);
160: Reasoner rdfsFinal = RDFSRuleReasonerFactory.theInstance()
161: .create(null);
162:
163: doTiming(rdfs1, tbox, data, "RDFS1", 1);
164: doTiming(rdfsFBRule, tbox, data, "RDFS FB rule", 1);
165: doTiming(rdfsFinal, tbox, data, "RDFS final rule", 1);
166: doTiming(rdfs1, tbox, data, "RDFS1", 50);
167: doTiming(rdfsFBRule, tbox, data, "RDFS FB rule", 50);
168: doTiming(rdfsFinal, tbox, data, "RDFS final rule", 50);
169:
170: } catch (Exception e) {
171: System.out.println("Problem: " + e.toString());
172: e.printStackTrace();
173: }
174: }
175:
176: }
177:
178: /*
179: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
180: All rights reserved.
181:
182: Redistribution and use in source and binary forms, with or without
183: modification, are permitted provided that the following conditions
184: are met:
185:
186: 1. Redistributions of source code must retain the above copyright
187: notice, this list of conditions and the following disclaimer.
188:
189: 2. Redistributions in binary form must reproduce the above copyright
190: notice, this list of conditions and the following disclaimer in the
191: documentation and/or other materials provided with the distribution.
192:
193: 3. The name of the author may not be used to endorse or promote products
194: derived from this software without specific prior written permission.
195:
196: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
197: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
198: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
200: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
202: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
203: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
204: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
205: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
206: */
|