use of com.bigdata.rdf.sail.BigdataSailRepository in project minerva by geneontology.
the class BlazegraphMolecularModelManager method initializeRepository.
private BigdataSailRepository initializeRepository(String pathToJournal) {
try {
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("blazegraph.properties"));
properties.setProperty(Options.FILE, pathToJournal);
BigdataSail sail = new BigdataSail(properties);
BigdataSailRepository repository = new BigdataSailRepository(sail);
repository.initialize();
return repository;
} catch (RepositoryException e) {
LOG.fatal("Could not create Blazegraph sail", e);
return null;
} catch (IOException e) {
LOG.fatal("Could not create Blazegraph sail", e);
return null;
}
}
use of com.bigdata.rdf.sail.BigdataSailRepository in project minerva by geneontology.
the class BlazegraphOntologyManager method initializeRepository.
private BigdataSailRepository initializeRepository(String pathToJournal) {
try {
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("onto-blazegraph.properties"));
properties.setProperty(Options.FILE, pathToJournal);
BigdataSail sail = new BigdataSail(properties);
BigdataSailRepository repository = new BigdataSailRepository(sail);
repository.initialize();
return repository;
} catch (RepositoryException e) {
LOG.fatal("Could not create Blazegraph sail", e);
return null;
} catch (IOException e) {
LOG.fatal("Could not create Blazegraph sail", e);
return null;
}
}
use of com.bigdata.rdf.sail.BigdataSailRepository in project minerva by geneontology.
the class CommandLineInterface method sparqlUpdate.
/**
* Updates the journal with the provided update sparql statement.
* cli parameter --sparql-update
*
* @param journalFilePath
* @param updateFile
* @throws OWLOntologyCreationException
* @throws IOException
* @throws RepositoryException
* @throws MalformedQueryException
* @throws UpdateExecutionException
*/
public static void sparqlUpdate(String journalFilePath, String updateFile) throws OWLOntologyCreationException, IOException, RepositoryException, MalformedQueryException, UpdateExecutionException {
// minimal inputs
if (journalFilePath == null) {
System.err.println("No journal file was configured.");
System.exit(-1);
return;
}
if (updateFile == null) {
System.err.println("No update file was configured.");
System.exit(-1);
return;
}
String update = FileUtils.readFileToString(new File(updateFile), StandardCharsets.UTF_8);
Properties properties = new Properties();
properties.load(CommandLineInterface.class.getResourceAsStream("/org/geneontology/minerva/blazegraph.properties"));
properties.setProperty(com.bigdata.journal.Options.FILE, journalFilePath);
BigdataSail sail = new BigdataSail(properties);
BigdataSailRepository repository = new BigdataSailRepository(sail);
repository.initialize();
BigdataSailRepositoryConnection conn = repository.getUnisolatedConnection();
BlazegraphMutationCounter counter = new BlazegraphMutationCounter();
conn.addChangeLog(counter);
conn.prepareUpdate(QueryLanguage.SPARQL, update).execute();
int changes = counter.mutationCount();
conn.removeChangeLog(counter);
System.out.println("\nApplied " + changes + " changes");
conn.close();
}
use of com.bigdata.rdf.sail.BigdataSailRepository in project minerva by geneontology.
the class ReplaceObsoleteReferencesCommand method run.
public static void run(String ontologyIRI, String catalogPath, String journalFilePath) throws FatalReplaceObsoleteReferencesError {
if (journalFilePath == null) {
throw new FatalReplaceObsoleteReferencesError("No journal file was configured.");
}
if (ontologyIRI == null) {
throw new FatalReplaceObsoleteReferencesError("No ontology IRI was configured.");
}
final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
if (catalogPath != null) {
try {
manager.getIRIMappers().set(new CatalogXmlIRIMapper(catalogPath));
} catch (IOException e) {
throw new FatalReplaceObsoleteReferencesError("Could not load catalog file from " + catalogPath, e);
}
}
final OWLOntology tbox;
try {
tbox = manager.loadOntology(IRI.create(ontologyIRI));
} catch (OWLOntologyCreationException e) {
throw new FatalReplaceObsoleteReferencesError("Could not load tbox ontology from " + ontologyIRI, e);
}
Properties properties = new Properties();
try {
properties.load(CommandLineInterface.class.getResourceAsStream("/org/geneontology/minerva/blazegraph.properties"));
} catch (IOException e) {
throw new FatalReplaceObsoleteReferencesError("Could not read blazegraph properties resource from jar file.");
}
properties.setProperty(com.bigdata.journal.Options.FILE, journalFilePath);
BigdataSail sail = new BigdataSail(properties);
BigdataSailRepository repository = new BigdataSailRepository(sail);
try {
repository.initialize();
} catch (RepositoryException e) {
throw new FatalReplaceObsoleteReferencesError("Could not initialize SAIL repository for database.", e);
}
BlazegraphMutationCounter counter = new BlazegraphMutationCounter();
String replacements = createReplacementsValuesList(tbox);
String sparqlUpdate = updateTemplate.replace("%%%values%%%", replacements);
String complementsSparqlUpdate = complementsUpdateTemplate.replace("%%%values%%%", replacements);
LOGGER.debug("Will apply SPARQL update:\n" + sparqlUpdate);
try {
applySPARQLUpdate(repository, sparqlUpdate, Optional.of(counter));
applySPARQLUpdate(repository, complementsSparqlUpdate, Optional.of(counter));
int changes = counter.mutationCount();
LOGGER.info("Successfully applied database updates to replace obsolete terms: " + changes + " changes");
} catch (RepositoryException | UpdateExecutionException | MalformedQueryException e) {
throw new FatalReplaceObsoleteReferencesError("Failed to apply SPARQL update.", e);
}
}
Aggregations