本文整理汇总了Java中org.apache.jena.riot.system.StreamRDF.finish方法的典型用法代码示例。如果您正苦于以下问题:Java StreamRDF.finish方法的具体用法?Java StreamRDF.finish怎么用?Java StreamRDF.finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.riot.system.StreamRDF
的用法示例。
在下文中一共展示了StreamRDF.finish方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTurtle
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
public void writeTurtle(String baseIRI, PrefixMapping prefixes, boolean writeBase) {
// Auto-register RDF prefix so that rdf:type is displayed well
// All other prefixes come from the query and should be as author intended
prefixes = ensureRDFPrefix(prefixes);
if (writeBase) {
// Jena's streaming Turtle writers don't output base even if it is provided,
// so we write it directly.
IndentedWriter w = new IndentedWriter(out);
RiotLib.writeBase(w, baseIRI);
w.flush();
}
StreamRDF writer = new WriterStreamRDFBlocks(out);
if (dedupWindowSize > 0) {
writer = new StreamRDFDedup(writer, dedupWindowSize);
}
writer.start();
writer.base(baseIRI);
for (Entry<String, String> e : prefixes.getNsPrefixMap().entrySet()) {
writer.prefix(e.getKey(), e.getValue());
}
StreamOps.sendTriplesToStream(triples, writer);
writer.finish();
}
示例2: write
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
private static void write(final RdfStream rdfStream,
final OutputStream output,
final Lang dataFormat,
final MediaType dataMediaType) throws IOException {
final RDFFormat format = defaultSerialization(dataFormat);
// For formats that can be block-streamed (n-triples, turtle)
if (format != null) {
LOGGER.debug("Stream-based serialization of {}", dataFormat.toString());
final StreamRDF stream = getWriterStream(output, format);
stream.start();
rdfStream.forEach(stream::triple);
stream.finish();
// For formats that require analysis of the entire model and cannot be streamed directly (rdfxml, n3)
} else {
LOGGER.debug("Non-stream serialization of {}", dataFormat.toString());
final Model model = rdfStream.collect(toModel());
// use block output streaming for RDFXML
if (RDFXML.equals(dataFormat)) {
RDFDataMgr.write(output, model.getGraph(), RDFXML_PLAIN);
} else if (JSONLD.equals(dataFormat)) {
final RDFFormat jsonldFormat = getFormatFromMediaType(dataMediaType);
RDFDataMgr.write(output, model.getGraph(), jsonldFormat);
} else {
RDFDataMgr.write(output, model.getGraph(), dataFormat);
}
}
}
示例3: write
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
@Override
public void write(final Stream<? extends Triple> triples, final OutputStream output, final RDFSyntax syntax,
final IRI... profiles) {
requireNonNull(triples, "The triples stream may not be null!");
requireNonNull(output, "The output stream may not be null!");
requireNonNull(syntax, "The RDF syntax value may not be null!");
try {
if (RDFA.equals(syntax)) {
htmlSerializer.write(output, triples, profiles.length > 0 ? profiles[0] : null);
} else {
final Lang lang = rdf.asJenaLang(syntax).orElseThrow(() ->
new RuntimeTrellisException("Invalid content type: " + syntax.mediaType()));
final RDFFormat format = defaultSerialization(lang);
if (nonNull(format)) {
LOGGER.debug("Writing stream-based RDF: {}", format);
final StreamRDF stream = getWriterStream(output, format);
stream.start();
ofNullable(nsService).ifPresent(svc -> svc.getNamespaces().forEach(stream::prefix));
triples.map(rdf::asJenaTriple).forEachOrdered(stream::triple);
stream.finish();
} else {
LOGGER.debug("Writing buffered RDF: {}", lang);
final org.apache.jena.graph.Graph graph = createDefaultGraph();
ofNullable(nsService).map(NamespaceService::getNamespaces)
.ifPresent(graph.getPrefixMapping()::setNsPrefixes);
triples.map(rdf::asJenaTriple).forEachOrdered(graph::add);
if (JSONLD.equals(lang)) {
writeJsonLd(output, DatasetGraphFactory.create(graph), profiles);
} else {
RDFDataMgr.write(output, graph, lang);
}
}
}
} catch (final AtlasException ex) {
throw new RuntimeTrellisException(ex);
}
}
示例4: write
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
@Override
public void write(final Stream<? extends Triple> triples, final OutputStream output, final RDFSyntax syntax,
final IRI... profiles) {
requireNonNull(triples, "The triples stream may not be null!");
requireNonNull(output, "The output stream may not be null!");
requireNonNull(syntax, "The RDF syntax value may not be null!");
try {
if (RDFA_HTML.equals(syntax)) {
htmlSerializer.write(output, triples, profiles.length > 0 ? profiles[0] : null);
} else {
final Lang lang = rdf.asJenaLang(syntax).orElseThrow(() ->
new RuntimeRepositoryException("Invalid content type: " + syntax.mediaType));
final RDFFormat format = defaultSerialization(lang);
if (nonNull(format)) {
LOGGER.debug("Writing stream-based RDF: {}", format);
final StreamRDF stream = getWriterStream(output, format);
stream.start();
ofNullable(nsService).ifPresent(svc -> svc.getNamespaces().forEach(stream::prefix));
triples.map(rdf::asJenaTriple).forEachOrdered(stream::triple);
stream.finish();
} else {
LOGGER.debug("Writing buffered RDF: {}", lang);
final org.apache.jena.graph.Graph graph = createDefaultGraph();
ofNullable(nsService).map(NamespaceService::getNamespaces)
.ifPresent(graph.getPrefixMapping()::setNsPrefixes);
triples.map(rdf::asJenaTriple).forEachOrdered(graph::add);
if (JSONLD.equals(lang)) {
writeJsonLd(output, DatasetGraphFactory.create(graph), profiles);
} else {
RDFDataMgr.write(output, graph, lang);
}
}
}
} catch (final AtlasException ex) {
throw new RuntimeRepositoryException(ex);
}
}
示例5: exec
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
@Override
protected void exec() {
StreamRDF dest = new StreamPatch(System.out);
dest.start();
if ( getPositional().isEmpty() )
execOne(System.in);
getPositional().forEach(fn->{
RDFDataMgr.parse(dest, fn);
// InputStream input = IO.openFile(fn);
// execOne(input);
});
dest.finish();
}
示例6: exportTree
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
@Override
public void exportTree(String uri, StreamRDF out) {
RegisterItem item = asItem(uri);
out.start();
try {
doExportTree(item, out);
} finally {
out.finish();
}
}
示例7: write
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
private static void write(final RdfStream rdfStream,
final OutputStream output,
final Lang dataFormat,
final MediaType dataMediaType,
final Map<String, String> nsPrefixes) throws IOException {
final RDFFormat format = defaultSerialization(dataFormat);
// For formats that can be block-streamed (n-triples, turtle)
if (format != null) {
LOGGER.debug("Stream-based serialization of {}", dataFormat.toString());
final StreamRDF stream = new SynchonizedStreamRDFWrapper(getWriterStream(output, format));
stream.start();
nsPrefixes.forEach(stream::prefix);
rdfStream.forEach(stream::triple);
stream.finish();
// For formats that require analysis of the entire model and cannot be streamed directly (rdfxml, n3)
} else {
LOGGER.debug("Non-stream serialization of {}", dataFormat.toString());
final Model model = rdfStream.collect(toModel());
model.setNsPrefixes(nsPrefixes);
// use block output streaming for RDFXML
if (RDFXML.equals(dataFormat)) {
RDFDataMgr.write(output, model.getGraph(), RDFXML_PLAIN);
} else if (JSONLD.equals(dataFormat)) {
final RDFFormat jsonldFormat = getFormatFromMediaType(dataMediaType);
RDFDataMgr.write(output, model.getGraph(), jsonldFormat);
} else {
RDFDataMgr.write(output, model.getGraph(), dataFormat);
}
}
}
示例8: writeNTriples
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
public void writeNTriples() {
StreamRDF writer = new WriterStreamRDFPlain(new IndentedWriter(out));
if (dedupWindowSize > 0) {
writer = new StreamRDFDedup(writer, dedupWindowSize);
}
writer.start();
StreamOps.sendTriplesToStream(triples, writer);
writer.finish();
}
示例9: shouldPassThroughTriples
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
@Test public void shouldPassThroughTriples() {
StreamRDF dedup = new StreamRDFDedup(new MockStreamRDF());
dedup.start();
dedup.triple(triple("<a> <a> <a>"));
dedup.triple(triple("<b> <b> <b>"));
dedup.triple(triple("<c> <c> <c>"));
dedup.finish();
assertEquals(triples("<a> <a> <a>", "<b> <b> <b>", "<c> <c> <c>"), received);
}
示例10: shouldRemoveDuplicateInWindow
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
@Test public void shouldRemoveDuplicateInWindow() {
StreamRDF dedup = new StreamRDFDedup(new MockStreamRDF());
dedup.start();
dedup.triple(triple("<a> <a> <a>"));
dedup.triple(triple("<a> <a> <a>"));
dedup.finish();
assertEquals(triples("<a> <a> <a>"), received);
}
示例11: shouldNotRemoveDuplicateOutsideWindow
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
@Test public void shouldNotRemoveDuplicateOutsideWindow() {
StreamRDF dedup = new StreamRDFDedup(new MockStreamRDF(), 2);
dedup.start();
dedup.triple(triple("<a> <a> <a>"));
dedup.triple(triple("<b> <b> <b>"));
dedup.triple(triple("<a> <a> <a>"));
dedup.triple(triple("<c> <c> <c>"));
dedup.triple(triple("<a> <a> <a>"));
dedup.finish();
assertEquals(triples("<a> <a> <a>", "<b> <b> <b>", "<c> <c> <c>", "<a> <a> <a>"), received);
}
示例12: run
import org.apache.jena.riot.system.StreamRDF; //导入方法依赖的package包/类
public static void run() {
new File("datasets2/").mkdirs();
FileOutputStream output;
try {
output = new FileOutputStream(new File("datasets2/" + FILE));
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
final StreamRDF writer = StreamRDFWriter.getWriterStream(output,
Lang.NT);
TreeSet<String> articleIDs = new TreeSet<>();
TreeSet<String> satelliteIDs = new TreeSet<>();
// stream dataset
// search for ?s a <ArticleClass>
// collect article IDs
collectWrite(articleIDs, writer);
System.out.println("file = " + FILE);
System.out.println("articles = " + articleIDs.size());
// for each article ID:
// add its CBD and
// collect satellite IDs
for (String a : articleIDs) {
System.out.print(a + "...");
cbd(a, writer, articleIDs, satelliteIDs, true);
System.out.println(" OK");
}
System.out.println();
System.out.println("satellites = " + satelliteIDs.size());
// for each satellite ID:
// launch describe query
// write out triples
for (String aut : satelliteIDs) {
System.out.print(aut + "...");
boolean success = cbd(aut, writer, articleIDs, satelliteIDs, false);
if(success)
System.out.println(" OK");
else
System.out.println(" skipped");
}
writer.finish();
System.out.println("\nDone.");
}