本文整理汇总了Java中org.eclipse.rdf4j.rio.RDFWriter类的典型用法代码示例。如果您正苦于以下问题:Java RDFWriter类的具体用法?Java RDFWriter怎么用?Java RDFWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RDFWriter类属于org.eclipse.rdf4j.rio包,在下文中一共展示了RDFWriter类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mergeResourceWithPrefixes
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
public static Model mergeResourceWithPrefixes(InputStream inputStreamPrefixes,
InputStream inputStreamData) throws IOException {
final Resource mergedDataResource =
new InputStreamResource(new SequenceInputStream(inputStreamPrefixes, inputStreamData));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, byteArrayOutputStream);
RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);
trigParser.setRDFHandler(turtleWriter);
trigParser.parse(mergedDataResource.getInputStream(), "");
Model result = Rio.parse(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), "",
RDFFormat.TURTLE);
byteArrayOutputStream.close();
inputStreamData.close();
return result;
}
示例2: getString
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
/**
* Convert Metadata object to RDF string
*
* @param <T>
* @param metadata Subclass of metadata object
* @param format RDF format
* @return RDF string
* @throws MetadataException
*/
public static <T extends Metadata> String getString(@Nonnull T metadata,
@Nonnull RDFFormat format)
throws MetadataException {
Preconditions.checkNotNull(metadata,
"Metadata object must not be null.");
Preconditions.checkNotNull(format, "RDF format must not be null.");
StringWriter sw = new StringWriter();
RDFWriter writer = Rio.createWriter(format, sw);
List<Statement> statement = getStatements(metadata);
try {
propagateToHandler(statement, writer);
} catch (RepositoryException | RDFHandlerException ex) {
LOGGER.error("Error reading RDF statements");
throw (new MetadataException(ex.getMessage()));
}
return sw.toString();
}
示例3: getModel
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
public static Model getModel(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, byteArrayOutputStream);
RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);
trigParser.setRDFHandler(turtleWriter);
trigParser.parse(inputStream, "");
org.eclipse.rdf4j.model.Model result = Rio.parse(
new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), "", RDFFormat.TURTLE);
byteArrayOutputStream.close();
return result;
}
示例4: testConstructQueryWithWriter
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
@Ignore
public void testConstructQueryWithWriter()
throws Exception {
RDFWriter writer = Rio.createWriter(RDFFormat.TURTLE, System.out);
@SuppressWarnings("unused")
String queryString = "PREFIX nn: <http://semanticbible.org/ns/2006/NTNames#>\n" +
"PREFIX test: <http://marklogic.com#test>\n" +
"\n" +
"construct { ?s test:test \"0\"} WHERE {?s nn:childOf nn:Eve . }";
conn.prepareGraphQuery(QueryLanguage.SPARQL,
"CONSTRUCT {?s ?p ?o } WHERE {?s ?p ?o } ").evaluate(writer);
}
示例5: write
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
/**
* Write contents of RDF repository to N-Triples output
*
* @param out
* @param format RDF output format
* @throws RepositoryException
*/
public void write(Writer out, RDFFormat format) throws RepositoryException {
RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, out);
try {
conn.export(writer);
} catch (RDFHandlerException ex) {
logger.warn("Error writing RDF");
}
}
示例6: renderInternal
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
protected void renderInternal(Map model, HttpServletRequest request, HttpServletResponse response) throws IOException {
RDFWriterFactory rdfWriterFactory = (RDFWriterFactory)model.get("factory");
RDFFormat rdfFormat = rdfWriterFactory.getRDFFormat();
response.setStatus(200);
this.setContentType(response, rdfFormat);
this.setContentDisposition(model, response, rdfFormat);
boolean headersOnly = ((Boolean)model.get("headersOnly")).booleanValue();
if(!headersOnly) {
ServletOutputStream out = response.getOutputStream();
try {
RDFWriter e = rdfWriterFactory.getWriter(out);
GraphQuery graphQuery = (GraphQuery)model.get("queryResult");
graphQuery.evaluate(e);
} catch (QueryInterruptedException var15) {
this.logger.error("Query interrupted", var15);
response.sendError(503, "Query evaluation took too long");
} catch (QueryEvaluationException var16) {
this.logger.error("Query evaluation error", var16);
response.sendError(500, "Query evaluation error: " + var16.getMessage());
} catch (RDFHandlerException var17) {
this.logger.error("Serialization error", var17);
response.sendError(500, "Serialization error: " + var17.getMessage());
} finally {
out.close();
}
}
this.logEndOfRequest(request);
}
示例7: getQueryRecordLogger
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
private QueryLogWriter getQueryRecordLogger(RDFWriterFactory writerFactory, OutputStream out) {
RDFWriter writer = writerFactory.getWriter(out);
QueryLogWriter handler = new RDFQueryLogWriter(writer);
try {
handler.startQueryLog();
} catch (QueryLogException e) {
e.printStackTrace();
}
return handler;
}
示例8: writeTo
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
@Override
public void writeTo(OutputStream stream, Syntax syntax) throws
// interface allows it
IOException, ModelRuntimeException {
RDFWriter rdfWriter = Rio.createWriter(getRDFFormat(syntax), stream);
writeTo(rdfWriter);
}
示例9: writeTo
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
private void writeTo(RDFWriter writer) throws ModelRuntimeException {
this.assertModel();
try {
this.connection.export(writer);
} catch(RDF4JException e) {
throw new ModelRuntimeException(e);
}
}
示例10: export
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
public static void export(final Connection connection, final Path path)
throws SQLException, IOException, RDFHandlerException {
final Map<Long, String> screenNames = loadScreenNames(connection, path);
connection.setAutoCommit(false);
final ValueFactory vf = SimpleValueFactory.getInstance();
try (Writer writer = new OutputStreamWriter(
new GZIPOutputStream(new FileOutputStream(path.toFile())), Charsets.UTF_8)) {
final RDFWriter out = Rio.createWriter(RDFFormat.NTRIPLES, writer);
out.startRDF();
int counter = 0;
try (PreparedStatement stmt = connection.prepareStatement("" //
+ "SELECT resource_id, uid, score, is_alignment\n" //
+ "FROM alignments\n" //
+ "WHERE version=2\n" //
+ "ORDER BY resource_id ASC, score DESC")) {
stmt.setFetchSize(1000);
try (ResultSet rs = stmt.executeQuery()) {
IRI lastEntity = null;
int rank = 1;
while (rs.next()) {
final long uid = rs.getLong("uid");
final String screenName = screenNames.get(uid);
Preconditions.checkState(screenName != null);
final IRI entity = vf.createIRI(rs.getString("resource_id"));
final IRI account = vf.createIRI(
"http://twitter.com/" + screenName.replaceAll("\\s", "+"));
final BNode candidate = vf.createBNode();
final float score = rs.getFloat("score");
final boolean align = rs.getBoolean("is_alignment");
rank = entity.equals(lastEntity) ? rank + 1 : 1;
lastEntity = entity;
LOGGER.debug("Processing candidate {} {} {} {}", entity, candidate, score,
align);
if (align) {
emit(out, entity, FOAF.ACCOUNT, account);
}
emit(out, entity, OWL.SAMEAS, entity);
emit(out, entity, SL.CANDIDATE_PROPERTY, candidate);
emit(out, candidate, SL.RANK, vf.createLiteral(rank));
emit(out, candidate, SL.CONFIDENCE, vf.createLiteral(score));
emit(out, candidate, SL.ACCOUNT, account);
emit(out, account, DCTERMS.IDENTIFIER, vf.createLiteral(uid));
emit(out, account, FOAF.ACCOUNT_NAME, vf.createLiteral(screenName));
if (++counter % 10000 == 0) {
LOGGER.info("{} candidates processed", counter);
}
}
}
}
out.endRDF();
}
}
示例11: main
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
/**
* Main program
*
* @param args
*/
public static void main(String[] args) {
logger.info("-- START --");
if (args.length < 2) {
logger.error("No input or output file");
System.exit(-1);
}
Optional<RDFFormat> fmtin = Rio.getParserFormatForFileName(args[0]);
if(!fmtin.isPresent()) {
logger.error("No parser for input {}", args[0]);
System.exit(-2);
}
Optional<RDFFormat> fmtout = Rio.getWriterFormatForFileName(args[1]);
if(!fmtout.isPresent()) {
logger.error("No parser for output {}", args[1]);
System.exit(-3);
}
int code = 0;
Repository repo = new SailRepository(new MemoryStore());
repo.initialize();
try (RepositoryConnection con = repo.getConnection()) {
con.add(new File(args[0]), "http://data.gov.be", fmtin.get());
// Various namespace prefixes
con.setNamespace(DCAT.PREFIX, DCAT.NAMESPACE);
con.setNamespace(DCTERMS.PREFIX, DCTERMS.NAMESPACE);
con.setNamespace(FOAF.PREFIX, FOAF.NAMESPACE);
con.setNamespace("vcard", "http://www.w3.org/2006/vcard/ns#");
con.setNamespace("locn", "http://www.w3.org/ns/locn#");
FileOutputStream fout = new FileOutputStream(new File(args[1]));
RDFWriter writer;
if (fmtout.get().equals(RDFFormat.RDFXML)) {
writer = new RDFXMLPrettyWriterFactory().getWriter(fout);
} else {
writer = Rio.createWriter(fmtout.get(), fout);
}
logger.info("Using writer {}", writer.getClass().getCanonicalName());
con.export(writer);
} catch (IOException ex) {
logger.error("Error converting", ex);
code = -1;
}
repo.shutDown();
System.exit(code);
}
示例12: RDFQueryLogWriter
import org.eclipse.rdf4j.rio.RDFWriter; //导入依赖的package包/类
public RDFQueryLogWriter(RDFWriter handler) {
this.handler = handler;
}