本文整理汇总了Java中org.eclipse.rdf4j.rio.Rio.createWriter方法的典型用法代码示例。如果您正苦于以下问题:Java Rio.createWriter方法的具体用法?Java Rio.createWriter怎么用?Java Rio.createWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.rdf4j.rio.Rio
的用法示例。
在下文中一共展示了Rio.createWriter方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: data
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Parameters(name = "{0}")
public static Collection<Object[]> data() {
Collection<Object[]> result = new ArrayList<>();
for (RDFFormat nextParserFormat : RDFParserRegistry.getInstance().getKeys()) {
try {
// Try to create a writer, as not all formats (RDFa for example) have writers,
// and we can't automatically test those formats like this
OutputStream out = new ByteArrayOutputStream();
Rio.createWriter(nextParserFormat, out);
// If the writer creation did not throw an exception, add it to the list
result.add(new Object[]{nextParserFormat});
} catch(UnsupportedRDFormatException e) {
// Ignore to drop this format from the list
}
}
assertFalse("No RDFFormats found with RDFParser and RDFWriter implementations on classpath", result.isEmpty());
return result;
}
示例2: mergeResourceWithPrefixes
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的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;
}
示例3: getString
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的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();
}
示例4: getModel
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的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;
}
示例5: testConstructQueryWithWriter
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的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);
}
示例6: write
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的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");
}
}
示例7: writeTo
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Override
public void writeTo(OutputStream stream, Syntax syntax) throws
// interface allows it
IOException, ModelRuntimeException {
RDFWriter rdfWriter = Rio.createWriter(getRDFFormat(syntax), stream);
writeTo(rdfWriter);
}
示例8: Rdf4jWriter
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
public Rdf4jWriter(OutputStream outputStream, RDFFormat rdfFormat) {
writer = new BufferedWriter(new OutputStreamWriter(outputStream, UTF_8));
rdfWriter = Rio.createWriter(rdfFormat, writer);
this.rdfFormat = rdfFormat;
valueFactory = SimpleValueFactory.getInstance();
rdfWriter.startRDF();
}
示例9: setup
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Override
protected void setup(Context context) throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
statsGraphContext = SVF.createIRI(conf.get(GRAPH_CONTEXT, HALYARD.STATS_GRAPH_CONTEXT.stringValue()));
String targetUrl = conf.get(TARGET);
if (targetUrl == null) {
sail = new HBaseSail(conf, conf.get(SOURCE), false, 0, true, 0, null, null);
sail.initialize();
sail.setNamespace(SD.PREFIX, SD.NAMESPACE);
sail.setNamespace(VOID.PREFIX, VOID.NAMESPACE);
sail.setNamespace(VOID_EXT.PREFIX, VOID_EXT.NAMESPACE);
sail.setNamespace(HALYARD.PREFIX, HALYARD.NAMESPACE);
} else {
targetUrl = MessageFormat.format(targetUrl, context.getTaskAttemptID().getTaskID().getId());
out = FileSystem.get(URI.create(targetUrl), conf).create(new Path(targetUrl));
try {
if (targetUrl.endsWith(".bz2")) {
out = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.BZIP2, out);
targetUrl = targetUrl.substring(0, targetUrl.length() - 4);
} else if (targetUrl.endsWith(".gz")) {
out = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, out);
targetUrl = targetUrl.substring(0, targetUrl.length() - 3);
}
} catch (CompressorException ce) {
throw new IOException(ce);
}
Optional<RDFFormat> form = Rio.getWriterFormatForFileName(targetUrl);
if (!form.isPresent()) throw new IOException("Unsupported target file format extension: " + targetUrl);
writer = Rio.createWriter(form.get(), out);
writer.handleNamespace(SD.PREFIX, SD.NAMESPACE);
writer.handleNamespace(VOID.PREFIX, VOID.NAMESPACE);
writer.handleNamespace(VOID_EXT.PREFIX, VOID_EXT.NAMESPACE);
writer.handleNamespace(HALYARD.PREFIX, HALYARD.NAMESPACE);
writer.startRDF();
}
writeStatement(HALYARD.STATS_ROOT_NODE, RDF.TYPE, VOID.DATASET);
writeStatement(HALYARD.STATS_ROOT_NODE, RDF.TYPE, SD.DATASET);
writeStatement(HALYARD.STATS_ROOT_NODE, RDF.TYPE, SD.GRAPH_CLASS);
writeStatement(HALYARD.STATS_ROOT_NODE, SD.DEFAULT_GRAPH, HALYARD.STATS_ROOT_NODE);
graphs = new WeakHashMap<>();
}
示例10: RIOResultWriter
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
public RIOResultWriter(StatusLog log, RDFFormat rdfFormat, OutputStream out) {
super(log);
this.out = out;
this.writer = Rio.createWriter(rdfFormat, out);
}
示例11: export
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的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();
}
}
示例12: main
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的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);
}
示例13: writeTo
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
* Writes the whole ModelSet to the OutputStream. Depending on the Syntax
* the context URIs might or might not be serialized. TriX should be able to
* serialize contexts.
*/
@Override
public void writeTo(OutputStream out, Syntax syntax) throws IOException, ModelRuntimeException {
RDFWriter rdfWriter = Rio.createWriter(getRDFFormat(syntax), out);
this.writeTo(rdfWriter);
}