Update of /cvsroot/cweb/bigdata-rdf/src/test/com/bigdata/rdf/inf In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv22601/src/test/com/bigdata/rdf/inf Modified Files: TestFullForwardClosure.java TestAll.java TestRuleRdfs11.java Added Files: AbstractRuleTestCase.java TestRuleRdfs07.java Log Message: testing SAIL and lubm, including adding BTree#removeAll(), touching up some inferences, making it possible to load different RDF interchange formats, and adding JOIN ordering based on the sesame optimizer and the actual triple pattern selectivity in the data. Index: TestFullForwardClosure.java =================================================================== RCS file: /cvsroot/cweb/bigdata-rdf/src/test/com/bigdata/rdf/inf/TestFullForwardClosure.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TestFullForwardClosure.java 14 Apr 2007 13:49:58 -0000 1.8 --- TestFullForwardClosure.java 18 Apr 2007 17:29:06 -0000 1.9 *************** *** 51,54 **** --- 51,56 ---- import java.io.IOException; + import org.openrdf.sesame.constants.RDFFormat; + /** * Test suite for full forward closure. *************** *** 84,96 **** */ ! store.loadData(new File("data/alibaba_v41.rdf"),"",false); ! ! store.loadData(new File("data/nciOncology.owl"),"",false); /* * Wordnet schema + nouns (two source files). */ ! // store.loadData(new File("data/wordnet-20000620.rdfs"), "", false); ! // store.loadData(new File("data/wordnet_nouns-20010201.rdf"), "", false); store.fullForwardClosure(); --- 86,131 ---- */ ! /* ! rule ms #entms entms/ms ! RuleRdf01 140 38 0 ! RuleRdfs02 0 0 0 ! RuleRdfs03 0 0 0 ! RuleRdfs05 0 592 0 ! RuleRdfs06 0 202 0 ! RuleRdfs07 110 97801 889 ! RuleRdfs08 0 330 0 ! RuleRdfs09 1687 31680 18 ! RuleRdfs10 0 330 0 ! RuleRdfs11 16 990 61 ! RuleRdfs12 0 0 0 ! RuleRdfs13 0 0 0 ! ! rule ms #entms entms/ms ! RuleRdf01 172 38 0 ! RuleRdfs02 0 0 0 ! RuleRdfs03 0 0 0 ! RuleRdfs05 0 592 0 ! RuleRdfs06 0 202 0 ! RuleRdfs07 109 97801 897 ! RuleRdfs08 0 330 0 ! RuleRdfs09 1687 31680 18 ! RuleRdfs10 0 330 0 ! RuleRdfs11 16 990 61 ! RuleRdfs12 0 0 0 ! RuleRdfs13 0 0 0 ! */ ! store.loadData(new File("data/alibaba_v41.rdf"), "", RDFFormat.RDFXML, ! false/* verifyData */, false/* commit */); ! ! // store.loadData(new File("data/nciOncology.owl"), "", RDFFormat.RDFXML, ! // false/* verifyData */, false/*commit*/); /* * Wordnet schema + nouns (two source files). */ ! // store.loadData(new File("data/wordnet-20000620.rdfs"), "", ! // RDFFormat.RDFXML, false/* verifyData */, false/* commit */); ! // store.loadData(new File("data/wordnet_nouns-20010201.rdf"), "", ! // RDFFormat.RDFXML, false/* verifyData */, false/* commit */); store.fullForwardClosure(); --- NEW FILE: TestRuleRdfs07.java --- /** The Notice below must appear in each file of the Source Code of any copy you distribute of the Licensed Product. Contributors to any Modifications may add their own copyright notices to identify their own contributions. License: The contents of this file are subject to the CognitiveWeb Open Source License Version 1.1 (the License). You may not copy or use this file, in either source code or executable form, except in compliance with the License. You may obtain a copy of the License from http://www.CognitiveWeb.org/legal/license/ Software distributed under the License is distributed on an AS IS basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyrights: Portions created by or assigned to CognitiveWeb are Copyright (c) 2003-2003 CognitiveWeb. All Rights Reserved. Contact information for CognitiveWeb is available at http://www.CognitiveWeb.org Portions Copyright (c) 2002-2003 Bryan Thompson. Acknowledgements: Special thanks to the developers of the Jabber Open Source License 1.0 (JOSL), from which this License was derived. This License contains terms that differ from JOSL. Special thanks to the CognitiveWeb Open Source Contributors for their suggestions and support of the Cognitive Web. Modifications: */ /* * Created on Apr 13, 2007 */ package com.bigdata.rdf.inf; import org.openrdf.model.URI; import org.openrdf.vocabulary.RDFS; import com.bigdata.rdf.model.OptimizedValueFactory._URI; /** * @see RuleRdfs07 * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ public class TestRuleRdfs07 extends AbstractRuleTestCase { /** * */ public TestRuleRdfs07() { } /** * @param name */ public TestRuleRdfs07(String name) { super(name); } /** * Test of {@link RuleRdfs07} where the data satisifies the rule exactly * once. * * <pre> * triple(?u,?b,?y) :- * triple(?a,rdfs:subPropertyOf,?b), * triple(?u,?a,?y). * </pre> */ public void test_rdfs07_01() { URI A = new _URI("http://www.foo.org/A"); URI B = new _URI("http://www.foo.org/B"); URI U = new _URI("http://www.foo.org/U"); URI Y = new _URI("http://www.foo.org/Y"); URI rdfsSubPropertyOf = new _URI(RDFS.SUBPROPERTYOF); store.addStatement(A, rdfsSubPropertyOf, B); store.addStatement(U, A, Y); assertTrue(store.containsStatement(A, rdfsSubPropertyOf, B)); assertTrue(store.containsStatement(U, A, Y)); assertFalse(store.containsStatement(U, B, Y)); // apply the rule. applyRule(store.rdfs7,1,1); assertEquals("#subqueries",1,stats.numSubqueries); /* * validate the state of the primary store. */ assertTrue(store.containsStatement(A, rdfsSubPropertyOf, B)); assertTrue(store.containsStatement(U, A, Y)); assertTrue(store.containsStatement(U, B, Y)); } /** * Test of {@link RuleRdfs07} where the data satisifies the rule twice -- * there are two matches in the subquery for the same binding on "?a". Only * one subquery is made since there is only one match for the first triple * pattern. * * <pre> * triple(?u,?b,?y) :- * triple(?a,rdfs:subPropertyOf,?b), * triple(?u,?a,?y). * </pre> */ public void test_rdfs07_02() { URI A = new _URI("http://www.foo.org/A"); URI B = new _URI("http://www.foo.org/B"); URI U1 = new _URI("http://www.foo.org/U1"); URI Y1 = new _URI("http://www.foo.org/Y1"); URI U2 = new _URI("http://www.foo.org/U2"); URI Y2 = new _URI("http://www.foo.org/Y2"); URI rdfsSubPropertyOf = new _URI(RDFS.SUBPROPERTYOF); store.addStatement(A, rdfsSubPropertyOf, B); store.addStatement(U1, A, Y1); store.addStatement(U2, A, Y2); assertTrue(store.containsStatement(A, rdfsSubPropertyOf, B)); assertTrue(store.containsStatement(U1, A, Y1)); assertTrue(store.containsStatement(U2, A, Y2)); assertFalse(store.containsStatement(U1, B, Y1)); assertFalse(store.containsStatement(U2, B, Y2)); // apply the rule. applyRule(store.rdfs7,2,2); assertEquals("#subqueries",1,stats.numSubqueries); /* * validate the state of the primary store. */ assertTrue(store.containsStatement(A, rdfsSubPropertyOf, B)); assertTrue(store.containsStatement(U1, A, Y1)); assertTrue(store.containsStatement(U2, A, Y2)); assertTrue(store.containsStatement(U1, B, Y1)); assertTrue(store.containsStatement(U2, B, Y2)); } /** * Test of {@link RuleRdfs07} where the data satisifies the rule twice -- * there are two matches on the first triple pattern that have the same * subject. However, only one subquery is made since both matches on the * first triple pattern have the same subject. * <p> * Note: This test is used to verify that the JOIN reorders the results from * the first triple pattern into SPO order so that fewer subqueries need to * be executed (only one subquery in this case). * * <pre> * triple(?u,?b,?y) :- * triple(?a,rdfs:subPropertyOf,?b), * triple(?u,?a,?y). * </pre> */ public void test_rdfs07_03() { URI A = new _URI("http://www.foo.org/A"); URI B1 = new _URI("http://www.foo.org/B1"); URI B2 = new _URI("http://www.foo.org/B2"); URI U = new _URI("http://www.foo.org/U"); URI Y = new _URI("http://www.foo.org/Y"); URI rdfsSubPropertyOf = new _URI(RDFS.SUBPROPERTYOF); store.addStatement(A, rdfsSubPropertyOf, B1); store.addStatement(A, rdfsSubPropertyOf, B2); store.addStatement(U, A, Y); assertTrue(store.containsStatement(A, rdfsSubPropertyOf, B1)); assertTrue(store.containsStatement(A, rdfsSubPropertyOf, B2)); assertTrue(store.containsStatement(U, A, Y)); assertFalse(store.containsStatement(U, B1, Y)); assertFalse(store.containsStatement(U, B2, Y)); // apply the rule. applyRule(store.rdfs7,2,2); // verify that only one subquery is issued. assertEquals("#subqueries",1,stats.numSubqueries); /* * validate the state of the primary store. */ assertTrue(store.containsStatement(A, rdfsSubPropertyOf, B1)); assertTrue(store.containsStatement(A, rdfsSubPropertyOf, B2)); assertTrue(store.containsStatement(U, A, Y)); assertTrue(store.containsStatement(U, B1, Y)); assertTrue(store.containsStatement(U, B2, Y)); } } Index: TestRuleRdfs11.java =================================================================== RCS file: /cvsroot/cweb/bigdata-rdf/src/test/com/bigdata/rdf/inf/TestRuleRdfs11.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestRuleRdfs11.java 14 Apr 2007 13:33:49 -0000 1.1 --- TestRuleRdfs11.java 18 Apr 2007 17:29:06 -0000 1.2 *************** *** 61,65 **** * @version $Id$ */ ! public class TestRuleRdfs11 extends AbstractInferenceEngineTestCase { /** --- 61,65 ---- * @version $Id$ */ ! public class TestRuleRdfs11 extends AbstractRuleTestCase { /** *************** *** 91,124 **** assertFalse(store.containsStatement(A, rdfsSubClassOf, C)); ! // store.fullForwardClosure(); ! ! Stats stats = new Stats(); ! ! TempTripleStore tmpStore = new TempTripleStore(); ! ! final int capacity = 10; ! ! final boolean distinct = false; ! ! SPOBuffer buffer = new SPOBuffer(tmpStore,capacity,distinct); ! ! // apply the rule. ! store.rdfs11.apply(stats, buffer); ! ! // dump entailments on the console. ! buffer.dump(store); ! ! assertEquals("numComputed",stats.numComputed,1); ! ! // flush entailments into the temporary store. ! buffer.flush(); /* - * transfer the entailments from the temporary store to the primary - * store. - */ - assertEquals("#copied",1,store.copyStatements(tmpStore)); - - /* * validate the state of the primary store. */ --- 91,97 ---- assertFalse(store.containsStatement(A, rdfsSubClassOf, C)); ! applyRule(store.rdfs11, 1/* numComputed */, 1/* numCopied */); /* * validate the state of the primary store. */ Index: TestAll.java =================================================================== RCS file: /cvsroot/cweb/bigdata-rdf/src/test/com/bigdata/rdf/inf/TestAll.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestAll.java 26 Jan 2007 18:22:15 -0000 1.1 --- TestAll.java 18 Apr 2007 17:29:06 -0000 1.2 *************** *** 78,81 **** --- 78,85 ---- TestSuite suite = new TestSuite("RDFS inference"); + suite.addTestSuite( TestRuleRdfs07.class ); + + suite.addTestSuite( TestRuleRdfs11.class ); + suite.addTestSuite( TestFullForwardClosure.class ); --- NEW FILE: AbstractRuleTestCase.java --- /** The Notice below must appear in each file of the Source Code of any copy you distribute of the Licensed Product. Contributors to any Modifications may add their own copyright notices to identify their own contributions. License: The contents of this file are subject to the CognitiveWeb Open Source License Version 1.1 (the License). You may not copy or use this file, in either source code or executable form, except in compliance with the License. You may obtain a copy of the License from http://www.CognitiveWeb.org/legal/license/ Software distributed under the License is distributed on an AS IS basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyrights: Portions created by or assigned to CognitiveWeb are Copyright (c) 2003-2003 CognitiveWeb. All Rights Reserved. Contact information for CognitiveWeb is available at http://www.CognitiveWeb.org Portions Copyright (c) 2002-2003 Bryan Thompson. Acknowledgements: Special thanks to the developers of the Jabber Open Source License 1.0 (JOSL), from which this License was derived. This License contains terms that differ from JOSL. Special thanks to the CognitiveWeb Open Source Contributors for their suggestions and support of the Cognitive Web. Modifications: */ /* * Created on Apr 18, 2007 */ package com.bigdata.rdf.inf; import com.bigdata.rdf.TempTripleStore; import com.bigdata.rdf.inf.Rule.Stats; /** * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ abstract public class AbstractRuleTestCase extends AbstractInferenceEngineTestCase { final protected TempTripleStore tmpStore = new TempTripleStore(); final protected Stats stats = new Stats(); final protected int capacity = 10; final protected boolean distinct = false; final protected SPOBuffer buffer = new SPOBuffer(tmpStore,capacity,distinct); /** * */ public AbstractRuleTestCase() { } /** * @param name */ public AbstractRuleTestCase(String name) { super(name); } /** * Applies the rule, copies the new entailments into the store and checks * the expected #of inferences computed and new statements copied into the * store. * <p> * Invoke as <code>applyRule( store.{rule}, ..., ... )</code> * * @param rule * The rule, which must be one of those found on {@link #store} * or otherwise configured so as to run with the {@link #store} * instance. * * @param expectedComputed * The #of entailments that should be computed by the rule. * * @param expectedCopied * The #of entailments that should be distinct from the * statements already in the store (the new inferences). */ protected void applyRule(Rule rule, int expectedComputed, int expectedCopied) { // apply the rule. rule.apply(stats, buffer); // dump entailments on the console. buffer.dump(store); // flush entailments into the temporary store. buffer.flush(); /* * Verify the #of entailments computed. */ assertEquals("numComputed",expectedComputed,stats.numComputed); /* * transfer the entailments from the temporary store to the primary * store. */ final int actualCopied = store.copyStatements(tmpStore); assertEquals("#copied",expectedCopied,actualCopied); } } |