private boolean trObjectProperty(OWLObjectProperty prop, String tag, Boolean value, Set<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; }
private void tr(OWLObjectPropertyDomainAxiom ax){ final OWLClassExpression domain = ax.getDomain(); OWLObjectPropertyExpression propEx = ax.getProperty(); if (propEx.isAnonymous()) { error(ax); return; } OWLObjectProperty prop = propEx.asOWLObjectProperty(); if (domain.isBottomEntity() || domain.isTopEntity()) { // at least get the type def frame getTypedefFrame(prop); // now throw the error error("domains using top or bottom entities are not translatable to OBO.", ax); return; } String range = this.getIdentifier(domain); if(range != null){ if( trObjectProperty(prop, OboFormatTag.TAG_DOMAIN.getTag(), range, ax.getAnnotations()) ){ return; } } error(ax); }
/** * Join clauses and its {@link QualifierValue} which have the same * relationship type and target. Try to resolve conflicts for multiple * statements. E.g., min=2 and min=3 is resolved to min=2, or max=2 and max=4 * is resolved to max=4. It will not merge conflicting exact cardinality statements. * * TODO How to merge "all_some", and "all_only"? * * @param clauses * @return normalized list of {@link Clause} */ public static List<Clause> normalizeRelationshipClauses(List<Clause> clauses) { final List<Clause> normalized = new ArrayList<Clause>(); while (!clauses.isEmpty()) { final Clause target = clauses.remove(0); List<Clause> similar = findSimilarClauses(clauses, target); normalized.add(target); mergeSimilarIntoTarget(target, similar); } return normalized; }
public String getIdentifier(OWLObject obj) { try { return getIdentifierFromObject(obj, owlOntology); } catch (UntranslatableAxiomException e) { error(e.getMessage()); } return null; }
private void tr(OWLFunctionalObjectPropertyAxiom ax){ OWLObjectPropertyExpression prop = ax.getProperty(); if(prop instanceof OWLObjectProperty){ if( trObjectProperty((OWLObjectProperty)prop, OboFormatTag.TAG_IS_FUNCTIONAL.getTag(), Boolean.TRUE, ax.getAnnotations()) ) { return; } } error(ax); }
String tagString = owlObjectToTag(prop); String synonymType = null; if (tagString == null) { OWLAnnotationProperty subProperty = axiom.getSubProperty(); if (prop.equals(subProperty)) { synonymType = getIdentifier(prop.getIRI()); tagString = OboFormatTag.TAG_SYNONYM.getTag(); break; return trGenericPropertyValue(prop, annVal, qualifiers, frame); String value = getValue(annVal, tagString); OboFormatTag tag = OBOFormatConstants.getTag(tagString); if(tag == null){ Clause clause = new Clause(OboFormatTag.TAG_PROPERTY_VALUE); String propId = this.getIdentifier(prop); addQualifiers(clause, qualifiers); if (propId.equals("shorthand") == false) { clause.addValue(propId); if (tag == OboFormatTag.TAG_ID) { if (frame.getId().equals(value) == false) { error("Conflicting id definitions: 1) "+frame.getId()+" 2)"+value); return false; clause.addValue(OBOFormatConstants.headerDateFormat.get().parseObject(value)); } catch (ParseException e) { error("Could not parse date string: "+value);
private void tr(OWLSubObjectPropertyOfAxiom ax){ OWLObjectPropertyExpression sup = ax.getSuperProperty(); OWLObjectPropertyExpression sub = ax.getSubProperty(); if (sub.isBottomEntity() || sub.isTopEntity() || sup.isBottomEntity() || sub.isTopEntity()) { error("SubProperties using Top or Bottom entites are not supported in OBO."); return; } if(sub instanceof OWLObjectProperty && sup instanceof OWLObjectProperty){ String supId = this.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.getAnnotations()); }else{ error(ax); } }
error("Assertions using owl:Thing or owl:Nothing are not translateable OBO", ax); return; qvs.add(new QualifierValue("gci_relation",getIdentifier(p))); qvs.add(new QualifierValue("gci_filler",getIdentifier(filler))); Frame f = getTermFrame((OWLClass) sub); c.setValue(this.getIdentifier(sup)); c.setQualifierValues(qvs); f.addClause(c); addQualifiers(c, ax.getAnnotations()); } else if (sup instanceof OWLQuantifiedObjectRestriction) { final OWLClassExpression filler = r.getFiller(); if (filler.isBottomEntity() || filler.isTopEntity()) { error("Assertions using owl:Thing or owl:Nothing are not translateable OBO", ax); return; String fillerId = this.getIdentifier(filler); error(ax); return; f.addClause(createRelationshipClauseWithRestrictions(r, fillerId, qvs, ax)); } else if (sup instanceof OWLObjectCardinalityRestriction) { final OWLClassExpression filler = cardinality.getFiller();
f= getTermFrame(entity.asOWLClass()); } else if (entity instanceof OWLObjectProperty) { f = getTypedefFrame(entity.asOWLObjectProperty()); }else if (entity instanceof OWLAnnotationProperty){ String tag = owlObjectToTag(prop); if(OboFormatTag.TAG_IS_METADATA_TAG.getTag().equals(tag)){ f = getTypedefFrame(entity); break; tr(aanAx, f); add(f); return;
private void tr(OWLDisjointClassesAxiom ax) { // use set, the OWL-API does not provide an order Set<OWLClassExpression> set = ax.getClassExpressions(); if (set.size() != 2) { error("Expected two classes in a disjoin classes axiom.", ax); } Iterator<OWLClassExpression> it = set.iterator(); OWLClassExpression ce1 = it.next(); OWLClassExpression ce2 = it.next(); if (ce1.isBottomEntity() || ce1.isTopEntity() || ce2.isBottomEntity() || ce2.isTopEntity()) { error("Disjoint classes axiom using Top or Bottom entities are not supported.", ax); } String cls2 = this.getIdentifier(ce2); if(cls2 == null){ error(ax); return; } if (ce1.isAnonymous()) { error(ax); return; } OWLClass cls1 = ce1.asOWLClass(); Frame f = getTermFrame(cls1); Clause c = new Clause(); c.setTag(OboFormatTag.TAG_DISJOINT_FROM.getTag()); c.setValue(cls2); f.addClause(c); addQualifiers(c, ax.getAnnotations()); }
String ontologyId = Owl2Obo.getOntologyId(ontology); if(outputFile == null){ gciFile = new File(config.outputdir.getValue(), ontologyId+ "-aux.owl").getAbsolutePath(); Owl2Obo bridge = new Owl2Obo(manager); bridge.setStrictConversion(config.strictConversion.getValue()); OBODoc doc = bridge.convert(ontology); outputFilePath = Owl2Obo.getOntologyId(ontology) + ".obo"; Collection<OWLAxiom> untranslatableAxioms = bridge.getUntranslatableAxioms(); if (untranslatableAxiomsFile != null && untranslatableAxioms != null && !untranslatableAxioms.isEmpty()) { writeUntranslatableAxioms(untranslatableAxiomsFile,
String propId = this.getIdentifier(prop); addQualifiers(clause, qualifiers); if (propId.equals("shorthand") == false) { clause.addValue(propId); IRI dataTypeIri = datatype.getIRI(); if (!OWL2Datatype.isBuiltIn(dataTypeIri)) { error("Untranslatable axiom due to unknown data type: "+annVal); return false; clause.addValue(getIdentifierUsingBaseOntology((IRI)annVal));
String id = getOntologyId(owlOntology); f.addClause(c); String vid = getDataVersion(owlOntology); if (vid != null) { Clause c2 = new Clause(); String tagString = owlObjectToTag(property); if (OboFormatTag.TAG_COMMENT.getTag().equals(tagString)) { property = fac.getOWLAnnotationProperty(Obo2Owl.trTagToIRI(OboFormatTag.TAG_REMARK.getTag())); tr(property, ann.getValue(), ann.getAnnotations(), f);
private void tr(OWLInverseObjectPropertiesAxiom ax){ OWLObjectPropertyExpression prop1 = ax.getFirstProperty(); OWLObjectPropertyExpression prop2 = ax.getSecondProperty(); if(prop1 instanceof OWLObjectProperty && prop2 instanceof OWLObjectProperty){ if( trObjectProperty((OWLObjectProperty)prop1, OboFormatTag.TAG_INVERSE_OF.getTag(), this.getIdentifier(prop2), ax.getAnnotations()) ) { return; } } error(ax); }
preProcess(owlOntology); tr(owlOntology); tr((OWLDeclarationAxiom) ax); } else if (ax instanceof OWLSubClassOfAxiom) { tr((OWLSubClassOfAxiom) ax); } else if (ax instanceof OWLDisjointClassesAxiom) { tr((OWLDisjointClassesAxiom) ax); } else if (ax instanceof OWLEquivalentClassesAxiom) { tr((OWLEquivalentClassesAxiom) ax); }else if (ax instanceof OWLClassAssertionAxiom){ tr((OWLClassAssertionAxiom)ax); }else if(ax instanceof OWLEquivalentObjectPropertiesAxiom) { tr((OWLEquivalentObjectPropertiesAxiom)ax); }else if(ax instanceof OWLSubAnnotationPropertyOfAxiom){ tr((OWLSubAnnotationPropertyOfAxiom)ax); }else if(ax instanceof OWLSubObjectPropertyOfAxiom){ tr((OWLSubObjectPropertyOfAxiom)ax); }else if(ax instanceof OWLObjectPropertyRangeAxiom){ tr((OWLObjectPropertyRangeAxiom)ax); }else if (ax instanceof OWLFunctionalObjectPropertyAxiom){ tr((OWLFunctionalObjectPropertyAxiom)ax); }else if(ax instanceof OWLSymmetricObjectPropertyAxiom){ tr((OWLSymmetricObjectPropertyAxiom)ax); }else if (ax instanceof OWLAsymmetricObjectPropertyAxiom){ tr((OWLAsymmetricObjectPropertyAxiom)ax); }else if(ax instanceof OWLObjectPropertyDomainAxiom){ tr((OWLObjectPropertyDomainAxiom)ax); }else if(ax instanceof OWLInverseFunctionalObjectPropertyAxiom){
Owl2Obo bridge = new Owl2Obo(manager); bridge.setStrictConversion(config.strictConversion.getValue()); OBODoc doc = bridge.convert(ontology); obodocs.add(doc);
private Clause createRelationshipClauseWithRestrictions( OWLQuantifiedObjectRestriction r, String fillerId, Set<QualifierValue> qvs, OWLSubClassOfAxiom ax) { Clause c = new Clause(); c.setTag(OboFormatTag.TAG_RELATIONSHIP.getTag()); c.addValue(this.getIdentifier(r.getProperty())); c.addValue(fillerId); c.setQualifierValues(qvs); addQualifiers(c, ax.getAnnotations()); return c; }
public void render(OWLOntology ontology, Writer writer) throws OWLOntologyStorageException { try { Owl2Obo translator = new Owl2Obo(ontology.getOWLOntologyManager()); OBODoc result = translator.convert(ontology); new OBOFormatWriter().write(result, new BufferedWriter(writer)); } catch (IOException e) { throw new OWLOntologyStorageException(e); } catch (OWLOntologyCreationException e) { throw new OWLOntologyStorageException(e); } } }
private Frame getTypedefFrame(OWLEntity entity){ String id = this.getIdentifier(entity); Frame f = obodoc.getTypedefFrame(id); if (f == null) { f = new Frame(FrameType.TYPEDEF); f.setId(id); f.addClause(new Clause(OboFormatTag.TAG_ID, id)); add(f); } return f; }
static void mergeSimilarIntoTarget(final Clause target, List<Clause> similar) { if (similar.isEmpty()) { return; } final Collection<QualifierValue> targetQVs = target.getQualifierValues(); for (Clause current : similar) { final Collection<QualifierValue> newQVs = current.getQualifierValues(); for (QualifierValue newQV : newQVs) { final String newQualifier = newQV.getQualifier(); // if min or max cardinality check for possible merges if ("minCardinality".equals(newQualifier) || "maxCardinality".equals(newQualifier)) { QualifierValue match = findMatchingQualifierValue(newQV, targetQVs); if (match != null) { mergeQualifierValues(match, newQV); } else { target.addQualifierValue(newQV); } } else { target.addQualifierValue(newQV); } } } }