⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rdfcoretests.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  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.rio.rdfxml;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.MalformedURLException;import java.net.URL;import java.util.Date;import java.util.HashMap;import java.util.Map;import junit.framework.TestCase;import org.openrdf.vocabulary.RDF;import org.openrdf.vocabulary.RDFS;import org.openrdf.model.Resource;import org.openrdf.model.URI;import org.openrdf.model.Value;import org.openrdf.model.impl.BNodeImpl;import org.openrdf.model.impl.LiteralImpl;import org.openrdf.model.impl.URIImpl;import org.openrdf.rio.ParseException;import org.openrdf.rio.Parser;import org.openrdf.rio.RdfDocumentWriter;import org.openrdf.rio.StatementHandler;import org.openrdf.rio.StatementHandlerException;import org.openrdf.rio.ntriples.NTriplesParser;import org.openrdf.sesame.admin.AdminMsgCollector;import org.openrdf.sesame.config.AccessDeniedException;import org.openrdf.sesame.config.UnknownRepositoryException;import org.openrdf.sesame.constants.QueryLanguage;import org.openrdf.sesame.constants.RDFFormat;import org.openrdf.sesame.export.RdfExport;import org.openrdf.sesame.query.MalformedQueryException;import org.openrdf.sesame.query.QueryEvaluationException;import org.openrdf.sesame.query.QueryResultsTable;import org.openrdf.sesame.repository.remote.HTTPRepository;import org.openrdf.sesame.repository.remote.HTTPService;import org.openrdf.sesame.sail.RdfRepository;import org.openrdf.sesame.sail.SailInitializationException;import org.openrdf.sesame.sail.SailUpdateException;import org.openrdf.sesame.sail.SailUtil;public class RdfCoreTests extends TestCase {/*--------------------------------------+| Variables                             |+--------------------------------------*/	protected RdfXmlParser _rdfXmlParser;	protected NTriplesParser _nTriplesParser;	protected HTTPService _demoServer;	protected URL _demoServerURL; 	protected HTTPRepository _manifestRep;	protected HTTPRepository _logRep;	protected String _manifestId = "rdfcore";	protected String _logId = "rdfcore-results";	protected RdfRepository _parsedModel;	protected RdfRepository _expectedModel;	protected RdfRepository _logModel;	protected String _rdfCoreURL = "http://www.w3.org/2000/10/rdf-tests/rdfcore/";	protected String _testSchemaURL = _rdfCoreURL + "testSchema#";	protected String _resOntURL = "http://www.w3.org/2002/03owlt/resultsOntology#";	protected String _sesameURL = "http://sesame.aidministrator.nl/";/*--------------------------------------+| Constructors                          |+--------------------------------------*/	public RdfCoreTests() {		super();	}	public RdfCoreTests(String name) {		super(name);	}/*--------------------------------------+| Methods                               |+--------------------------------------*/	protected void setUp() {		_logModel = new org.openrdf.sesame.sailimpl.memory.RdfRepository();		try {			_demoServerURL = new URL("http://sesame.aidministrator.nl/sesame/");		}		catch (MalformedURLException e) {			fail("malformed url: " + e.getMessage());		}		try {			Map noParams = new HashMap();			_logModel.initialize(noParams);		}		catch (SailInitializationException e) {			fail("Unable to initialize models: " + e.getMessage());		}		_rdfXmlParser = new RdfXmlParser();		_rdfXmlParser.setDatatypeHandling(Parser.DT_IGNORE);		_rdfXmlParser.setParseStandAloneDocuments(true);		_nTriplesParser = new NTriplesParser();		_nTriplesParser.setDatatypeHandling(Parser.DT_IGNORE);				// read the manifest		try {			_demoServer = new HTTPService(_demoServerURL);			// FIXME fill in appropriate username and password			_demoServer.login("username", "password");						_manifestRep = (HTTPRepository)_demoServer.getRepository(_manifestId);			_logRep = (HTTPRepository)_demoServer.getRepository(_logId);						_manifestRep.clear(new AdminMsgCollector());			_manifestRep.addData(new URL(_rdfCoreURL + "Manifest.rdf"), _rdfCoreURL, RDFFormat.RDFXML, true,  new AdminMsgCollector());		}		catch (UnknownRepositoryException e) {			fail("unknown repository " + e.getMessage());		}		catch (MalformedURLException e) {			fail("malformed url: " + e.getMessage());		}		catch (AccessDeniedException e) {			fail("access denied: " + e.getMessage());		}		catch (IOException e) {			fail("unable to upload manifest: " + e.getMessage());		}		_addLogStatement("system", RDFS.LABEL, "Sesame", 2, 3);		_addLogStatement("system", RDFS.COMMENT, "These tests were run on the current CVS version of Sesame and the Rio RDF parser", 2, 3);		_addLogStatement("system", "http://xmlns.com/foaf/0.1/homepage", "http://sourceforge.net/projects/sesame", 2, 1); 	}	protected void tearDown() {		_rdfXmlParser = null;		_nTriplesParser = null;		_parsedModel.shutDown();		_expectedModel.shutDown();		RdfExport exporter = new RdfExport();		try {			_logModel.changeNamespacePrefix(_resOntURL, "r");			_logModel.changeNamespacePrefix(_testSchemaURL, "test");			_logModel.changeNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");			OutputStream out = new FileOutputStream("/tmp/results.rdf");			RdfDocumentWriter xmlWriter = new RdfXmlWriter(out);			exporter.exportRdf(_logModel, xmlWriter, true);			out.close();			_logRep.clear(new AdminMsgCollector());			InputStream in = new FileInputStream("/tmp/results.rdf");			_logRep.addData(in, _sesameURL + "parserTest", RDFFormat.RDFXML, true, new AdminMsgCollector());			in.close();		}		catch (SailUpdateException e) {			// nothing		}		catch (AccessDeniedException e) {			fail("access denied on writing to result repository: " + e.getMessage());		}		catch (FileNotFoundException e) {			//nothing		}		catch (IOException e) {			//nothing		}		finally {			_logModel.shutDown();			_logModel = _parsedModel = _expectedModel = null;		}	}/*--------------------------------------+| Test methods                          |+--------------------------------------*/	public void testRdfCoreCases() {		// positive tests		try {			QueryResultsTable positiveCases = 			_manifestRep.performTableQuery(QueryLanguage.SERQL,					" select CASE, INPUT, OUTPUT" +					" from  {CASE} <rdf:type> {<test:PositiveParserTest>};" +					"              <test:inputDocument> {INPUT}; " +					"			   <test:outputDocument> {OUTPUT};" +					"              <test:status> {STATUS}" +					" where label(STATUS) = \"APPROVED\"" +					" using namespace " +					"        test = <!" + _testSchemaURL + ">");			int noPosCases = positiveCases.getRowCount();			for (int row = 0; row < noPosCases; row++) {				String testName = positiveCases.getValue(row, 0).toString();				String inputFile = positiveCases.getValue(row, 1).toString();				String outputFile = positiveCases.getValue(row, 2).toString();				_positiveParserTest(row, testName, inputFile, outputFile);			}			// negative tests			QueryResultsTable negativeCases = 			_manifestRep.performTableQuery(QueryLanguage.SERQL,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -