/** * Tr. * * @return the oBO doc */ protected OBODoc tr() { setObodoc(new OBODoc()); preProcess(); tr(getOWLOntology()); // declarations need to be sorted - otherwise there is a risk of id being processed before // altId, which causes spurious clauses. accept(getOWLOntology().axioms(AxiomType.DECLARATION).sorted()); AxiomType.skipDeclarations().forEach(t -> accept(getOWLOntology().axioms(t))); if (!untranslatableAxioms.isEmpty() && !discardUntranslatable) { String axiomString = OwlStringTools.translate(untranslatableAxioms, manager); if (!axiomString.isEmpty()) { Frame headerFrame = getObodoc().getHeaderFrame(); if (headerFrame == null) { headerFrame = new Frame(FrameType.HEADER); getObodoc().setHeaderFrame(headerFrame); } headerFrame.addClause(new Clause(OboFormatTag.TAG_OWL_AXIOMS, axiomString)); } } return getObodoc(); }
/** * Tr object property. * * @param prop the prop * @param tag the tag * @param value the value * @param annotations the annotations * @return true, if successful */ protected boolean trObjectProperty(@Nullable OWLObjectProperty prop, @Nullable String tag, @Nullable String value, Stream<OWLAnnotation> annotations) { if (prop == null || value == null) { return false; } addQualifiers(clause(prop, tag, value), annotations); return true; }
/** * Tr object property. * * @param prop the prop * @param tag the tag * @param value the value * @param annotations the annotations * @return true, if successful */ protected boolean trObjectProperty(@Nullable OWLObjectProperty prop, String tag, @Nullable Boolean value, Stream<OWLAnnotation> annotations) { if (prop == null || value == null) { return false; } Frame f = getTypedefFrame(prop); Clause clause = new Clause(tag); clause.addValue(value); f.addClause(clause); addQualifiers(clause, annotations); return true; }
Collection<OWLAnnotation> qualifiers, Frame frame) { String tagString = owlObjectToTag(prop); OboFormatTag tag = null; if (tagString != null) { if (annVal.isIRI() && FrameType.TERM.equals(frame.getType()) && isMetadataTag(prop)) { String propId = this.getIdentifier(prop); if (propId != null) { Clause clause = new Clause(OboFormatTag.TAG_RELATIONSHIP); clause.addValue(propId); clause.addValue(getIdentifier((IRI) annVal)); addQualifiers(clause, qualifiers.stream()); frame.addClause(clause); return true; return trGenericPropertyValue(prop, annVal, qualifiers.stream(), frame); Object value = getValue(annVal, tagString); if (!value.toString().trim().isEmpty()) { if (tag == OboFormatTag.TAG_ID) { if (!value.equals(frame.getId())) { warn("Conflicting id definitions: 1) " + frame.getId() + " 2)" + value); return false; OBOFormatConstants.headerDateFormat().parseObject(value.toString())); } catch (@SuppressWarnings("unused") ParseException e) { error("Could not parse date string: " + value, true); return false;
boolean isAnnotationProperty = entity.isOWLAnnotationProperty(); Optional<OboAltIdCheckResult> altIdOptional = checkForOboAltId(set); if (altIdOptional.isPresent()) { String currentId = getIdentifier(entity.getIRI()); addAltId(altIdOptional.get().replacedBy, currentId, isClass, isObjectProperty); f = getTermFrame(entity.asOWLClass()); } else if (isObjectProperty) { f = getTypedefFrame(entity.asOWLObjectProperty()); } else if (isAnnotationProperty) { for (OWLAnnotationAssertionAxiom ax : set) { OWLAnnotationProperty prop = ax.getProperty(); String tag = owlObjectToTag(prop); if (OboFormatTag.TAG_IS_METADATA_TAG.getTag().equals(tag)) { f = getTypedefFrame(entity); break; set.forEach(a -> tr(a, f1)); add(f);
if (sub.isBottomEntity() || sub.isTopEntity() || sup.isBottomEntity() || sup .isTopEntity()) { error("SubAnnotationProperties using Top or Bottom entites are not supported in OBO.", false); return; String tagObject = owlObjectToTag(sup); if (OboFormatTag.TAG_SYNONYMTYPEDEF.getTag().equals(tagObject)) { String name = ""; String scope = null; for (OWLAnnotationAssertionAxiom axiom : asList( getOWLOntology().annotationAssertionAxioms(sub.getIRI()))) { String tg = owlObjectToTag(axiom.getProperty()); if (OboFormatTag.TAG_NAME.getTag().equals(tg)) { name = ((OWLLiteral) axiom.getValue()).getLiteral(); } else if (OboFormatTag.TAG_SCOPE.getTag().equals(tg)) { scope = owlObjectToTag(axiom.getValue()); Frame hf = checkNotNull(getObodoc().getHeaderFrame()); assert hf != null; Clause clause = new Clause(OboFormatTag.TAG_SYNONYMTYPEDEF); clause.addValue(getIdentifier(sub)); clause.addValue(name); if (scope != null) { clause.addValue(scope); addQualifiers(clause, ax.annotations()); if (!hf.getClauses().contains(clause)) { hf.addClause(clause);
Set<QualifierValue> qvs = new HashSet<>(); if (sub.isOWLNothing() || sub.isTopEntity() || sup.isTopEntity() || sup.isOWLNothing()) { error(TOP_BOTTOM_NONTRANSLATEABLE, ax, false); return; qvs.add(new QualifierValue("gci_relation", checkNotNull(getIdentifier(p)))); qvs.add(new QualifierValue("gci_filler", checkNotNull(getIdentifier(filler)))); Frame f = getTermFrame((OWLClass) sub); if (sup instanceof OWLClass) { Clause c = new Clause(OboFormatTag.TAG_IS_A.getTag()); c.setValue(checkNotNull(getIdentifier(sup))); c.setQualifierValues(qvs); f.addClause(c); addQualifiers(c, ax.annotations()); } else if (sup instanceof OWLObjectCardinalityRestriction) { OWLClassExpression filler = cardinality.getFiller(); if (filler.isBottomEntity() || filler.isTopEntity()) { error(TOP_BOTTOM_NONTRANSLATEABLE, ax, false); return; String fillerId = getIdentifier(filler); if (fillerId == null) { error(ax, true); return; createRelationshipClauseWithCardinality(cardinality, fillerId, qvs, ax)); } else if (sup instanceof OWLQuantifiedObjectRestriction) {
protected void tr(OWLSubObjectPropertyOfAxiom ax) { OWLObjectPropertyExpression sup = ax.getSuperProperty(); OWLObjectPropertyExpression sub = ax.getSubProperty(); if (sub.isBottomEntity() || sub.isTopEntity() || sup.isBottomEntity() || sup .isTopEntity()) { error("SubProperties using Top or Bottom entites are not supported in OBO.", false); return; } if (sub.isOWLObjectProperty() && sup.isOWLObjectProperty()) { String supId = checkNotNull(getIdentifier(sup)); if (supId.startsWith("owl:")) { return; } Frame f = getTypedefFrame((OWLObjectProperty) sub); Clause clause = new Clause(OboFormatTag.TAG_IS_A, supId); f.addClause(clause); addQualifiers(clause, ax.annotations()); } else { error(ax, true); } }
error("Expected two classes in a disjoin classes axiom.", ax, false); if (ce1.isBottomEntity() || ce1.isTopEntity() || ce2.isBottomEntity() || ce2 .isTopEntity()) { error("Disjoint classes axiom using Top or Bottom entities are not supported.", ax, false); String cls2 = getIdentifier(ce2); if (cls2 == null) { error(ax, true); return; error(ax, false); return; Frame f = getTermFrame(cls1); Clause c = new Clause(OboFormatTag.TAG_DISJOINT_FROM.getTag()); c.setValue(cls2); f.addClause(c); addQualifiers(c, ax.annotations());
String propId = getIdentifier(prop); addQualifiers(clause, qualifiers); if (!shorthand(propId)) { clause.addValue(propId); if (annVal instanceof OWLLiteral) { IRI dataTypeIri = datatype.getIRI(); if (!OWL2Datatype.isBuiltIn(dataTypeIri)) { error("Untranslatable axiom due to unknown data type: " + annVal, true); return false; clause.addValue(getIdentifier((IRI) annVal));
data = doc.getBytes(); } else if (format instanceof OBODocumentFormat && !checkOBO) { OWLAPIOwl2Obo bridge = new OWLAPIOwl2Obo(ontology.getOWLOntologyManager()); OBODoc oboOntology = bridge.convert(ontology); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(baos))) {
/** * Creates the relationship clause with restrictions. * * @param r the r * @param fillerId the filler id * @param qvs the qvs * @param ax the ax * @return the clause */ protected Clause createRelationshipClauseWithRestrictions(OWLQuantifiedObjectRestriction r, String fillerId, Set<QualifierValue> qvs, OWLSubClassOfAxiom ax) { Clause c = new Clause(OboFormatTag.TAG_RELATIONSHIP.getTag()); c.addValue(getIdentifier(r.getProperty())); c.addValue(fillerId); c.setQualifierValues(qvs); addQualifiers(c, ax.annotations()); return c; }
/** * Adds the qualifiers. * * @param c the c * @param qualifiers the qualifiers */ protected static void addQualifiers(Clause c, Stream<OWLAnnotation> qualifiers) { qualifiers.forEach(a -> addQualifiers(c, a)); }
Collection<OWLAnnotation> qualifiers, Frame frame) { String tagString = owlObjectToTag(prop); OboFormatTag tag = null; if (tagString != null) { if (annVal.isIRI() && FrameType.TERM.equals(frame.getType()) && isMetadataTag(prop)) { String propId = this.getIdentifier(prop); if (propId != null) { Clause clause = new Clause(OboFormatTag.TAG_RELATIONSHIP); clause.addValue(propId); clause.addValue(getIdentifier((IRI) annVal)); addQualifiers(clause, qualifiers.stream()); frame.addClause(clause); return true; return trGenericPropertyValue(prop, annVal, qualifiers.stream(), frame); Object value = getValue(annVal, tagString); if (!value.toString().trim().isEmpty()) { if (tag == OboFormatTag.TAG_ID) { if (!value.equals(frame.getId())) { warn("Conflicting id definitions: 1) " + frame.getId() + " 2)" + value); return false; OBOFormatConstants.headerDateFormat().parseObject(value.toString())); } catch (@SuppressWarnings("unused") ParseException e) { error("Could not parse date string: " + value, true); return false;
boolean isAnnotationProperty = entity.isOWLAnnotationProperty(); Optional<OboAltIdCheckResult> altIdOptional = checkForOboAltId(set); if (altIdOptional.isPresent()) { String currentId = getIdentifier(entity.getIRI()); addAltId(altIdOptional.get().replacedBy, currentId, isClass, isObjectProperty); f = getTermFrame(entity.asOWLClass()); } else if (isObjectProperty) { f = getTypedefFrame(entity.asOWLObjectProperty()); } else if (isAnnotationProperty) { for (OWLAnnotationAssertionAxiom ax : set) { OWLAnnotationProperty prop = ax.getProperty(); String tag = owlObjectToTag(prop); if (OboFormatTag.TAG_IS_METADATA_TAG.getTag().equals(tag)) { f = getTypedefFrame(entity); break; set.forEach(a -> tr(a, f1)); add(f);
if (sub.isBottomEntity() || sub.isTopEntity() || sup.isBottomEntity() || sup .isTopEntity()) { error("SubAnnotationProperties using Top or Bottom entites are not supported in OBO.", false); return; String tagObject = owlObjectToTag(sup); if (OboFormatTag.TAG_SYNONYMTYPEDEF.getTag().equals(tagObject)) { String name = ""; String scope = null; for (OWLAnnotationAssertionAxiom axiom : asList( getOWLOntology().annotationAssertionAxioms(sub.getIRI()))) { String tg = owlObjectToTag(axiom.getProperty()); if (OboFormatTag.TAG_NAME.getTag().equals(tg)) { name = ((OWLLiteral) axiom.getValue()).getLiteral(); } else if (OboFormatTag.TAG_SCOPE.getTag().equals(tg)) { scope = owlObjectToTag(axiom.getValue()); Frame hf = checkNotNull(getObodoc().getHeaderFrame()); assert hf != null; Clause clause = new Clause(OboFormatTag.TAG_SYNONYMTYPEDEF); clause.addValue(getIdentifier(sub)); clause.addValue(name); if (scope != null) { clause.addValue(scope); addQualifiers(clause, ax.annotations()); if (!hf.getClauses().contains(clause)) { hf.addClause(clause);
Set<QualifierValue> qvs = new HashSet<>(); if (sub.isOWLNothing() || sub.isTopEntity() || sup.isTopEntity() || sup.isOWLNothing()) { error(TOP_BOTTOM_NONTRANSLATEABLE, ax, false); return; qvs.add(new QualifierValue("gci_relation", checkNotNull(getIdentifier(p)))); qvs.add(new QualifierValue("gci_filler", checkNotNull(getIdentifier(filler)))); Frame f = getTermFrame((OWLClass) sub); if (sup instanceof OWLClass) { Clause c = new Clause(OboFormatTag.TAG_IS_A.getTag()); c.setValue(checkNotNull(getIdentifier(sup))); c.setQualifierValues(qvs); f.addClause(c); addQualifiers(c, ax.annotations()); } else if (sup instanceof OWLObjectCardinalityRestriction) { OWLClassExpression filler = cardinality.getFiller(); if (filler.isBottomEntity() || filler.isTopEntity()) { error(TOP_BOTTOM_NONTRANSLATEABLE, ax, false); return; String fillerId = getIdentifier(filler); if (fillerId == null) { error(ax, true); return; createRelationshipClauseWithCardinality(cardinality, fillerId, qvs, ax)); } else if (sup instanceof OWLQuantifiedObjectRestriction) {
protected void tr(OWLSubObjectPropertyOfAxiom ax) { OWLObjectPropertyExpression sup = ax.getSuperProperty(); OWLObjectPropertyExpression sub = ax.getSubProperty(); if (sub.isBottomEntity() || sub.isTopEntity() || sup.isBottomEntity() || sup .isTopEntity()) { error("SubProperties using Top or Bottom entites are not supported in OBO.", false); return; } if (sub.isOWLObjectProperty() && sup.isOWLObjectProperty()) { String supId = checkNotNull(getIdentifier(sup)); if (supId.startsWith("owl:")) { return; } Frame f = getTypedefFrame((OWLObjectProperty) sub); Clause clause = new Clause(OboFormatTag.TAG_IS_A, supId); f.addClause(clause); addQualifiers(clause, ax.annotations()); } else { error(ax, true); } }
error("Expected two classes in a disjoin classes axiom.", ax, false); if (ce1.isBottomEntity() || ce1.isTopEntity() || ce2.isBottomEntity() || ce2 .isTopEntity()) { error("Disjoint classes axiom using Top or Bottom entities are not supported.", ax, false); String cls2 = getIdentifier(ce2); if (cls2 == null) { error(ax, true); return; error(ax, false); return; Frame f = getTermFrame(cls1); Clause c = new Clause(OboFormatTag.TAG_DISJOINT_FROM.getTag()); c.setValue(cls2); f.addClause(c); addQualifiers(c, ax.annotations());