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); } }
protected Stream<? extends OWLAxiom> getAxioms(OWLEntity entity) { if (entity.isOWLClass()) { return getOntology().axioms(entity.asOWLClass()); } if (entity.isOWLObjectProperty()) { return getOntology().axioms(entity.asOWLObjectProperty()); } if (entity.isOWLDataProperty()) { return getOntology().axioms(entity.asOWLDataProperty()); } if (entity.isOWLNamedIndividual()) { return getOntology().axioms(entity.asOWLNamedIndividual()); } return empty(); }
@Override public OWLClass getOWLClass(String name) { for (OWLEntity ent : shortFormProvider.getEntities(name)) { if (ent.isOWLClass()) { return ent.asOWLClass(); } } return null; }
@Override public OWLObjectProperty getOWLObjectProperty(String name) { for (OWLEntity ent : shortFormProvider.getEntities(name)) { if (ent.isOWLObjectProperty()) { return ent.asOWLObjectProperty(); } } return null; }
@Nonnull public List<OBOXRef> getXRefs(@Nonnull OWLEntity term) { return rootOntology.getAnnotationAssertionAxioms(term.getIRI()).stream() .filter(ax -> isXRefProperty(ax.getProperty())) .map(ax -> converter.toXRef(ax.getAnnotation(), ax.getAnnotations())) .collect(toList()); } }
public void setXRefs(UserId userId, OWLEntity term, List<OBOXRef> xrefs) { IRI subject = term.getIRI(); Set<OWLAnnotation> annotations = xrefs.stream() .map(annotationToXRefConverter::toAnnotation) .collect(Collectors.toSet()); List<OWLOntologyChange> changes = new ArrayList<>(); // Remove OLD for (OWLAnnotationAssertionAxiom ax : rootOntology.getAnnotationAssertionAxioms(subject)) { if (isXRefProperty(ax.getProperty())) { changes.add(new RemoveAxiom(rootOntology, ax)); } } // Add NEW for (OWLAnnotation annotation : annotations) { changes.add(new AddAxiom(rootOntology, dataFactory.getOWLAnnotationAssertionAxiom(subject, annotation))); } changeManager.applyChanges(userId, new FixedChangeListGenerator<>(changes, term, "Edited term XRefs") ); }
@Override protected ChangeListGenerator<Boolean> getChangeListGenerator(MoveEntitiesToParentAction action, ExecutionContext executionContext) { if(action.getEntity().isOWLClass()) { ImmutableSet<OWLClass> clses = action.getEntities().stream().map(OWLEntity::asOWLClass).collect(toImmutableSet()); return factory.create(clses, action.getEntity().asOWLClass(), action.getCommitMessage()); } return null; }
@NonNull private Set<@NonNull OWLDeclarationAxiom> getOWLClassDeclarationAxioms() { return getOWLOntology().getAxioms(AxiomType.DECLARATION, Imports.INCLUDED).stream() .filter(owlDeclarationAxiom -> owlDeclarationAxiom.getEntity().isOWLClass()).collect(Collectors.toSet()); }
@NonNull private Set<@NonNull OWLDeclarationAxiom> getOWLIndividualDeclarationAxioms() { return getOWLOntology().getAxioms(AxiomType.DECLARATION, Imports.INCLUDED).stream() .filter(owlDeclarationAxiom -> owlDeclarationAxiom.getEntity().isOWLNamedIndividual()) .collect(Collectors.toSet()); }
@NonNull private Set<@NonNull OWLDeclarationAxiom> getOWLObjectPropertyDeclarationAxioms() { return getOWLOntology().getAxioms(AxiomType.DECLARATION, Imports.INCLUDED).stream() .filter(owlDeclarationAxiom -> owlDeclarationAxiom.getEntity().isOWLObjectProperty()).collect(Collectors.toSet()); }
@NonNull private Set<@NonNull OWLDeclarationAxiom> getOWLDataPropertyDeclarationAxioms() { return getOWLOntology().getAxioms(AxiomType.DECLARATION, Imports.INCLUDED).stream() .filter(owlDeclarationAxiom -> owlDeclarationAxiom.getEntity().isOWLDataProperty()).collect(Collectors.toSet()); }
/** * Writes of the annotation for the specified entity. * * @param entity The entity * @param alreadyWrittenAxioms already written axioms, to be updated with the newly written * axioms */ protected void writeAnnotations(OWLEntity entity, Set<OWLAxiom> alreadyWrittenAxioms) { ont.annotationAssertionAxioms(entity.getIRI()).sorted().filter(alreadyWrittenAxioms::add) .forEach(this::acceptAndReturn); }
/** * Retrieve the {@link OWLNamedIndividual} for a given {@link IRI}, if * it has at least one corresponding {@link OWLDeclarationAxiom}. * * @param iri iri * @return {@link OWLNamedIndividual} or null */ @Nullable protected OWLNamedIndividual getOWLIndividual(IRI iri) { for (OWLOntology o : ontologies) { OWLNamedIndividual c = o.getOWLOntologyManager().getOWLDataFactory() .getOWLNamedIndividual(iri); Optional<OWLDeclarationAxiom> found = o.declarationAxioms(c) .filter(da -> da.getEntity() .isOWLNamedIndividual()).findAny(); if (found.isPresent()) { return found.get().getEntity().asOWLNamedIndividual(); } } return null; }
public void update(@Nonnull Dictionary dictionary, @Nonnull Collection<OWLEntity> entities) { checkNotNull(entities).forEach(entity -> { dictionary.remove(entity); if (dictionary.getLanguage().isAnnotationBased()) { rootOntology.getImportsClosure().stream() .flatMap(ont -> ont.getAnnotationAssertionAxioms(entity.getIRI()).stream()) .filter(ax -> isAxiomForDictionary(ax, dictionary)) .forEach(ax -> { OWLLiteral literal = (OWLLiteral) ax.getValue(); String lexicalValue = literal.getLiteral(); dictionary.put(entity, lexicalValue); }); } else { String localName = extractor.getLocalName(entity.getIRI()); dictionary.put(entity, localName); } }); }
private void updateDeprecatedEntityAnnotations(@Nonnull List<OWLOntologyChange> changes) { if (!profile.shouldRemoveAnnotationAssertions()) { logger.info("[Deprecate Entity] Annotation assertions left intact"); return; } ontologies.forEach(o -> { o.getAnnotationAssertionAxioms(info.getEntityToDeprecate().getIRI()).stream() .filter(ax -> { Set<IRI> preservedAnnotationValuePropertiesIris = profile.getPreservedAnnotationValuePropertiesIris(); return !preservedAnnotationValuePropertiesIris.contains(ax.getProperty().getIRI()); }) .forEach(ax -> changes.add(new RemoveAxiom(o, ax))); }); }
private void replaceAnnotationAssertions(@Nonnull List<OWLOntologyChange> changes, @Nonnull Set<IRI> propertyIris, @Nonnull String replacement) { ontologies.forEach(o -> { IRI entityIri = info.getEntityToDeprecate().getIRI(); o.getAnnotationAssertionAxioms(entityIri).stream() .filter(ax -> propertyIris.contains(ax.getProperty().getIRI())) .filter(ax -> ax.getValue().asLiteral().isPresent()) .forEach(ax -> { changes.add(new RemoveAxiom(o, ax)); OWLLiteral currentLiteral = ax.getValue().asLiteral().get(); OWLLiteral replacementLiteral = new LiteralLexicalValueReplacer(dataFactory).replaceLexicalValue( currentLiteral, replacement); OWLAxiom replacementAx = dataFactory.getOWLAnnotationAssertionAxiom( ax.getProperty(), ax.getSubject(), replacementLiteral, ax.getAnnotations()); changes.add(new AddAxiom(o, replacementAx)); }); }); }
/** * @return entities with invalid qnames */ public Set<OWLEntity> getEntitiesWithInvalidQNames() { return asUnorderedSet( getEntitiesThatRequireNamespaces().stream().filter(e -> !e.getIRI().getRemainder() .isPresent())); } }