public boolean contains(OWLObjectProperty prop) { if (prop.equals(owlOntologyManager.getOWLDataFactory().getOWLThing())) { return true; } else if (prop.equals(owlOntologyManager.getOWLDataFactory().getOWLNothing())) { return true; } return owlObjectProperty2ObjectPropertyPointerMap.containsKey(prop); }
private void runWithSeparateFiles() { if (owlFile == null) { throw new NullPointerException("You have to specify an ontology file!"); } OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = null; OBDADataFactory obdaDataFactory = OBDADataFactoryImpl.getInstance(); try { ontology = manager.loadOntologyFromOntologyDocument((new File(owlFile))); if (disableReasoning) { /* * when reasoning is disabled, we extract only the declaration assertions for the vocabulary */ ontology = extractDeclarations(manager, ontology); } Collection<Predicate> predicates = new ArrayList<>(); for (OWLClass owlClass : ontology.getClassesInSignature()) { Predicate predicate = obdaDataFactory.getClassPredicate(owlClass.getIRI().toString()); predicates.add(predicate); } for (OWLDataProperty owlDataProperty : ontology.getDataPropertiesInSignature()) { Predicate predicate = obdaDataFactory.getDataPropertyPredicate(owlDataProperty.getIRI().toString()); predicates.add(predicate); } for (OWLObjectProperty owlObjectProperty : ontology.getObjectPropertiesInSignature()) { Predicate predicate = obdaDataFactory.getObjectPropertyPredicate(owlObjectProperty.getIRI().toString()); predicates.add(predicate); } OBDAModel obdaModel = loadMappingFile(mappingFile); Ontology inputOntology = OWLAPI3TranslatorUtility.translate(ontology); obdaModel.declareAll(inputOntology.getVocabulary()); int numPredicates = predicates.size(); int i = 1; for (Predicate predicate : predicates) { System.err.println(String.format("Materializing %s (%d/%d)", predicate, i, numPredicates)); serializePredicate(ontology, inputOntology, obdaModel, predicate, outputFile, format); i++; } } catch (OWLOntologyCreationException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
private Iterable<Concept> getDomainsConcepts(OWLOntology o, OWLObjectProperty objectProperty) { String uri = objectProperty.getIRI().toString(); if (objectProperty.getDomains(o).size() == 0) { throw new LumifyException("Invalid number of domain properties on " + uri); } List<Concept> domains = new ArrayList<Concept>(); for (OWLClassExpression rangeClassExpr : objectProperty.getDomains(o)) { OWLClass rangeClass = rangeClassExpr.asOWLClass(); String rangeClassUri = rangeClass.getIRI().toString(); Concept ontologyClass = getConceptByIRI(rangeClassUri); checkNotNull(ontologyClass, "Could not find class with uri: " + rangeClassUri); domains.add(ontologyClass); } return domains; }
protected void importInverseOf(OWLOntology o, OWLObjectProperty objectProperty) { String iri = objectProperty.getIRI().toString(); Relationship fromRelationship = null; for (OWLObjectPropertyExpression inverseOf : objectProperty.getInverses(o)) { if (inverseOf instanceof OWLObjectProperty) { if (fromRelationship == null) { fromRelationship = getRelationshipByIRI(iri); } OWLObjectProperty inverseOfOWLObjectProperty = (OWLObjectProperty) inverseOf; String inverseOfIri = inverseOfOWLObjectProperty.getIRI().toString(); Relationship inverseOfRelationship = getRelationshipByIRI(inverseOfIri); getOrCreateInverseOfRelationship(fromRelationship, inverseOfRelationship); } } }
protected void importObjectProperty(OWLOntology o, OWLObjectProperty objectProperty) { String iri = objectProperty.getIRI().toString(); String label = getLabel(o, objectProperty); checkNotNull(label, "label cannot be null or empty for " + iri); LOGGER.info("Importing ontology object property " + iri + " (label: " + label + ")"); for (Concept domain : getDomainsConcepts(o, objectProperty)) { for (Concept range : getRangesConcepts(o, objectProperty)) { getOrCreateRelationshipType(domain, range, iri, label); } } }
/** * Gets the property by given name, e.g. has_topping * * @param propName * @return */ public OWLObjectProperty getNamedObjectProperty(String propName) { if (objPropNameCache == null) { objPropNameCache = new HashMap<String, URI>(); for (OWLOntology ont : reasoner.getLoadedOntologies()) { for (OWLObjectProperty prop : ont.getReferencedObjectProperties()) { objPropNameCache.put(prop.toString(), prop.getURI()); } } } // search the HashMap OWLObjectProperty namedProp = null; URI uri = objPropNameCache.get(propName); if (uri != null) { namedProp = manager.getOWLDataFactory().getOWLObjectProperty(uri); } else { System.err.println("Cannot find object property: " + propName + " in loaded ontologies"); } return namedProp; }
public void visit(OWLObjectProperty owlObjectProperty) { try { lastObjectPropertyPointer = owlObjectProperty2ObjectPropertyPointerMap.get(owlObjectProperty); if (lastObjectPropertyPointer == null) { lastObjectPropertyPointer = faCTPlusPlus.getObjectProperty(owlObjectProperty.getURI().toString()); objectPropertyPointerMap.put(lastObjectPropertyPointer, owlObjectProperty); owlObjectProperty2ObjectPropertyPointerMap.put( owlObjectProperty, lastObjectPropertyPointer); } } catch (Exception e) { throw new FaCTPlusPlusRuntimeException(e); } }