Search in sources :

Example 11 with RDFParseException

use of org.openrdf.rio.RDFParseException in project incubator-rya by apache.

the class RyaSailRepositoryConnection method add.

@Override
public void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    CombineContextsRdfInserter rdfInserter = new CombineContextsRdfInserter(this);
    rdfInserter.enforceContext(contexts);
    boolean localTransaction = startLocalTransaction();
    try {
        RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
        loader.load(reader, baseURI, dataFormat, rdfInserter);
        conditionalCommit(localTransaction);
    } catch (RDFHandlerException e) {
        conditionalRollback(localTransaction);
        throw ((RepositoryException) e.getCause());
    } catch (RDFParseException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (IOException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (RuntimeException e) {
        conditionalRollback(localTransaction);
        throw e;
    }
}
Also used : RDFHandlerException(org.openrdf.rio.RDFHandlerException) CombineContextsRdfInserter(org.apache.rya.rdftriplestore.utils.CombineContextsRdfInserter) RepositoryException(org.openrdf.repository.RepositoryException) IOException(java.io.IOException) RDFLoader(org.openrdf.repository.util.RDFLoader) RDFParseException(org.openrdf.rio.RDFParseException)

Example 12 with RDFParseException

use of org.openrdf.rio.RDFParseException in project incubator-rya by apache.

the class AccumuloLoadStatementsFile method loadStatements.

@Override
public void loadStatements(final String ryaInstanceName, final Path statementsFile, final RDFFormat format) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(ryaInstanceName);
    requireNonNull(statementsFile);
    requireNonNull(format);
    // Ensure the Rya Instance exists.
    if (!instanceExists.exists(ryaInstanceName)) {
        throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
    }
    Sail sail = null;
    SailRepository sailRepo = null;
    SailRepositoryConnection sailRepoConn = null;
    try {
        // Get a Sail object that is connected to the Rya instance.
        final AccumuloRdfConfiguration ryaConf = getAccumuloConnectionDetails().buildAccumuloRdfConfiguration(ryaInstanceName);
        // RYA-327 should address this hardcoded value.
        ryaConf.setFlush(false);
        sail = RyaSailFactory.getInstance(ryaConf);
        // Load the file.
        sailRepo = new SailRepository(sail);
        sailRepoConn = sailRepo.getConnection();
        sailRepoConn.add(statementsFile.toFile(), null, format);
    } catch (final SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
        log.warn("Exception while loading:", e);
        throw new RyaClientException("A problem connecting to the Rya instance named '" + ryaInstanceName + "' has caused the load to fail.", e);
    } catch (final RepositoryException | RDFParseException | UnsupportedRDFormatException | IOException e) {
        log.warn("Exception while loading:", e);
        throw new RyaClientException("A problem processing the RDF file has caused the load into Rya instance named " + ryaInstanceName + "to fail.", e);
    } finally {
        // Shut it all down.
        if (sailRepoConn != null) {
            try {
                sailRepoConn.close();
            } catch (final RepositoryException e) {
                log.warn("Couldn't close the SailRepoConnection that is attached to the Rya instance.", e);
            }
        }
        if (sailRepo != null) {
            try {
                sailRepo.shutDown();
            } catch (final RepositoryException e) {
                log.warn("Couldn't shut down the SailRepository that is attached to the Rya instance.", e);
            }
        }
        if (sail != null) {
            try {
                sail.shutDown();
            } catch (final SailException e) {
                log.warn("Couldn't shut down the Sail that is attached to the Rya instance.", e);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) UnsupportedRDFormatException(org.openrdf.rio.UnsupportedRDFormatException) RyaClientException(org.apache.rya.api.client.RyaClientException) SailRepository(org.openrdf.repository.sail.SailRepository) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RepositoryException(org.openrdf.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.openrdf.sail.SailException) IOException(java.io.IOException) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Sail(org.openrdf.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) RDFParseException(org.openrdf.rio.RDFParseException)

Example 13 with RDFParseException

use of org.openrdf.rio.RDFParseException in project wikidata-query-rdf by wikimedia.

the class Munge method run.

public void run() throws RDFHandlerException, IOException, RDFParseException, InterruptedException {
    try {
        AsyncRDFHandler chunkWriter = AsyncRDFHandler.processAsync(new RDFChunkWriter(chunkFileFormat), false, BUFFER_SIZE);
        AtomicLong actualChunk = new AtomicLong(0);
        EntityMungingRdfHandler.EntityCountListener chunker = (entities) -> {
            long currentChunk = entities / chunkSize;
            if (currentChunk != actualChunk.get()) {
                actualChunk.set(currentChunk);
                // endRDF will cause RDFChunkWriter to start writing a new chunk
                chunkWriter.endRDF();
            }
        };
        EntityMungingRdfHandler munger = new EntityMungingRdfHandler(uris, this.munger, chunkWriter, chunker);
        RDFParser parser = RDFParserSuppliers.defaultRdfParser().get(AsyncRDFHandler.processAsync(new NormalizingRdfHandler(munger), true, BUFFER_SIZE));
        parser.parse(from, uris.root());
        // thread:main: parser -> AsyncRDFHandler -> queue
        // thread:replayer1: Normalizing/Munging -> AsyncRDFHandler -> queue
        // thread:replayer2: RDFChunkWriter -> RDFWriter -> IO
        chunkWriter.waitForCompletion();
    } finally {
        try {
            from.close();
        } catch (IOException e) {
            log.error("Error closing input", e);
        }
    }
}
Also used : Statement(org.openrdf.model.Statement) Munger(org.wikidata.query.rdf.tool.rdf.Munger) LoggerFactory(org.slf4j.LoggerFactory) NormalizingRdfHandler(org.wikidata.query.rdf.tool.rdf.NormalizingRdfHandler) LinkedHashMap(java.util.LinkedHashMap) RDFFormat(org.openrdf.rio.RDFFormat) Locale(java.util.Locale) Map(java.util.Map) MungeOptions(org.wikidata.query.rdf.tool.options.MungeOptions) BasicWriterSettings(org.openrdf.rio.helpers.BasicWriterSettings) AsyncRDFHandler(org.wikidata.query.rdf.tool.rdf.AsyncRDFHandler) OptionsUtils.mungerFromOptions(org.wikidata.query.rdf.tool.options.OptionsUtils.mungerFromOptions) FALSE(java.lang.Boolean.FALSE) Logger(org.slf4j.Logger) RDFHandlerException(org.openrdf.rio.RDFHandlerException) OptionsUtils(org.wikidata.query.rdf.tool.options.OptionsUtils) RDFParserSuppliers(org.wikidata.query.rdf.tool.rdf.RDFParserSuppliers) WriterConfig(org.openrdf.rio.WriterConfig) IOException(java.io.IOException) Rio(org.openrdf.rio.Rio) Reader(java.io.Reader) PrefixRecordingRdfHandler(org.wikidata.query.rdf.tool.rdf.PrefixRecordingRdfHandler) AtomicLong(java.util.concurrent.atomic.AtomicLong) RDFParser(org.openrdf.rio.RDFParser) OptionsUtils.handleOptions(org.wikidata.query.rdf.tool.options.OptionsUtils.handleOptions) RDFParseException(org.openrdf.rio.RDFParseException) UrisScheme(org.wikidata.query.rdf.common.uri.UrisScheme) Writer(java.io.Writer) EntityMungingRdfHandler(org.wikidata.query.rdf.tool.rdf.EntityMungingRdfHandler) RDFHandler(org.openrdf.rio.RDFHandler) RDFWriter(org.openrdf.rio.RDFWriter) AtomicLong(java.util.concurrent.atomic.AtomicLong) EntityMungingRdfHandler(org.wikidata.query.rdf.tool.rdf.EntityMungingRdfHandler) AsyncRDFHandler(org.wikidata.query.rdf.tool.rdf.AsyncRDFHandler) IOException(java.io.IOException) RDFParser(org.openrdf.rio.RDFParser) NormalizingRdfHandler(org.wikidata.query.rdf.tool.rdf.NormalizingRdfHandler)

Example 14 with RDFParseException

use of org.openrdf.rio.RDFParseException in project vcell by virtualcell.

the class PCIDRequest method response.

@Override
public PathwayCommonsResponse response() {
    try {
        URL url = url();
        URLConnection connection = url.openConnection();
        String text = StringUtil.textFromInputStream(connection.getInputStream());
        Graph graph = new HashGraph();
        Map<String, String> nsMap = new HashMap<String, String>();
        SesameRioUtil.readRDFFromString(text, graph, nsMap, RDFFormat.RDFXML, uriBase);
        try {
            return new PCTextModelResponse(this, text, graph);
        } catch (Throwable t) {
            return new PCTextResponse(this, text);
        }
    } catch (MalformedURLException e) {
        return new PCExceptionResponse(this, e);
    } catch (IOException e) {
        return new PCExceptionResponse(this, e);
    } catch (RDFParseException e) {
        return new PCExceptionResponse(this, e);
    } catch (RDFHandlerException e) {
        return new PCExceptionResponse(this, e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) HashGraph(org.sbpax.impl.HashGraph) Graph(org.openrdf.model.Graph) HashGraph(org.sbpax.impl.HashGraph) RDFHandlerException(org.openrdf.rio.RDFHandlerException) PCExceptionResponse(org.vcell.sybil.util.http.pathwaycommons.PCExceptionResponse) RDFParseException(org.openrdf.rio.RDFParseException)

Aggregations

RDFParseException (org.openrdf.rio.RDFParseException)14 IOException (java.io.IOException)13 RDFHandlerException (org.openrdf.rio.RDFHandlerException)10 RepositoryException (org.openrdf.repository.RepositoryException)6 RDFParser (org.openrdf.rio.RDFParser)5 InputStreamReader (java.io.InputStreamReader)4 RDFFormat (org.openrdf.rio.RDFFormat)4 Statement (org.openrdf.model.Statement)3 SailRepository (org.openrdf.repository.sail.SailRepository)3 SocketException (java.net.SocketException)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)2 RyaClientException (org.apache.rya.api.client.RyaClientException)2