Search in sources :

Example 1 with TimRdfHandler

use of nl.knaw.huygens.timbuctoo.v5.rdfio.implementations.rdf4j.parsers.TimRdfHandler 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);
        }
    }
}
Also used : UnsupportedRDFormatException(org.eclipse.rdf4j.rio.UnsupportedRDFormatException) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) TimRdfHandler(nl.knaw.huygens.timbuctoo.v5.rdfio.implementations.rdf4j.parsers.TimRdfHandler) IOException(java.io.IOException) RDFParser(org.eclipse.rdf4j.rio.RDFParser) RdfProcessingFailedException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.RdfProcessingFailedException) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Aggregations

IOException (java.io.IOException)1 RdfProcessingFailedException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.RdfProcessingFailedException)1 TimRdfHandler (nl.knaw.huygens.timbuctoo.v5.rdfio.implementations.rdf4j.parsers.TimRdfHandler)1 RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)1 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)1 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)1 RDFParser (org.eclipse.rdf4j.rio.RDFParser)1 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)1