本文整理汇总了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();
}