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