📄 inferencingtest.java
字号:
/* Sesame - Storage and Querying architecture for RDF and RDF Schema * Copyright (C) 2001-2005 Aduna * * Contact: * Aduna * Prinses Julianaplein 14 b * 3817 CS Amersfoort * The Netherlands * tel. +33 (0)33 465 99 87 * fax. +33 (0)33 465 99 87 * * http://aduna.biz/ * http://www.openrdf.org/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package org.openrdf.sesame.sail;import java.io.IOException;import java.io.InputStream;import java.util.HashMap;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import org.openrdf.model.Statement;import org.openrdf.sesame.admin.AdminListener;import org.openrdf.sesame.admin.RdfAdmin;import org.openrdf.sesame.admin.UpdateException;import org.openrdf.sesame.constants.RDFFormat;public class InferencingTest extends TestCase {/*--------------------------------------+| Constants |+--------------------------------------*/ public static final String TEST_DIR_PREFIX = "/files/testcases/rdf-mt-inferencing";/*--------------------------------------+| Variables |+--------------------------------------*/ protected RdfSchemaRepository _rss; protected String _inputData; protected String _outputData; protected boolean _isPositiveTest;/*--------------------------------------+| Constructors |+--------------------------------------*/ /** * Creates a new inferencing test. This test can either be positive or * negative. For positive tests, all triples from <tt>outputData</tt> * should be present in the triples returned by the supplied * RdfSchemaRepository after the triples from <tt>intputData</tt> have been * added to it. For negative tests, none of the triples from * <tt>outputData</tt> should be present in the returned triples. * * @param name The name of the test. * @param rss The RdfSchemaRepository to test. * @param inputData The URL of the (N-Triples) data containing the triples * that should be added to the RdfSchemaRepository. * @param outputData The URL of the (N-Triples) data containing the triples * that should or should not (depending on the value of * <tt>isPositiveTest</tt> be present in the statements returned by the * RdfSchemaRepository. * @param isPositiveTest Flag indicating whether this is a positive or a * negative inferencing test; <tt>true</tt> for a positive test, * <tt>false</tt> for a negative test. **/ public InferencingTest( String name, RdfSchemaRepository rss, String inputData, String outputData, boolean isPositiveTest) { super(name); _rss = rss; _inputData = inputData; _outputData = outputData; _isPositiveTest = isPositiveTest; }/*--------------------------------------+| Methods |+--------------------------------------*/ protected void runTest() { try { // Clear the repository try { _rss.startTransaction(); _rss.clearRepository(); _rss.commitTransaction(); } catch (SailUpdateException e) { fail("SailUpdateException: " + e.getMessage()); } // Upload input data InputStream stream = getClass().getResourceAsStream(_inputData); RdfAdmin rdfAdmin = new RdfAdmin(_rss); rdfAdmin.addRdfModel( stream, _inputData, new DummyAdminListener(), RDFFormat.NTRIPLES, true); // Upload output data RdfRepository outputRepository = new org.openrdf.sesame.sailimpl.memory.RdfRepository(); outputRepository.initialize(new HashMap()); stream = getClass().getResourceAsStream(_outputData); rdfAdmin = new RdfAdmin(outputRepository); rdfAdmin.addRdfModel( stream, _inputData, // use _inputData for base URL new DummyAdminListener(), RDFFormat.NTRIPLES, true); // Check whether all statement from outputRepository are present // in _rss boolean outputEntailed = SailUtil.isSubset(outputRepository, _rss); if (_isPositiveTest) { assertTrue("Incomplete entailment ", outputEntailed); } else { assertFalse("Erroneous entailment ", outputEntailed); } } catch (IOException e) { fail("Unable to run test due to I/O error: " + e.getMessage()); } catch (UpdateException e) { fail("Unable to add data to repository: " + e.getMessage()); } catch (SailInitializationException e) { fail("Unable to initialize repository: " + e.getMessage()); } } class DummyAdminListener implements AdminListener { // Start/end transaction public void transactionStart() { } public void transactionEnd() { } public void status(String msg, int lineNo, int colNo) { } public void notification( String msg, int lineNo, int colNo, Statement statement) { } public void warning( String msg, int lineNo, int colNo, Statement statement) { } public void error( String msg, int lineNo, int colNo, Statement statement) { } }/*--------------------------------------+| Test methods |+--------------------------------------*/ public static Test suite(RdfSchemaRepository rss) { TestSuite suite = new TestSuite(); suite.addTest(_createTestCase(rss, "subclassof", "test001", true)); suite.addTest(_createTestCase(rss, "subclassof", "test002", true)); suite.addTest(_createTestCase(rss, "subclassof", "test003", true)); suite.addTest(_createTestCase(rss, "subclassof", "error001", false)); suite.addTest(_createTestCase(rss, "subpropertyof", "test001", true)); suite.addTest(_createTestCase(rss, "subpropertyof", "test002", true)); suite.addTest(_createTestCase(rss, "subpropertyof", "test003", true)); suite.addTest(_createTestCase(rss, "subpropertyof", "error001", false)); suite.addTest(_createTestCase(rss, "subpropertyof", "error002", false)); suite.addTest(_createTestCase(rss, "subpropertyof", "error003", false)); suite.addTest(_createTestCase(rss, "domain", "test001", true)); suite.addTest(_createTestCase(rss, "domain", "error001", false)); suite.addTest(_createTestCase(rss, "range", "test001", true)); suite.addTest(_createTestCase(rss, "range", "error001", false)); suite.addTest(_createTestCase(rss, "type", "test001", true)); suite.addTest(_createTestCase(rss, "type", "test002", true)); suite.addTest(_createTestCase(rss, "type", "test003", true)); suite.addTest(_createTestCase(rss, "type", "test004", true)); suite.addTest(_createTestCase(rss, "type", "test005", true)); suite.addTest(_createTestCase(rss, "type", "error001", false)); suite.addTest(_createTestCase(rss, "type", "error002", false)); return suite; } private static TestCase _createTestCase( RdfSchemaRepository rss, String subdir, String testName, boolean isPositiveTest) { return new InferencingTest( subdir + "/" + testName, rss, TEST_DIR_PREFIX + "/" + subdir + "/" + testName + "-in.nt", TEST_DIR_PREFIX + "/" + subdir + "/" + testName + "-out.nt", isPositiveTest); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -