/*** * This method loads the given ontologies in the system. This will merge * these new ontologies with the existing ones in a set. Then it will * translate the assertions in all the ontologies into a single one, in our * internal representation. * * The translation is done using our OWLAPITranslator that gets the TBox * part of the ontologies and filters all the DL-Lite axioms (RDFS/OWL2QL * and DL-Lite). * */ private ClassifiedTBox loadOntologies(OWLOntology ontology) { /* * We will keep track of the loaded ontologies and translate the TBox * part of them into our internal representation. */ log.debug("Load ontologies called. Translating ontologies."); Ontology mergeOntology = owlapiTranslator.translateAndClassify(ontology); return mergeOntology.tbox(); }
public AnnotationAssertion translate(OWLAnnotationAssertionAxiom ax, OntologyVocabularyCategory<AnnotationProperty> annotationProperties) throws TranslationException, InconsistentOntologyException { IRIConstant c1 = getIndividual(ax.getSubject()); Constant c2 = getValue(ax.getValue()); AnnotationProperty ap = getPropertyExpression(ax.getProperty(), annotationProperties); return OntologyBuilderImpl.createAnnotationAssertion(ap, c1, c2); }
public ClassAssertion translate(OWLClassAssertionAxiom ax, OntologyVocabularyCategory<OClass> classes) throws TranslationException, InconsistentOntologyException { OWLClassExpression classExpression = ax.getClassExpression(); if (!(classExpression instanceof OWLClass)) throw new OWLAPITranslatorOWL2QL.TranslationException("complex class expressions are not supported"); OClass concept = getOClass((OWLClass) classExpression, classes); IRIConstant c = getIndividual(ax.getIndividual()); return OntologyBuilderImpl.createClassAssertion(concept, c); }
public ObjectPropertyAssertion translate(OWLObjectPropertyAssertionAxiom ax, OntologyVocabularyCategory<ObjectPropertyExpression> objectProperties) throws TranslationException, InconsistentOntologyException { IRIConstant c1 = getIndividual(ax.getSubject()); IRIConstant c2 = getIndividual(ax.getObject()); ObjectPropertyExpression ope = getPropertyExpression(ax.getProperty(), objectProperties); return OntologyBuilderImpl.createObjectPropertyAssertion(ope, c1, c2); }
public DataPropertyAssertion translate(OWLDataPropertyAssertionAxiom ax, OntologyVocabularyCategory<DataPropertyExpression> dataProperties) throws TranslationException, InconsistentOntologyException { IRIConstant c1 = getIndividual(ax.getSubject()); ValueConstant c2 = getValueOfLiteral(ax.getObject()); DataPropertyExpression dpe = getPropertyExpression(ax.getProperty(), dataProperties); return OntologyBuilderImpl.createDataPropertyAssertion(dpe, c1, c2); }
/** * Include all imports and load then into a single translated merge. * * @param owl * @return */ public Ontology translateAndClassify(OWLOntology owl) { Set<OWLOntology> owls = owl.getOWLOntologyManager().getImportsClosure(owl); log.debug("Load ontologies called. Translating {} ontologies.", owls.size()); OntologyBuilder builder = OntologyBuilderImpl.builder(rdfFactory); for (OWLOntology o : owls) { extractOntoloyVocabulary(o, builder); } for (OWLOntology o : owls) { OWLAxiomVisitorImpl visitor = new OWLAxiomVisitorImpl(o, builder); for (OWLAxiom axiom : o.getAxioms()) { axiom.accept(visitor); } } Ontology onto = builder.build(); log.debug("Ontology loaded: {}", onto); return onto; }
private Constant getValue(OWLAnnotationValue value) throws TranslationException { try { if (value instanceof IRI) { return termFactory.getConstantIRI(rdfFactory.createIRI(value.asIRI().get().toString())); } else if (value instanceof OWLLiteral) { return getValueOfLiteral(value.asLiteral().get()); } else throw new OWLAPITranslatorOWL2QL.TranslationException("Found anonymous individual, this feature is not supported:" + value); } catch (OWLRuntimeException ore) { throw new OWLAPITranslatorOWL2QL.TranslationException(ore.getMessage()); } }
Optional<Ontology> loadOntology() throws OntologyException { OWLAPITranslatorOWL2QL translator = getInjector().getInstance(OWLAPITranslatorOWL2QL.class); try { return loadInputOntology() .map(o -> translator.translateAndClassify(o)); } catch (OWLOntologyCreationException e) { throw new OntologyException(e.getMessage()); } }
/** * Methods to get the empty concepts and roles in the ontology using the given mappings. * It generates SPARQL queries to check for entities. * @return QuestOWLEmptyEntitiesChecker class to get empty concepts and roles * @throws Exception */ public QuestOWLEmptyEntitiesChecker getEmptyEntitiesChecker() throws Exception { OWLOntology rootOntology = getRootOntology(); Ontology mergeOntology = owlapiTranslator.translateAndClassify(rootOntology); ClassifiedTBox tBox = mergeOntology.tbox(); return new QuestOWLEmptyEntitiesChecker(tBox, owlConnection); }
/** * High-level method */ public static OntopSemanticIndexLoader loadOntologyIndividuals(OWLOntology owlOntology, Properties properties) throws SemanticIndexException { OntopModelConfiguration defaultConfiguration = OntopModelConfiguration.defaultBuilder().build(); OWLAPITranslatorOWL2QL translatorOWL2QL = defaultConfiguration.getInjector().getInstance(OWLAPITranslatorOWL2QL.class); Ontology ontology = translatorOWL2QL.translateAndClassify(owlOntology); SIRepository repo = new SIRepository(ontology.tbox(), defaultConfiguration.getTermFactory(), defaultConfiguration.getTypeFactory(), defaultConfiguration.getInjector().getInstance(TargetAtomFactory.class) ); try { Connection connection = repo.createConnection(); // load the data Set<OWLOntology> ontologyClosure = owlOntology.getOWLOntologyManager().getImportsClosure(owlOntology); OWLAPIABoxIterator aBoxIter = new OWLAPIABoxIterator(ontologyClosure, ontology.tbox(), translatorOWL2QL); int count = repo.insertData(connection, aBoxIter); LOG.debug("Inserted {} triples from the ontology.", count); return new OntopSemanticIndexLoaderImpl(repo, connection, properties, Optional.of(extractTBox(owlOntology))); } catch (SQLException e) { throw new SemanticIndexException(e.getMessage()); } }
Ontology ontology = translatorOWL2QL.translateAndClassify(inputOntology); SIRepository repo = new SIRepository(ontology.tbox(), obdaConfiguration.getTermFactory(), obdaConfiguration.getTypeFactory(),