当前位置: 首页>>代码示例>>Java>>正文


Java RDFFormat类代码示例

本文整理汇总了Java中org.openrdf.rio.RDFFormat的典型用法代码示例。如果您正苦于以下问题:Java RDFFormat类的具体用法?Java RDFFormat怎么用?Java RDFFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RDFFormat类属于org.openrdf.rio包,在下文中一共展示了RDFFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRDFFormat

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
/**
 * Returns an instance of {@link org.openrdf.rio.RDFFormat} for a
 * given MIME-Type string.
 *
 * @param mimetype the MIME-Type as string
 * @return the corresponding RDF-Format
 */
protected RDFFormat getRDFFormat(String mimetype) {
	switch (mimetype) {
		default:
		case RDFMediaType.RDF_TURTLE:
			return RDFFormat.TURTLE;
		case RDFMediaType.RDF_YARS:
			return RDFFormat.YARS;
		case RDFMediaType.RDF_XML:
			return RDFFormat.RDFXML;
		case RDFMediaType.RDF_NTRIPLES:
			return RDFFormat.NTRIPLES;
		case RDFMediaType.RDF_JSON:
			return RDFFormat.RDFJSON;
	}
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:23,代码来源:AbstractSailResource.java

示例2: addToGraphstore

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
/**
 * Helper method for handleAdd.
 */
private void addToGraphstore(
		RepositoryConnection conn,
		InputStream in,
		String base,
		RDFFormat format,
		Resource dctx,
		boolean chunked) throws IOException, RDFParseException,
		RDFHandlerException, RepositoryException {
	if (chunked) {
		RDFParser parser = getRDFParser(format);
		parser.setRDFHandler(
				new ChunkedCommitHandler(conn, chunksize, dctx));
		parser.parse(in, base);
	} else {
		if (dctx != null) {
			conn.add(in, base, format, dctx);
		} else {
			conn.add(in, base, format);
		}
	}
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:25,代码来源:GraphStore.java

示例3: before

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Before
public void before()
		throws RepositoryException, IOException, RDFParseException,
		       MalformedQueryException, QueryResultParseException,
			   QueryResultHandlerException {
	repo = new SailRepository(new MemoryStore());
	repo.initialize();
	conn = repo.getConnection();
	vf = conn.getValueFactory();
	conn.add(getResource(data), "file://", RDFFormat.TURTLE);
	SPARQLResultsXMLParserFactory factory =
			new SPARQLResultsXMLParserFactory();
	parser = factory.getParser();
	parser.setValueFactory(vf);
	List<Rule> rules;
	rules = Rules.fromOntology(getResource(data));
	QueryRewriter rewriter = new QueryRewriter(conn, rules);
	query = (TupleQuery) rewriter.rewrite(QueryLanguage.SPARQL, queryString);
	nonInfQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	System.out.println("== QUERY (" + this.name + ") ==");
	System.out.println(nonInfQuery);
	System.out.println("== REWRITTEN QUERY (" + this.name + ") ==");
	System.out.println(query);
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:25,代码来源:SPARQLInferenceTest.java

示例4: setUp

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws IOException, RepositoryException, RDFParseException {
	int port;
	try (final ServerSocket serverSocket = new ServerSocket(0)) {
		port = serverSocket.getLocalPort();
	}
	server = CommunityServerBuilder.server()
		.onPort(port)
		.withThirdPartyJaxRsPackage("de.unikiel.inf.comsys.neo4j", "/rdf")
		.build();
	server.start();
	GraphDatabaseService db = server.getDatabase().getGraph();
	Repository rep = RepositoryRegistry.getInstance(db).getRepository();
	conn = rep.getConnection();
	InputStream testdata = RDFServerExtensionTest.class.getResourceAsStream("/sp2b.n3");
	conn.add(testdata, "http://example.com/", RDFFormat.N3);
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:18,代码来源:RDFServerExtensionTest.java

示例5: parseConfig

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
protected Graph parseConfig(File file) throws SailConfigException, IOException {

        RDFFormat format = Rio.getParserFormatForFileName(file.getAbsolutePath());
        if (format==null)
            throw new SailConfigException("Unsupported file format: " + file.getAbsolutePath());
        RDFParser parser = Rio.createParser(format);
        Graph model = new GraphImpl();
        parser.setRDFHandler(new StatementCollector(model));
        InputStream stream = new FileInputStream(file);

        try {
            parser.parse(stream, file.getAbsolutePath());
        } catch (Exception e) {
            throw new SailConfigException("Error parsing file!");
        }

        stream.close();
        return model;
    }
 
开发者ID:dice-group,项目名称:CostFed,代码行数:20,代码来源:QueryEvaluation.java

示例6: runSPARQL

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
/**
 * Execute a CONSTRUCT/DESCRIBE SPARQL query against the graph
 * 
 * @param qs
 *            CONSTRUCT or DESCRIBE SPARQL query
 * @param format
 *            the serialization format for the returned graph
 * @return serialized graph of results
 */
public String runSPARQL(String qs, RDFFormat format) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			GraphQuery query = con.prepareGraphQuery(org.openrdf.query.QueryLanguage.SPARQL, qs);
			StringWriter stringout = new StringWriter();
			RDFWriter w = Rio.createWriter(format, stringout);
			query.evaluate(w);
			return stringout.toString();
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dvcama,项目名称:resource-to-sparqlresult,代码行数:27,代码来源:SimpleGraph.java

示例7: testTicket583

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Test
public void testTicket583() throws Exception {
	RepositoryConnection rc = engine.getRawConnection();
	rc.add( TICKETBASE, null, RDFFormat.TURTLE );
	engine.setBuilders( UriBuilder.getBuilder( "http://example.org/ex1" ),
			UriBuilder.getBuilder( "http://foo.bar/model#" ) );

	EngineLoader el = new EngineLoader();
	el.loadToEngine( Arrays.asList( TICKET583 ), engine, false, null );
	el.release();

	if ( log.isTraceEnabled() ) {
		File tmpdir = FileUtils.getTempDirectory();
		try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
				"ticket583.nt" ) ) ) ) {
			rc.export( new NTriplesWriter( w ) );
		}
	}

	compareData( rc, getExpectedGraph( TICKET583_EXP ),
			UriBuilder.getBuilder( "http://example.org/ex1" ),
			UriBuilder.getBuilder( "http://foo.bar/model#" ) );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:24,代码来源:EngineLoaderTest.java

示例8: testTicket584

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
public void testTicket584() throws Exception {
		RepositoryConnection rc = engine.getRawConnection();

		rc.add( TICKETBASE, null, RDFFormat.TURTLE );
		engine.setBuilders( UriBuilder.getBuilder( "http://example.org/ex1" ),
				UriBuilder.getBuilder( "http://foo.bar/model#" ) );

		EngineLoader el = new EngineLoader();
		el.loadToEngine( Arrays.asList( TICKET584 ), engine, false, null );
		el.release();

		if ( log.isTraceEnabled() ) {
			File tmpdir = FileUtils.getTempDirectory();
			try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
					"ticket584.nt" ) ) ) ) {
				engine.getRawConnection().export( new NTriplesWriter( w ) );
			}
		}

//		compareData( rc, getExpectedGraph( TICKET584_EXP ),
//				UriBuilder.getBuilder( "http://example.org/ex1" ),
//				UriBuilder.getBuilder( "http://foo.bar/model#" ) );
	}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:24,代码来源:EngineLoaderTest.java

示例9: testCheckModelConformanceLegacy

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Test
public void testCheckModelConformanceLegacy() throws Exception {
	engine.setBuilders( UriBuilder.getBuilder( DATAURI ),
			UriBuilder.getBuilder( OWLSTART ) );

	engine.getRawConnection().add( LEGACY_EXP, "", RDFFormat.NTRIPLES );

	el.release(); // release the checker from setup
	el = new QaChecker( engine );
	ImportData test = new ImportData();
	test.getMetadata().setDataBuilder( engine.getDataBuilder().toString() );
	test.getMetadata().setSchemaBuilder( engine.getSchemaBuilder().toString() );

	LoadingSheetData lsd
			= LoadingSheetData.relsheet( "Product-x", "Category-x", "Category-y" );
	lsd.addProperty( "extraprop-x" );
	test.add( lsd );

	LoadingSheetData errs = el.checkModelConformance( lsd );

	assertTrue( errs.hasModelErrors() );
	assertTrue( errs.hasSubjectTypeError() );
	assertTrue( errs.hasObjectTypeError() );
	assertTrue( errs.propertyIsError( "extraprop-x" ) );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:26,代码来源:QaCheckerTest.java

示例10: setUp

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	eng = InMemorySesameEngine.open();

	RepositoryConnection rc = eng.getRawConnection();
	rc.begin();
	rc.add( DATA, null, RDFFormat.NTRIPLES );
	rc.add( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
			new LiteralImpl( "label" ) ) );

	rc.remove( eng.getBaseUri(), MetadataConstants.DCT_MODIFIED, null );
	rc.add( eng.getBaseUri(), MetadataConstants.DCT_MODIFIED,
			rc.getValueFactory().createLiteral( new Date() ) );

	rc.commit();
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:17,代码来源:InMemorySesameEngineTest.java

示例11: testNTriplesInput

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Test
public void testNTriplesInput() throws Exception {
    RdfFileInputTool.main(new String[]{
            "-Dac.mock=true",
            "-Dac.instance=" + instance,
            "-Dac.username=" + user,
            "-Dac.pwd=" + pwd,
            "-Dac.auth=" + auths.toString(),
            "-Dac.cv=" + auths.toString(),
            "-Drdf.tablePrefix=" + tablePrefix,
            "-Drdf.format=" + RDFFormat.NTRIPLES.getName(),
            "src/test/resources/test.ntriples",
    });
    RyaStatement rs = new RyaStatement(new RyaURI("urn:lubm:rdfts#GraduateStudent01"),
            new RyaURI("urn:lubm:rdfts#hasFriend"),
            new RyaURI("urn:lubm:rdfts#GraduateStudent02"));
    rs.setColumnVisibility(auths.toString().getBytes());
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(tablePrefix);
    conf.setAuths(auths.toString());
    TestUtils.verify(connector, conf, rs);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:23,代码来源:RdfFileInputToolTest.java

示例12: testInputContext

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Test
public void testInputContext() throws Exception {
    RdfFileInputTool.main(new String[]{
            "-Dac.mock=true",
            "-Dac.instance=" + instance,
            "-Dac.username=" + user,
            "-Dac.pwd=" + pwd,
            "-Dac.auth=" + auths.toString(),
            "-Dac.cv=" + auths.toString(),
            "-Drdf.tablePrefix=" + tablePrefix,
            "-Drdf.format=" + RDFFormat.TRIG.getName(),
            "src/test/resources/namedgraphs.trig",
    });
    RyaStatement rs = new RyaStatement(new RyaURI("http://www.example.org/exampleDocument#Monica"),
            new RyaURI("http://www.example.org/vocabulary#name"),
            new RyaType("Monica Murphy"),
            new RyaURI("http://www.example.org/exampleDocument#G1"));
    rs.setColumnVisibility(auths.toString().getBytes());
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(tablePrefix);
    conf.setAuths(auths.toString());
    TestUtils.verify(connector, conf, rs);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:RdfFileInputToolTest.java

示例13: getSail

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Override
public synchronized Sail getSail() throws SailException {
	if (repository == null) {
		try {
			virtuoso = new VirtuosoRepository("jdbc:virtuoso://localhost:1111", "dba", "dba", true);
			repository = new RepositorySail(virtuoso);
			
			// Needed for inferencing...
			URL schema = Thread.currentThread().getContextClassLoader().getResource("/org/waag/ah/rdf/schema/artsholland.rdf");
			RepositoryConnection connection = virtuoso.getConnection();
			connection.add(schema, null, RDFFormat.RDFXML);
			virtuoso.createRuleSet("artsholland", "http://purl.org/artsholland/1.0/");
			connection.close();
			
		} catch (Exception e) {
			throw new SailException(e);
		}
	}
	return repository;
}
 
开发者ID:erfgoed-en-locatie,项目名称:artsholland-platform,代码行数:21,代码来源:Virtuoso.java

示例14: loadHistory

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Override
	public JSONArray loadHistory(String filename) throws Exception {
		File file = new File(filename);
//		String encoding = EncodingDetector.detect(file);
//		String contents = EncodingDetector.getString(file, encoding);
		
		SailRepository myRepository = new SailRepository(new MemoryStore());
		myRepository.initialize();
		SailRepositoryConnection con = myRepository.getConnection();
		con.add(file, "", RDFFormat.TURTLE);
		
		RepositoryResult<Statement> result = con.getStatements(null, new URIImpl("http://isi.edu/integration/karma/dev#hasWorksheetHistory"), null, false);
		if(result.hasNext()) {
			Statement stmt = result.next();
			String history = stmt.getObject().stringValue();
			return new JSONArray(history);
		}
		return new JSONArray();
	}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:20,代码来源:R2RMLAlignmentFileSaver.java

示例15: getTriples

import org.openrdf.rio.RDFFormat; //导入依赖的package包/类
@Override
public String getTriples(RDFFormat format) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    RDFParser parser = Rio.createParser(RDFFormat.NTRIPLES);
    RDFWriter writer = Rio.createWriter(format, out);
    parser.setRDFHandler(writer);

    try {
        this.getObjectConnection().exportStatements(this.getResource(), null, null, true, writer);

        if (getSelector() != null) {
            parser.parse(IOUtils.toInputStream(getSelector().getTriples(RDFFormat.NTRIPLES), "UTF-8"), "");
        }
    } catch (IOException | RDFHandlerException | RDFParseException | RepositoryException e) {
        e.printStackTrace();
    }

    return out.toString();
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:20,代码来源:SpecificResourceSupport.java


注:本文中的org.openrdf.rio.RDFFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。