@Override public void visit(OWLAnnotation node) { sb.append("Annotation("); node.annotations().forEach(a -> { a.accept(this); sb.append(' '); }); node.getProperty().accept(this); sb.append(' '); node.getValue().accept(this); sb.append(')'); }
protected void expandAssertions(OWLOntology o, OWLAnnotationProperty p) { OWLAnnotationProperty ap425 = df.getOWLAnnotationProperty(IRI_IAO_0000425.getIRI()); getAnnotationObjects(p, o.importsClosure(), ap425).map(a -> a.getValue().asLiteral()) .filter(v -> v.isPresent()) .forEach(v -> { String str = v.get().getLiteral(); LOG.info("assertion mapping {} to {}", p, str); expandAssertionToMap.put(p.getIRI(), str); }); }
@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 static String getValueAsLiteralOrURI(OWLAnnotationValue v){ try{ return v.asIRI().get().getIRIString(); }catch(Exception e){ //instead of a resource, it was added as a String return v.asLiteral().get().getLiteral(); } }
.getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_LogicalDefinitionViewRelation); Optional<String> findAny = ontology.annotations().filter(a -> a.getProperty().equals(p)) .map(a -> a.getValue() .asLiteral()).filter(Optional::isPresent).map(x -> x.get().getLiteral()).findAny(); if (!findAny.isPresent()) { return; IRI pIRI = oboIdToIRI(findAny.get()); OWLObjectProperty vp = fac.getOWLObjectProperty(pIRI); Set<OWLAxiom> rmAxioms = new HashSet<>(); Set<OWLAxiom> newAxioms = new HashSet<>(); xs.add(fac.getOWLObjectSomeValuesFrom(vp, x));
return ints.getReferencingAxioms((OWLEntity) owlEntity); } else if (owlEntity instanceof OWLAnonymousIndividual) { return ints.get(OWLAnonymousIndividual.class, OWLAxiom.class).get() .values((OWLAnonymousIndividual) owlEntity, OWLAxiom.class); } else if (owlEntity.isIRI()) { .forEach(e -> OWLAPIStreamUtils.add(axioms, referencingAxioms(e))); axioms(AxiomType.DATA_PROPERTY_ASSERTION) .filter(ax -> OWL2Datatype.XSD_ANY_URI.matches(ax.getObject().getDatatype())) .filter(ax -> ax.getObject().getLiteral().equals(iriString)).forEach(axioms::add); axioms(AxiomType.ANNOTATION_ASSERTION) .forEach(ax -> examineAssertion(owlEntity, axioms, ax)); .forEach(axioms::add); axioms(AxiomType.ANNOTATION_ASSERTION) .filter(ax -> owlEntity.equals(ax.getValue().asLiteral().orElse(null))) .forEach(axioms::add); AxiomType.AXIOM_TYPES.stream().flatMap(this::axioms)
String scopeValue = null; Optional<OWLAnnotation> a = getAnnotationObjects(indv, getOWLOntology(), df.getRDFSLabel()).findFirst(); if (a.isPresent()) { nameValue = '"' + a.get().getValue().asLiteral().get().getLiteral() + '"'; .filter(ann -> !ann.getProperty().equals(df.getRDFSLabel())) .findFirst(); if (a.isPresent()) { scopeValue = a.get().getValue().asLiteral().get().getLiteral(); String nameValue = ""; Optional<OWLAnnotation> value = getAnnotationObjects(indv, getOWLOntology(), df.getRDFSLabel()).findFirst(); if (value.isPresent()) { nameValue = '"' + value.get().getValue().asLiteral().get().getLiteral() + '"';
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; }
/** * @param function function to run if the value is an anonymous individual * @param <T> returned type * @return mapped value for anonymous individuals, empty for non individuals */ default <T> Optional<T> mapAnonymousIndividual(Function<OWLAnonymousIndividual, T> function) { OWLAnnotationValue value = annotationValue(); if (value.isIRI()) { return Optional.ofNullable(function.apply((OWLAnonymousIndividual) value)); } return Optional.empty(); }
/** * @param function function to run if the value is a literal * @param <T> returned type * @return mapped value for literals, empty otherwise */ default <T> Optional<T> mapLiteral(Function<OWLLiteral, T> function) { OWLAnnotationValue value = annotationValue(); if (value.isLiteral()) { return Optional.ofNullable(function.apply((OWLLiteral) value)); } return Optional.empty(); }
/** * Pre process. */ protected void preProcess() { // converse of postProcess in obo2owl String viewRel = null; OWLAnnotationProperty logicalDef = manager.getOWLDataFactory().getOWLAnnotationProperty( Obo2OWLVocabulary.IRI_OIO_LogicalDefinitionViewRelation.getIRI()); List<OWLAnnotation> collect = asList(getOWLOntology().annotations(logicalDef)); for (OWLAnnotation ann : collect) { OWLAnnotationValue v = ann.getValue(); if (v instanceof OWLLiteral) { viewRel = ((OWLLiteral) v).getLiteral(); } else if (v.isIRI()) { viewRel = getIdentifier((IRI) v); } break; } if (viewRel == null) { return; } String view = viewRel; Set<OWLAxiom> rmAxioms = new HashSet<>(); Set<OWLAxiom> newAxioms = new HashSet<>(); getOWLOntology().axioms(AxiomType.EQUIVALENT_CLASSES) .forEach(eca -> preprocessEquivalents(view, rmAxioms, newAxioms, eca)); getOWLOntology().remove(rmAxioms); getOWLOntology().add(newAxioms); }
@Override public void visit(OWLAnnotation node) { write(ANNOTATION); writeOpenBracket(); node.annotations().forEach(this::acceptAndSpace); acceptAndSpace(node.getProperty()); node.getValue().accept(this); writeCloseBracket(); }
protected void examineAssertion(OWLPrimitive owlEntity, Set<OWLAxiom> axioms, OWLAnnotationAssertionAxiom ax) { if (ax.getSubject().equals(owlEntity)) { axioms.add(ax); } else { ax.getValue().asLiteral().ifPresent(lit -> { if (OWL2Datatype.XSD_ANY_URI.matches(lit.getDatatype()) && lit.getLiteral().equals(owlEntity.toString())) { axioms.add(ax); } }); } }
public void visit(OWLAnnotation node) { node.getProperty().accept(this); OWLAnnotationProperty prop = (OWLAnnotationProperty) obj; node.getValue().accept(this); OWLAnnotationValue val = (OWLAnnotationValue) obj; obj = dataFactory.getOWLAnnotation(prop, val); }
@Override public void visit(OWLAnnotationAssertionAxiom axiom) { axiom.getSubject().accept(this); axiom.getProperty().accept(this); axiom.getValue().accept(this); processAxiomAnnotations(axiom); }
/** * Adds the qualifiers. * * @param c the c * @param qualifier the qualifier */ protected static void addQualifiers(Clause c, OWLAnnotation qualifier) { String prop = owlObjectToTag(qualifier.getProperty()); if (prop == null) { prop = qualifier.getProperty().getIRI().toString(); } if (SKIPPED_QUALIFIERS.contains(prop)) { return; } String value = qualifier.getValue().toString(); if (qualifier.getValue() instanceof OWLLiteral) { value = ((OWLLiteral) qualifier.getValue()).getLiteral(); } else if (qualifier.getValue().isIRI()) { value = getIdentifier((IRI) qualifier.getValue()); } QualifierValue qv = new QualifierValue(prop, value); c.addQualifierValue(qv); }
public void visit(@Nonnull OWLAnnotation annotation) { int propStart = builder.mark(); annotation.getProperty().accept(this); int propEnd = builder.mark(); builder.applyStyle(propStart, propEnd, ProtegeStyles.getStyles().getAnnotationPropertyStyle()); renderSpace(); if (annotation.getValue() instanceof OWLLiteral) { OWLLiteral literal = (OWLLiteral) annotation.getValue(); Style langStyle = ProtegeStyles.getStyles().getAnnotationLangStyle(); if (literal.isRDFPlainLiteral()) { if (!literal.getLang().isEmpty()) { builder.appendWithStyle("[language: ", langStyle); builder.appendWithStyle(literal.getLang(), langStyle); builder.appendWithStyle("] ", langStyle); } } else { builder.appendWithStyle("[type: ", langStyle); int dtStart = builder.mark(); literal.getDatatype().accept(this); int dtEnd = builder.mark(); builder.applyStyle(dtStart, dtEnd, langStyle); builder.appendWithStyle("] ", langStyle); } builder.append(literal.getLiteral()); } else { annotation.getValue().accept(this); } }
private void processAnnotationAssertion(OWLOntology ontology, OWLEntity entity, OWLAnnotationAssertionAxiom ax, Pattern pattern, OntologyChangeList.Builder<Boolean> builder) { if (!ax.getValue().isLiteral()) { return; OWLLiteral literal = (OWLLiteral) ax.getValue(); if (!matchesProperty(ax)) { return; Matcher matcher = pattern.matcher(literal.getLiteral()); if(!matcher.find()) { return; OWLLiteral newLiteral; if(newLangTag.isEmpty()) { newLiteral = dataFactory.getOWLLiteral(newLexicalValue, literal.getDatatype()); newLiteral = dataFactory.getOWLLiteral(newLexicalValue, newLangTag); OWLAxiom newAx = dataFactory.getOWLAnnotationAssertionAxiom(newProperty, entity.getIRI(), newLiteral, ax.getAnnotations()); if (newAnnotationData.equals(ax)) { return;
@Nonnull public OBOXRef visit(@Nonnull OWLLiteral literal) { String description = ""; for (OWLAnnotation anno : annoAnnos) { if (anno.getProperty().isLabel()) { description = anno.getValue().accept(new OWLAnnotationValueVisitorEx<String>() { @Nonnull public String visit(@Nonnull org.semanticweb.owlapi.model.IRI iri) { return iri.toString(); } @Nonnull public String visit(@Nonnull OWLAnonymousIndividual individual) { return individual.toString(); } @Nonnull public String visit(@Nonnull OWLLiteral literal) { return literal.getLiteral(); } }); break; } } return oboXRefConverter.toOBOXRef(literal.getLiteral(), description); } });
@SuppressWarnings({"null", "unused"}) @Override public void handle(String currentId, String value, String qualifierBlock, String comment) { if (currentId == null) { return; } OWLAnnotation xrefAnnotation = getConsumer().parseXRef(value); IRI subject = getIRIFromOBOId(currentId); OWLAnnotationAssertionAxiom ax = getDataFactory() .getOWLAnnotationAssertionAxiom(xrefAnnotation.getProperty(), subject, xrefAnnotation.getValue()); applyChange(new AddAxiom(getOntology(), ax)); if (getConsumer().isTypedef() && xrefAnnotation.getValue().isIRI()) { IRI xrefIRI = (IRI) xrefAnnotation.getValue(); String typedefId = getConsumer().getCurrentId(); getConsumer().addSymbolicIdMapping(typedefId, xrefIRI); } } }