本文整理匯總了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;
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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#" ) );
}
示例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#" ) );
}
示例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" ) );
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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();
}