use of org.openrdf.query.MalformedQueryException 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