Search in sources :

Example 1 with RioMemoryTripleSource

use of org.semanticweb.owlapi.rio.RioMemoryTripleSource in project minerva by geneontology.

the class BlazegraphMolecularModelManager method loadModel.

@Override
public void loadModel(IRI modelId, boolean isOverride) throws OWLOntologyCreationException {
    if (modelMap.containsKey(modelId)) {
        if (!isOverride) {
            throw new OWLOntologyCreationException("Model already exists: " + modelId);
        }
        unlinkModel(modelId);
    }
    try {
        BigdataSailRepositoryConnection connection = repo.getReadOnlyConnection();
        try {
            RepositoryResult<Resource> graphs = connection.getContextIDs();
            if (!Iterations.asSet(graphs).contains(new URIImpl(modelId.toString()))) {
                throw new OWLOntologyCreationException("No such model in datastore: " + modelId);
            }
            graphs.close();
            RepositoryResult<Statement> statements = connection.getStatements(null, null, null, false, new URIImpl(modelId.toString()));
            // setting minimal = false will load the abox with the tbox ontology manager, allowing for OWL understanding of tbox content
            boolean minimal = false;
            OWLOntology abox = loadOntologyDocumentSource(new RioMemoryTripleSource(statements), minimal);
            statements.close();
            abox = postLoadFileFilter(abox);
            ModelContainer model = addModel(modelId, abox);
        } finally {
            connection.close();
        }
    } catch (RepositoryException e) {
        throw new OWLOntologyCreationException(e);
    }
}
Also used : RioMemoryTripleSource(org.semanticweb.owlapi.rio.RioMemoryTripleSource) BigdataSailRepositoryConnection(com.bigdata.rdf.sail.BigdataSailRepositoryConnection) URIImpl(org.openrdf.model.impl.URIImpl) RepositoryException(org.openrdf.repository.RepositoryException)

Example 2 with RioMemoryTripleSource

use of org.semanticweb.owlapi.rio.RioMemoryTripleSource in project minerva by geneontology.

the class CoreMolecularModelManager method loadOWLOntologyDocumentSource.

private static OWLOntology loadOWLOntologyDocumentSource(final OWLOntologyDocumentSource source, final OWLOntologyManager manager) throws OWLOntologyCreationException {
    final OWLOntology ontology;
    if (source instanceof RioMemoryTripleSource) {
        RioParserImpl parser = new RioParserImpl(new RioRDFXMLDocumentFormatFactory());
        ontology = manager.createOntology();
        OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration();
        try {
            parser.parse(source, ontology, config);
        } catch (IOException e) {
            throw new OWLOntologyCreationException(e);
        }
    } else {
        ontology = manager.loadOntologyFromOntologyDocument(source);
    }
    return ontology;
}
Also used : RioParserImpl(org.semanticweb.owlapi.rio.RioParserImpl) RioMemoryTripleSource(org.semanticweb.owlapi.rio.RioMemoryTripleSource) RioRDFXMLDocumentFormatFactory(org.semanticweb.owlapi.formats.RioRDFXMLDocumentFormatFactory) IOException(java.io.IOException)

Example 3 with RioMemoryTripleSource

use of org.semanticweb.owlapi.rio.RioMemoryTripleSource in project minerva by geneontology.

the class BlazegraphMolecularModelManager method loadModelABox.

@Override
public OWLOntology loadModelABox(IRI modelId, OWLOntologyManager manager) throws OWLOntologyCreationException {
    LOG.info("Load model abox: " + modelId + " from database");
    try {
        BigdataSailRepositoryConnection connection = repo.getReadOnlyConnection();
        try {
            // TODO repeated code with loadModel
            RepositoryResult<Resource> graphs = connection.getContextIDs();
            if (!Iterations.asSet(graphs).contains(new URIImpl(modelId.toString()))) {
                throw new OWLOntologyCreationException("No such model in datastore: " + modelId);
            }
            graphs.close();
            RepositoryResult<Statement> statements = connection.getStatements(null, null, null, false, new URIImpl(modelId.toString()));
            // setting minimal to true will give an OWL abox with triples that won't be connected to the tbox, hence e.g. object properties might not be recognized.
            boolean minimal = true;
            OWLOntology abox;
            if (manager == null) {
                abox = loadOntologyDocumentSource(new RioMemoryTripleSource(statements), minimal);
            } else {
                abox = loadOntologyDocumentSource(new RioMemoryTripleSource(statements), minimal, manager);
            }
            statements.close();
            abox = postLoadFileFilter(abox);
            return abox;
        } finally {
            connection.close();
        }
    } catch (RepositoryException e) {
        throw new OWLOntologyCreationException(e);
    }
}
Also used : RioMemoryTripleSource(org.semanticweb.owlapi.rio.RioMemoryTripleSource) BigdataSailRepositoryConnection(com.bigdata.rdf.sail.BigdataSailRepositoryConnection) URIImpl(org.openrdf.model.impl.URIImpl) RepositoryException(org.openrdf.repository.RepositoryException)

Aggregations

RioMemoryTripleSource (org.semanticweb.owlapi.rio.RioMemoryTripleSource)3 BigdataSailRepositoryConnection (com.bigdata.rdf.sail.BigdataSailRepositoryConnection)2 URIImpl (org.openrdf.model.impl.URIImpl)2 RepositoryException (org.openrdf.repository.RepositoryException)2 IOException (java.io.IOException)1 RioRDFXMLDocumentFormatFactory (org.semanticweb.owlapi.formats.RioRDFXMLDocumentFormatFactory)1 RioParserImpl (org.semanticweb.owlapi.rio.RioParserImpl)1