/** * Retrieve an {@link IRI} by rdfs:label. * * @param label label * @return {@link IRI} or null */ @Nullable protected IRI getIRIByLabel(String label) { for (OWLOntology o : ontologies) { Optional<OWLAnnotationAssertionAxiom> anyMatch = o .axioms(AxiomType.ANNOTATION_ASSERTION).filter( aa -> isMatchingLabel(label, aa.getValue(), aa.getProperty()) && aa .getSubject().isIRI()).findAny(); if (anyMatch.isPresent()) { return (IRI) anyMatch.get().getSubject(); } } 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()); } }
@Override default Stream<?> components() { return Stream.of(getSubject(), getProperty(), getValue(), annotationsAsList()); }
public void visit(OWLAnnotationAssertionAxiom axiom) { hashCode = 47; hashCode = hashCode * MULT + axiom.getSubject().hashCode(); hashCode = hashCode * MULT + axiom.getProperty().hashCode(); hashCode = hashCode * MULT + axiom.getValue().hashCode(); hashCode = hashCode * MULT + axiom.getAnnotations().hashCode(); }
private void tr(OWLAnnotationAssertionAxiom aanAx, Frame frame) { boolean success = tr(aanAx.getProperty(), aanAx.getValue(), aanAx.getAnnotations(), frame); if (!success) { untranslatableAxioms.add(aanAx); } }
@Nonnull public List<OBOXRef> getXRefs(@Nonnull OWLAnnotationAssertionAxiom annotationAssertion) { return annotationAssertion.getAnnotations().stream() .filter(anno -> isXRefProperty(anno.getProperty())) .map(anno -> converter.toXRef(anno, anno.getAnnotations())) .filter(xref -> xref != null) .collect(toList()); }
private void renderUntypedIRIAnnotationAssertions() { Collection<IRI> annotatedIRIs = new HashSet<>(); ontology.axioms(ANNOTATION_ASSERTION).filter(ax -> ax.getSubject().isIRI()) .forEach(ax -> addIfUntyped(ax.getSubject(), annotatedIRIs)); if (!annotatedIRIs.isEmpty()) { writeBanner(ANNOTATED_IRIS_BANNER_TEXT); annotatedIRIs.stream().sorted().forEach(this::renderIRI); } }
/** * Rebuild the underlying cache of deprecated entities using the specified ontologies. * * @param ontologies A stream of ontologies */ public void rebuildCacheFromActiveOntologies(@Nonnull Collection<OWLOntology> ontologies) { logger.debug("[DeprecationCache] Rebuilding deprecated entities cache"); deprecatedEntities.clear(); ontologies.forEach(o -> { o.getReferencingAxioms(owlDeprecatedAnnotationProperty).stream() .filter(ax -> ax instanceof OWLAnnotationAssertionAxiom) .map(ax -> (OWLAnnotationAssertionAxiom) ax) .filter(ax -> ax.getSubject() instanceof IRI) .map(ax -> (IRI) ax.getSubject()) .forEach(deprecatedEntities::add); }); }
@Nullable protected static String handleIAO10001(@Nullable String replacedBy, final Set<OWLAnnotationAssertionAxiom> unrelatedAxioms, OWLAnnotationAssertionAxiom axiom) { OWLAnnotationValue value = axiom.getValue(); Optional<OWLLiteral> asLiteral = value.asLiteral(); if (asLiteral.isPresent()) { return asLiteral.get().getLiteral(); } // fallback: also check for an IRI Optional<IRI> asIRI = value.asIRI(); if (asIRI.isPresent()) { // translate IRI to OBO style ID return getIdentifier(asIRI.get()); } unrelatedAxioms.add(axiom); return replacedBy; }
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") ); }
protected static boolean handleIAO227(boolean isMerged, final Set<OWLAnnotationAssertionAxiom> unrelatedAxioms, OWLAnnotationAssertionAxiom axiom) { OWLAnnotationValue value = axiom.getValue(); Optional<IRI> asIRI = value.asIRI(); if (asIRI.isPresent()) { return Obo2OWLConstants.IRI_IAO_0000227.equals(asIRI.get()); } unrelatedAxioms.add(axiom); return isMerged; }
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 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)); }); }); }
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))); }); }
/** * Retrieve the annotation from an annotation assertion axiom. * * @param axiom axiom * @param p optional annotation property to filter. Null means all. * @return annotations */ public static Stream<OWLAnnotation> annotationObject(OWLAnnotationAssertionAxiom axiom, @Nullable OWLAnnotationProperty p) { if (p == null || axiom.getProperty().equals(p)) { return Stream.of(axiom.getAnnotation()); } return Stream.empty(); }
@Override public Stream<OWLAnnotationAssertionAxiom> getAnnotationAssertionAxioms(@Nonnull IRI subject, @Nonnull OWLAnnotationProperty property) { return rootOntology.getAnnotationAssertionAxioms(subject).stream() .filter(ax -> ax.getProperty().equals(property)); }
@Override @Nullable public String getName(String id) { // convert OBO id to IRI OWLAPIObo2Owl obo2owl = new OWLAPIObo2Owl(ont.getOWLOntologyManager()); IRI iri = obo2owl.oboIdToIRI(id); // look for label of entity List<OWLAnnotationAssertionAxiom> axioms = asList(ont.axioms(OWLAnnotationAssertionAxiom.class, OWLAnnotationSubject.class, iri, Imports.INCLUDED, IN_SUB_POSITION)); for (OWLAnnotationAssertionAxiom axiom : axioms) { if (axiom.getProperty().isLabel()) { OWLAnnotationValue value = axiom.getValue(); if (value instanceof OWLLiteral) { return ((OWLLiteral) value).getLiteral(); } } } return null; }
@Override @Nullable public String getPrefixIRI(IRI iri) { for (OWLAnnotationAssertionAxiom annotation : asList( ontology.annotationAssertionAxioms(iri))) { if (annotation.getProperty().isLabel()) { OWLAnnotationValue value = annotation.getValue(); if (value instanceof OWLLiteral) { return '<' + ((OWLLiteral) value).getLiteral() + '>'; } } } return delegate.getPrefixIRI(iri); }
@Nullable public static String getIdentifierFromObject(OWLObject obj, OWLOntology ont) throws UntranslatableAxiomException { OWLEntity entity = (OWLEntity) obj; for (OWLAnnotationAssertionAxiom ax : asList( ont.annotationAssertionAxioms(entity.getIRI()))) { String propId = getIdentifierFromObject(ax.getProperty().getIRI(), ont); OWLAnnotationValue value = ax.getValue(); if (value instanceof OWLLiteral) { return ((OWLLiteral) value).getLiteral(); return getIdentifier(((OWLEntity) obj).getIRI());
@Override public Set<OWLObject> getOWLObjects(OWLOntology ontology, ErrorListener errorListener) { Set<OWLObject> toReturn = new HashSet<>(); ontology.classesInSignature().forEach(owlClass -> EntitySearcher .getAnnotationAssertionAxioms(owlClass.getIRI(), ontology).forEach(annotationAxiom -> { PatternExtractor patternExtractor = patternModel.getPatternModelFactory().getPatternExtractor(errorListener); OWLAnnotation annotation = annotationAxiom.getAnnotation(); PatternOPPLScript script = annotation.accept(patternExtractor); if (script != null && getName().equals(script.getName())) { toReturn.add(annotationAxiom); } })); return toReturn; }