protected OWLReasonerBase(OWLOntology rootOntology, OWLReasonerConfiguration configuration, BufferingMode bufferingMode) { this.rootOntology = checkNotNull(rootOntology, "rootOntology cannot be null"); this.bufferingMode = checkNotNull(bufferingMode, "bufferingMode cannot be null"); this.configuration = checkNotNull(configuration, "configuration cannot be null"); timeOut = configuration.getTimeOut(); manager = rootOntology.getOWLOntologyManager(); manager.addOntologyChangeListener(this::handleRawOntologyChanges); reasonerAxioms = asUnorderedSet( rootOntology.importsClosure().flatMap(o -> Stream.concat(o.logicalAxioms(), o .axioms(AxiomType.DECLARATION))) .map(ax -> OWLAxiom.getAxiomWithoutAnnotations(ax))); }
@Override public void setOntologyFormat(OWLOntology ontology, OWLDocumentFormat ontologyFormat) { writeLock.lock(); try { OWLOntologyID ontologyID = ontology.getOntologyID(); ontologyFormatsByOntology.put(ontologyID, ontologyFormat); } finally { writeLock.unlock(); } }
protected static OWLOntology extractDeclarations(OWLOntologyManager manager, OWLOntology ontology) throws OWLOntologyCreationException { IRI ontologyIRI = ontology.getOntologyID().getOntologyIRI().get(); System.err.println("Ontology " + ontologyIRI); Set<OWLDeclarationAxiom> declarationAxioms = ontology.getAxioms(AxiomType.DECLARATION); manager.removeOntology(ontology); OWLOntology newOntology = manager.createOntology(ontologyIRI); manager.addAxioms(newOntology, declarationAxioms); return newOntology; }
public void setOntology(OWLOntology ontology) { this.ontology = ontology; if(ontology != null){ //gets all object properties from the ontology objectProperties = ontology.getObjectPropertiesInSignature(); //gets all data properties from the ontology dataProperties = ontology.getDataPropertiesInSignature(); } }
protected Set<OWLEntity> getEntitiesThatRequireNamespaces() { Set<OWLEntity> result = new HashSet<OWLEntity>(); result.addAll(ontology.getClassesInSignature()); result.addAll(ontology.getObjectPropertiesInSignature()); result.addAll(ontology.getDataPropertiesInSignature()); result.addAll(ontology.getIndividualsInSignature()); result.addAll(ontology.getAnnotationPropertiesInSignature()); return result; }
/** * Checks whether the same IRI denotes both a class and an individual in the ontology. * @param ontology the OWL ontology * @param iri the entity IRI * @return TRUE if the IRI is used as both, class and individual, otherwise FALSE */ public static boolean hasPunning(OWLOntology ontology, IRI iri){ boolean isClass = ontology.getClassesInSignature().contains(ontology.getOWLOntologyManager().getOWLDataFactory().getOWLClass(iri)); boolean isIndividual = ontology.getIndividualsInSignature().contains(ontology.getOWLOntologyManager().getOWLDataFactory().getOWLNamedIndividual(iri)); return isClass && isIndividual; } }
@Nonnull @Override public Stream<OWLClass> getTypes(@Nonnull OWLNamedIndividual individual) { return rootOntology.getImportsClosure() .stream() .flatMap(o -> o.getImportsClosure().stream()) .flatMap(o -> o.getClassAssertionAxioms(individual).stream()) .map(OWLClassAssertionAxiom::getClassExpression) .filter(ce -> !ce.isAnonymous()) .map(OWLClassExpression::asOWLClass); }
private void createEdgesForClass(Set<Edge> edges, Set<OWLEntity> processed, OWLClass cls) { var subClassAxioms = getOntologies().flatMap(o -> o.getSubClassAxiomsForSubClass(cls).stream().sorted()); var equivalentClassesAxioms = getEquivalentClassAxiomsAsSubClassOfAxioms(cls); var combinedAxioms = Streams.concat(subClassAxioms, equivalentClassesAxioms); combinedAxioms .filter(ax -> isNamedClass(ax.getSubClass())) .forEach(ax -> createEdgeForSubClassOfAxiom(cls, ax, edges, processed)); }
private void rebuild() { activeLangs.clear(); Stopwatch stopwatch = Stopwatch.createStarted(); rootOntology.getImportsClosure().stream() .flatMap(ont -> ont.getAxioms(ANNOTATION_ASSERTION).stream()) .filter(ActiveLanguagesManager::isLabellingAnnotation) .forEach(this::addAxiom); stopwatch.stop(); logger.info("{} Extracted {} languages in {} ms", projectId, activeLangs.elementSet().size(), stopwatch.elapsed(MILLISECONDS)); rebuildSortedLanguages(); logSortedLanguages(); }
private void writeDeclarations(OWLEntity entity, Set<OWLAxiom> alreadyWrittenAxioms, Collection<IRI> illegals) { Collection<OWLDeclarationAxiom> axioms = asList(ont.declarationAxioms(entity).sorted()); axioms.stream().filter(alreadyWrittenAxioms::add).forEach(this::acceptAndReturn); // if multiple illegal declarations already exist, they have already // been outputted the renderer cannot take responsibility for removing // them. It should not add declarations for illegally punned entities // here, though if (addMissingDeclarations && axioms.isEmpty() && !entity.isBuiltIn() && !illegals.contains(entity.getIRI()) && !ont.isDeclared(entity, Imports.INCLUDED)) { OWLDeclarationAxiom declaration = ont.getOWLOntologyManager().getOWLDataFactory().getOWLDeclarationAxiom(entity); acceptAndReturn(declaration); } }
private void updateState() { boolean enabled = getOWLModelManager().getActiveOntologies().stream() .filter(o -> !o.getIndividualsInSignature().isEmpty()) .findAny() .isPresent(); setEnabled(enabled); }
@Override public void visit(OWLObjectProperty property) { add(axioms, ontology.axioms(property).filter(this::threewayDisjointObject)); add(axioms, ontology.axioms(SUB_PROPERTY_CHAIN_OF) .filter(ax -> ax.getSuperProperty().equals(property))); OWLObjectInverseOf inverse = ontology.getOWLOntologyManager().getOWLDataFactory() .getOWLObjectInverseOf(property); add(axioms, ontology.axioms(inverse)); }
/** * @param ont ontology to use * @return short form of the ontology IRI */ public String getShortForm(OWLOntology ont) { OWLOntologyID ontologyID = ont.getOntologyID(); if (ontologyID.getOntologyIRI().isPresent()) { return getShortForm(verifyNotNull(ontologyID.getOntologyIRI().get())); } else { return ontologyID.toString(); } }
/** * Instantiates a new definition tracker. * * @param ontology ontology to track */ public DefinitionTracker(OWLOntology ontology) { this.ontology = checkNotNull(ontology, "ontology cannot be null"); ontology.importsClosure().flatMap(OWLOntology::axioms).forEach(this::addAxiom); ontology.getOWLOntologyManager().addOntologyChangeListener(this); }
public List<OWLOntologyChange> getChanges() { Set<OWLIndividual> individuals = ontologies.stream() .flatMap(o -> o.getIndividualsInSignature().stream()) .collect(toSet()); List<OWLOntologyChange> changes = new ArrayList<>(); if (!individuals.isEmpty()) { changes.add(new AddAxiom(ont, dataFactory.getOWLDifferentIndividualsAxiom(individuals))); } return changes; } }
private ImmutableCollection<OWLAnnotationAssertionAxiom> getAxioms(@Nonnull IRI subject) { return axiomsBySubject.get(subject, (iri) -> rootOntology.getImportsClosure().stream() .flatMap(ont -> ont.getAnnotationAssertionAxioms(iri).stream()) .collect(toImmutableList())); }
private void addVersionIRIToOntologyHeader(OWLOntology ontology) { OWLOntologyID ontID = ontology.getOntologyID(); if (ontID.getVersionIRI().isPresent()) { addTriple(ontology, OWL_VERSION_IRI.getIRI(), ontID.getVersionIRI().get()); } }
/** * Gets the versions (if any) of the ontology that have the specified IRI * * @param ontology The ontology IRI * @return The set of ontologies that have the specified ontology IRI. */ default Stream<OWLOntology> versions(IRI ontology) { return ontologies().filter(o -> o.getOntologyID().matchOntology(ontology)); }
/** * @param ontology ontology */ public UseOfReservedVocabularyForOntologyIRI(OWLOntology ontology) { super(ontology, null, ontology.getOntologyID().getOntologyIRI().get()); }
@SuppressWarnings("null") protected AbstractMacroExpansionVisitor(OWLOntology o) { df = o.getOWLOntologyManager().getOWLDataFactory(); expandExpressionMap = new HashMap<>(); expandAssertionToMap = new HashMap<>(); OWLAnnotationProperty ap424 = df.getOWLAnnotationProperty(IRI_IAO_0000424.getIRI()); o.objectPropertiesInSignature() .forEach(p -> getAnnotationObjects(p, o.importsClosure(), ap424).forEach( a -> mapToExpand(p, a))); o.annotationPropertiesInSignature().forEach(p -> expandAssertions(o, p)); OIO_ISEXPANSION = df.getOWLAnnotationProperty( IRI.create(Obo2OWLConstants.OIOVOCAB_IRI_PREFIX, "is_expansion")); expansionMarkerAnnotation = df.getOWLAnnotation(OIO_ISEXPANSION, df.getOWLLiteral(true)); }