use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class TriGWriter method endRDF.
@Override
public void endRDF() throws RDFHandlerException {
super.endRDF();
try {
closeActiveContext();
writer.flush();
} catch (IOException e) {
throw new RDFHandlerException(e);
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class BinaryRDFWriter method handleStatement.
public void handleStatement(Statement st) throws RDFHandlerException {
statementQueue.add(st);
incValueFreq(st.getSubject());
incValueFreq(st.getPredicate());
incValueFreq(st.getObject());
incValueFreq(st.getContext());
if (statementQueue.remainingCapacity() > 0) {
// postpone statement writing until queue is filled
return;
}
// Process the first statement from the queue
startRDF();
try {
writeStatement();
} catch (IOException e) {
throw new RDFHandlerException(e);
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class JSONLDInternalTripleCallback method triple.
private void triple(String s, String p, String value, String datatype, String language, String graph) {
if (s == null || p == null || value == null) {
// TODO: i don't know what to do here!!!!
return;
}
final Resource subject = createResource(s);
final IRI predicate = vf.createIRI(p);
final IRI datatypeURI = datatype == null ? null : vf.createIRI(datatype);
Value object;
try {
object = RDFParserHelper.createLiteral(value, language, datatypeURI, getParserConfig(), getParserErrorListener(), getValueFactory());
} catch (final RDFParseException e) {
throw new RuntimeException(e);
}
Statement result;
if (graph == null) {
result = vf.createStatement(subject, predicate, object);
} else {
result = vf.createStatement(subject, predicate, object, createResource(graph));
}
if (handler != null) {
try {
handler.handleStatement(result);
} catch (final RDFHandlerException e) {
throw new RuntimeException(e);
}
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class JSONLDWriter method endRDF.
@Override
public void endRDF() throws RDFHandlerException {
final JSONLDInternalRDFParser serialiser = new JSONLDInternalRDFParser();
try {
Object output = JsonLdProcessor.fromRDF(model, serialiser);
final JSONLDMode mode = getWriterConfig().get(JSONLDSettings.JSONLD_MODE);
final JsonLdOptions opts = new JsonLdOptions();
// opts.addBlankNodeIDs =
// getWriterConfig().get(BasicParserSettings.PRESERVE_BNODE_IDS);
opts.setUseRdfType(getWriterConfig().get(JSONLDSettings.USE_RDF_TYPE));
opts.setUseNativeTypes(getWriterConfig().get(JSONLDSettings.USE_NATIVE_TYPES));
if (baseURI != null && getWriterConfig().get(BasicWriterSettings.BASE_DIRECTIVE)) {
opts.setBase(baseURI);
}
if (mode == JSONLDMode.EXPAND) {
output = JsonLdProcessor.expand(output, opts);
}
// TODO: Implement inframe in JSONLDSettings
final Object inframe = null;
if (mode == JSONLDMode.FLATTEN) {
output = JsonLdProcessor.flatten(output, inframe, opts);
}
if (mode == JSONLDMode.COMPACT) {
final Map<String, Object> ctx = new LinkedHashMap<String, Object>();
addPrefixes(ctx, model.getNamespaces());
final Map<String, Object> localCtx = new HashMap<String, Object>();
localCtx.put("@context", ctx);
output = JsonLdProcessor.compact(output, localCtx, opts);
}
if (getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT)) {
JsonUtils.writePrettyPrint(writer, output);
} else {
JsonUtils.write(writer, output);
}
} catch (final JsonLdError e) {
throw new RDFHandlerException("Could not render JSONLD", e);
} catch (final JsonGenerationException e) {
throw new RDFHandlerException("Could not render JSONLD", e);
} catch (final JsonMappingException e) {
throw new RDFHandlerException("Could not render JSONLD", e);
} catch (final IOException e) {
throw new RDFHandlerException("Could not render JSONLD", e);
}
}
use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.
the class NTriplesWriter method handleStatement.
@Override
public void handleStatement(Statement st) throws RDFHandlerException {
if (!writingStarted) {
throw new RuntimeException("Document writing has not yet been started");
}
try {
writeValue(st.getSubject());
writer.write(" ");
writeIRI(st.getPredicate());
writer.write(" ");
writeValue(st.getObject());
writer.write(" .\n");
} catch (IOException e) {
throw new RDFHandlerException(e);
}
}
Aggregations