Search in sources :

Example 1 with BigdataSailRepository

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;
    }
}
Also used : BigdataSailRepository(com.bigdata.rdf.sail.BigdataSailRepository) RepositoryException(org.openrdf.repository.RepositoryException) BigdataSail(com.bigdata.rdf.sail.BigdataSail)

Example 2 with BigdataSailRepository

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;
    }
}
Also used : BigdataSailRepository(com.bigdata.rdf.sail.BigdataSailRepository) RepositoryException(org.openrdf.repository.RepositoryException) BigdataSail(com.bigdata.rdf.sail.BigdataSail) IOException(java.io.IOException)

Example 3 with BigdataSailRepository

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();
}
Also used : BigdataSailRepository(com.bigdata.rdf.sail.BigdataSailRepository) BigdataSailRepositoryConnection(com.bigdata.rdf.sail.BigdataSailRepositoryConnection) BigdataSail(com.bigdata.rdf.sail.BigdataSail) BlazegraphMutationCounter(org.geneontology.minerva.util.BlazegraphMutationCounter)

Example 4 with BigdataSailRepository

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

BigdataSail (com.bigdata.rdf.sail.BigdataSail)4 BigdataSailRepository (com.bigdata.rdf.sail.BigdataSailRepository)4 RepositoryException (org.openrdf.repository.RepositoryException)3 IOException (java.io.IOException)2 BlazegraphMutationCounter (org.geneontology.minerva.util.BlazegraphMutationCounter)2 BigdataSailRepositoryConnection (com.bigdata.rdf.sail.BigdataSailRepositoryConnection)1 Properties (java.util.Properties)1 CatalogXmlIRIMapper (org.obolibrary.robot.CatalogXmlIRIMapper)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1 UpdateExecutionException (org.openrdf.query.UpdateExecutionException)1