use of org.apache.jena.riot.RDFParser in project jena by apache.
the class UpdateEngineWorker method visit.
@Override
public void visit(UpdateLoad update) {
// LOAD SILENT? iri ( INTO GraphRef )?
String source = update.getSource();
Node dest = update.getDest();
Graph graph = graph(datasetGraph, dest);
// We must load buffered if silent so that the dataset graph sees
// all or no triples/quads when there is a parse error
// (no nested transaction abort).
boolean loadBuffered = update.getSilent() || !datasetGraph.supportsTransactionAbort();
try {
if (dest == null) {
// Quads accepted (extension).
if (loadBuffered) {
DatasetGraph dsg2 = DatasetGraphFactory.create();
RDFDataMgr.read(dsg2, source);
dsg2.find().forEachRemaining(datasetGraph::add);
} else {
RDFDataMgr.read(datasetGraph, source);
}
return;
}
// LOAD SILENT? iri INTO GraphRef
// Load triples. To give a decent error message and also not have the usual
// parser behaviour of just selecting default graph triples when the
// destination is a graph, we need to do the same steps as RDFParser.parseURI,
// with different checking.
TypedInputStream input = RDFDataMgr.open(source);
String contentType = input.getContentType();
Lang lang = RDFDataMgr.determineLang(source, contentType, Lang.TTL);
if (lang == null)
throw new UpdateException("Failed to determine the syntax for '" + source + "'");
if (!RDFLanguages.isTriples(lang))
throw new UpdateException("Attempt to load quads into a graph");
RDFParser parser = RDFParser.source(input.getInputStream()).forceLang(lang).build();
if (loadBuffered) {
Graph g = GraphFactory.createGraphMem();
parser.parse(g);
GraphUtil.addInto(graph, g);
} else {
parser.parse(graph);
}
} catch (RuntimeException ex) {
if (!update.getSilent()) {
if (ex instanceof UpdateException)
throw ex;
throw new UpdateException("Failed to LOAD '" + source + "' :: " + ex.getMessage(), ex);
}
}
}
use of org.apache.jena.riot.RDFParser in project jena by apache.
the class tdbloader method loadQuadsStdin.
private void loadQuadsStdin() {
DataLoader loader = chooseLoader(super.getDatasetGraph(), graphName);
StreamRDF dest = loader.stream();
if (lang == null)
lang = Lang.NQUADS;
RDFParser parser = RDFParser.create().lang(lang).source(System.in).build();
long elapsed = Timer.time(() -> {
loader.startBulk();
parser.parse(dest);
loader.finishBulk();
});
// return elapsed;
}
Aggregations