use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class TurtleWriter method startRDF.
@Override
public void startRDF() throws RDFHandlerException {
if (writingStarted) {
throw new RuntimeException("Document writing has already started");
}
writingStarted = true;
try {
xsdStringToPlainLiteral = getWriterConfig().get(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL);
prettyPrint = getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT);
inlineBNodes = getWriterConfig().get(BasicWriterSettings.INLINE_BLANK_NODES);
if (prettyPrint) {
writer.setIndentationString(" ");
} else {
writer.setIndentationString("");
}
if (baseIRI != null && getWriterConfig().get(BasicWriterSettings.BASE_DIRECTIVE)) {
writeBase(baseIRI.toString());
}
// Write namespace declarations
for (Map.Entry<String, String> entry : namespaceTable.entrySet()) {
String name = entry.getKey();
String prefix = entry.getValue();
writeNamespace(prefix, name);
}
if (!namespaceTable.isEmpty()) {
writer.writeEOL();
}
} catch (IOException e) {
throw new RDFHandlerException(e);
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class NQuadsWriter method handleStatement.
@Override
public void handleStatement(Statement st) throws RDFHandlerException {
if (!writingStarted) {
throw new RuntimeException("Document writing has not yet been started");
}
try {
// SUBJECT
writeValue(st.getSubject());
writer.write(" ");
// PREDICATE
writeValue(st.getPredicate());
writer.write(" ");
// OBJECT
writeValue(st.getObject());
if (null != st.getContext()) {
writer.write(" ");
writeValue(st.getContext());
}
writer.write(" .\n");
} catch (IOException e) {
throw new RDFHandlerException(e);
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project timbuctoo by HuygensING.
the class Rdf4jRdfParser method importRdf.
@Override
public void importRdf(CachedLog input, String baseUri, String defaultGraph, RdfProcessor rdfProcessor) throws RdfProcessingFailedException {
try {
RDFFormat format = Rio.getParserFormatForMIMEType(input.getMimeType().toString()).orElseThrow(() -> new UnsupportedRDFormatException(input.getMimeType() + " is not a supported rdf type."));
RDFParser rdfParser = Rio.createParser(format);
rdfParser.setPreserveBNodeIDs(true);
rdfParser.setRDFHandler(new TimRdfHandler(rdfProcessor, defaultGraph, input.getFile().getName()));
rdfParser.parse(input.getReader(), baseUri);
} catch (IOException | RDFParseException | UnsupportedRDFormatException e) {
throw new RdfProcessingFailedException(e);
} catch (RDFHandlerException e) {
if (e.getCause() instanceof RdfProcessingFailedException) {
throw (RdfProcessingFailedException) e.getCause();
} else {
throw new RdfProcessingFailedException(e);
}
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project timbuctoo by HuygensING.
the class TimRdfHandler method handleStatement.
@Override
public void handleStatement(Statement st) throws RDFHandlerException {
try {
if (Thread.currentThread().isInterrupted()) {
rdfProcessor.commit();
throw new RDFHandlerException("Interrupted");
}
String graph = st.getContext() == null ? defaultGraph : st.getContext().stringValue();
rdfProcessor.onQuad(isAssertion(), handleNode(st.getSubject()), st.getPredicate().stringValue(), handleNode(st.getObject()), (st.getObject() instanceof Literal) ? ((Literal) st.getObject()).getDatatype().toString() : null, (st.getObject() instanceof Literal) ? ((Literal) st.getObject()).getLanguage().orElse(null) : null, graph);
} catch (RdfProcessingFailedException e) {
throw new RDFHandlerException(e);
}
}
Aggregations