當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。