Search in sources :

Example 16 with MalformedQueryException

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);
    }
}
Also used : UpdateExecutionException(org.openrdf.query.UpdateExecutionException) RepositoryException(org.openrdf.repository.RepositoryException) IOException(java.io.IOException) Properties(java.util.Properties) CatalogXmlIRIMapper(org.obolibrary.robot.CatalogXmlIRIMapper) BigdataSailRepository(com.bigdata.rdf.sail.BigdataSailRepository) MalformedQueryException(org.openrdf.query.MalformedQueryException) BigdataSail(com.bigdata.rdf.sail.BigdataSail) BlazegraphMutationCounter(org.geneontology.minerva.util.BlazegraphMutationCounter)

Aggregations

MalformedQueryException (org.openrdf.query.MalformedQueryException)16 IOException (java.io.IOException)4 StandardizingSPARQLParser (openrdffork.StandardizingSPARQLParser)4 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)4 RepositoryException (org.openrdf.repository.RepositoryException)4 HashMap (java.util.HashMap)3 TupleQueryResult (org.openrdf.query.TupleQueryResult)3 Bigdata2ASTSPARQLParser (com.bigdata.rdf.sail.sparql.Bigdata2ASTSPARQLParser)2 ASTContainer (com.bigdata.rdf.sparql.ast.ASTContainer)2 RenderVisitor (openrdffork.RenderVisitor)2 TupleQuery (org.openrdf.query.TupleQuery)2 UpdateExecutionException (org.openrdf.query.UpdateExecutionException)2 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)2 ParsedQuery (org.openrdf.query.parser.ParsedQuery)2 BigdataSail (com.bigdata.rdf.sail.BigdataSail)1 BigdataSailRepository (com.bigdata.rdf.sail.BigdataSailRepository)1 BigdataSailRepositoryConnection (com.bigdata.rdf.sail.BigdataSailRepositoryConnection)1 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)1 MalformedSPARQLException (com.thoughtworks.studios.shine.semweb.MalformedSPARQLException)1 MoreThanOneResultFoundException (com.thoughtworks.studios.shine.semweb.MoreThanOneResultFoundException)1