Search in sources :

Example 26 with RDFHandlerException

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);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) IOException(java.io.IOException)

Example 27 with RDFHandlerException

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);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) IOException(java.io.IOException)

Example 28 with RDFHandlerException

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);
        }
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 29 with RDFHandlerException

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);
    }
}
Also used : JSONLDMode(org.eclipse.rdf4j.rio.helpers.JSONLDMode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) JsonLdError(com.github.jsonldjava.core.JsonLdError) LinkedHashMap(java.util.LinkedHashMap) JsonLdOptions(com.github.jsonldjava.core.JsonLdOptions) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException)

Example 30 with RDFHandlerException

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);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) IOException(java.io.IOException)

Aggregations

RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)99 IOException (java.io.IOException)51 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)24 Statement (org.eclipse.rdf4j.model.Statement)20 IRI (org.eclipse.rdf4j.model.IRI)19 Resource (org.eclipse.rdf4j.model.Resource)19 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)17 Value (org.eclipse.rdf4j.model.Value)12 RDFLoader (org.eclipse.rdf4j.repository.util.RDFLoader)10 AbstractRDFHandler (org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 ParsedIRI (org.eclipse.rdf4j.common.net.ParsedIRI)8 BNode (org.eclipse.rdf4j.model.BNode)8 Literal (org.eclipse.rdf4j.model.Literal)8 RDFParser (org.eclipse.rdf4j.rio.RDFParser)8 HashSet (java.util.HashSet)7 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)7 LpException (com.linkedpipes.etl.executor.api.v1.LpException)5 HashMap (java.util.HashMap)5 LinkedHashSet (java.util.LinkedHashSet)5