/*** * 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(); }
/** * Requires the annotation, data and object properties to be clearly distinguished * (disjoint sets, according to the OWL semantics) * * Be careful if you are using a T-box bootstrapped from the mapping * * It is NOT assumed that the declared vocabulary contains information on every RDF predicate * used in the mapping. * */ @Override public void validate(MappingWithProvenance mapping, Ontology ontology) throws MappingOntologyMismatchException { ImmutableMultimap<IRI, Datatype> datatypeMap = computeDataTypeMap(ontology.tbox()); for (Map.Entry<IQ, PPMappingAssertionProvenance> entry : mapping.getProvenanceMap().entrySet()) { validateAssertion(entry.getKey(), entry.getValue(), ontology, datatypeMap); } }
/** * Requires the annotation, data and object properties to be clearly distinguished * (disjoint sets, according to the OWL semantics) * * Be careful if you are using a T-box bootstrapped from the mapping * * It is NOT assumed that the declared vocabulary contains information on every RDF predicate * used in the mapping. * */ @Override public void validate(MappingWithProvenance mapping, Ontology ontology) throws MappingOntologyMismatchException { ImmutableMultimap<String, Datatype> datatypeMap = computeDataTypeMap(ontology.tbox()); for (Map.Entry<IntermediateQuery, PPMappingAssertionProvenance> entry : mapping.getProvenanceMap().entrySet()) { validateAssertion(entry.getKey(), entry.getValue(), ontology, datatypeMap); } }
/** * 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); }
@Override public OBDASpecification transform(Mapping mapping, DBMetadata dbMetadata, Optional<Ontology> ontology) { if (ontology.isPresent()) { Mapping factsAsMapping = factConverter.convert(ontology.get().abox(), settings.isOntologyAnnotationQueryingEnabled(), mapping.getMetadata().getUriTemplateMatcher()); Mapping mappingWithFacts = mappingMerger.merge(mapping, factsAsMapping); return createSpecification(mappingWithFacts, dbMetadata, ontology.get().tbox()); } else { ClassifiedTBox emptyTBox = OntologyBuilderImpl.builder(rdfFactory).build().tbox(); return createSpecification(mapping, dbMetadata, emptyTBox); } }
@Override public OBDASpecification transform(Mapping mapping, DBMetadata dbMetadata, Optional<Ontology> ontology) { if (ontology.isPresent()) { Mapping factsAsMapping = factConverter.convert(ontology.get().abox(), mapping.getExecutorRegistry(), settings.isOntologyAnnotationQueryingEnabled(), mapping.getMetadata().getUriTemplateMatcher()); Mapping mappingWithFacts = mappingMerger.merge(mapping, factsAsMapping); return createSpecification(mappingWithFacts, dbMetadata, ontology.get().tbox()); } else { ClassifiedTBox emptyTBox = OntologyBuilderImpl.builder().build().tbox(); return createSpecification(mapping, dbMetadata, emptyTBox); } }
private void checkObjectOrAnnotationProperty(String predicateIRI, PPMappingAssertionProvenance provenance, Ontology ontology) throws MappingOntologyMismatchException { /* * Cannot be a data property (should be either an object or an annotation property) */ if (ontology.tbox().dataProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, DATA_PROPERTY_STR, OBJECT_PROPERTY_STR)); /* * Cannot be a class */ if (ontology.tbox().classes().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, CLASS_STR, OBJECT_PROPERTY_STR)); }
private void checkObjectOrAnnotationProperty(IRI predicateIRI, PPMappingAssertionProvenance provenance, Ontology ontology) throws MappingOntologyMismatchException { /* * Cannot be a data property (should be either an object or an annotation property) */ if (ontology.tbox().dataProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, DATA_PROPERTY_STR, OBJECT_PROPERTY_STR)); /* * Cannot be a class */ if (ontology.tbox().classes().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, CLASS_STR, OBJECT_PROPERTY_STR)); }
/** * 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()); } }
public static OntopSemanticIndexLoader loadRDFGraph(Dataset dataset, Properties properties) throws SemanticIndexException { // Merge default and named graphs to filter duplicates Set<IRI> graphURLs = new HashSet<>(); graphURLs.addAll(dataset.getDefaultGraphs()); graphURLs.addAll(dataset.getNamedGraphs()); OntopModelConfiguration defaultConfiguration = OntopModelConfiguration.defaultBuilder().build(); Injector injector = defaultConfiguration.getInjector(); RDF rdfFactory = injector.getInstance(RDF.class); CollectRDFVocabulary collectVocabulary = new CollectRDFVocabulary(rdfFactory); for (IRI graphURL : graphURLs) { processRDF(collectVocabulary, graphURL); } Ontology vocabulary = collectVocabulary.vb.build(); SIRepository repo = new SIRepository(vocabulary.tbox(), defaultConfiguration.getTermFactory(), defaultConfiguration.getTypeFactory(), injector.getInstance(TargetAtomFactory.class)); Connection connection = repo.createConnection(); // Load the data SemanticIndexRDFHandler insertData = new SemanticIndexRDFHandler(repo, connection, defaultConfiguration.getTypeFactory(), defaultConfiguration.getTermFactory(), injector.getInstance(RDF.class)); for (IRI graphURL : graphURLs) { processRDF(insertData, graphURL); } LOG.info("Inserted {} triples", insertData.count); return new OntopSemanticIndexLoaderImpl(repo, connection, properties, Optional.empty() /* no tbox */); }
private void checkClass(IRI predicateIRI, PPMappingAssertionProvenance provenance, Ontology ontology) throws MappingOntologyMismatchException { /* * Cannot be an object property */ if (ontology.tbox().objectProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, OBJECT_PROPERTY_STR, CLASS_STR)); /* * Cannot be a data property */ else if (ontology.tbox().dataProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, DATA_PROPERTY_STR, CLASS_STR)); /* * Cannot be an annotation property */ if (ontology.annotationProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, ANNOTATION_PROPERTY_STR, DATA_PROPERTY_STR)); }
private void checkClass(String predicateIRI, PPMappingAssertionProvenance provenance, Ontology ontology) throws MappingOntologyMismatchException { /* * Cannot be an object property */ if (ontology.tbox().objectProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, OBJECT_PROPERTY_STR, CLASS_STR)); /* * Cannot be a data property */ else if (ontology.tbox().dataProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, DATA_PROPERTY_STR, CLASS_STR)); /* * Cannot be an annotation property */ if (ontology.annotationProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, ANNOTATION_PROPERTY_STR, DATA_PROPERTY_STR)); }
SIRepository repo = new SIRepository(ontology.tbox(), obdaConfiguration.getTermFactory(), obdaConfiguration.getTypeFactory(), obdaConfiguration.getInjector().getInstance(TargetAtomFactory.class));
if (ontology.tbox().objectProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, OBJECT_PROPERTY_STR, DATA_PROPERTY_STR)); if (ontology.tbox().classes().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, CLASS_STR, DATA_PROPERTY_STR));
if (ontology.tbox().objectProperties().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, OBJECT_PROPERTY_STR, DATA_PROPERTY_STR)); if (ontology.tbox().classes().contains(predicateIRI)) throw new MappingOntologyMismatchException(generatePropertyOrClassConflictMessage(predicateIRI, provenance, CLASS_STR, DATA_PROPERTY_STR));