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;
}
}
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);
}
}
}
}
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);
}
}
}
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);
}
}
Aggregations