@Nullable protected IRI getIRIByIdentifier(String id) { OWLAPIObo2Owl b = new OWLAPIObo2Owl(manager); b.setObodoc(new OBODoc()); return b.oboIdToIRI(id); }
} else { String id = checkNotNull(typedefFrame.getId()); OWLObjectProperty p = trObjectProp(id); add(fac.getOWLDeclarationAxiom(p)); String xid = translateShorthandIdToExpandedId(id); if (!xid.equals(id)) { OWLAxiom ax = fac .getOWLAnnotationAssertionAxiom(trTagToAnnotationProp("shorthand"), p.getIRI(), trLiteral(id), new HashSet<OWLAnnotation>()); add(ax); OboFormatTag tagConstant = OBOFormatConstants.getTag(tag); if (tagConstant == OboFormatTag.TAG_INTERSECTION_OF) { OWLAxiom axiom = trRelationIntersectionOf(id, p, clauses); if (axiom != null) { add(axiom); OWLAxiom axiom = trRelationUnionOf(id, p, clauses); if (axiom != null) { add(axiom); add(translateAltIds(clauses, p.getIRI(), false)); } else { clauses.forEach(c -> add(trTypedefClause(p, tag, c)));
protected void handleDate(String t, @Nullable Clause clause) { if (clause != null) { Object value = clause.getValue(); String dateString = null; if (value instanceof Date) { dateString = OBOFormatConstants.headerDateFormat().format((Date) value); } else if (value instanceof String) { dateString = (String) value; } if (dateString != null) { addOntologyAnnotation(trTagToAnnotationProp(t), trLiteral(dateString), trAnnotations(clause)); } else { // TODO: Throw Exceptions OBOFormatException e = new OBOFormatException( "Cannot translate clause «" + clause + '»'); LOG.error("Cannot translate: {}", clause, e); } } }
/** * Adds the ontology annotation. * * @param ap the ap * @param v the v * @param annotations the annotations */ protected void addOntologyAnnotation(OWLAnnotationProperty ap, OWLAnnotationValue v, Set<OWLAnnotation> annotations) { OWLAnnotation ontAnn = fac.getOWLAnnotation(ap, v, annotations); AddOntologyAnnotation addAnn = new AddOntologyAnnotation(getOwlOntology(), ontAnn); apply(addAnn); }
OWLAnnotationProperty parentAnnotProp = trTagToAnnotationProp(t); for (Clause clause : headerFrame.getClauses(t)) { OWLAnnotationProperty childAnnotProp = trAnnotationProp( clause.getValue(String.class)); Set<OWLAnnotation> annotations = trAnnotations(clause); add(fac.getOWLSubAnnotationPropertyOfAxiom(childAnnotProp, parentAnnotProp, annotations)); OWLAnnotationProperty ap = trTagToAnnotationProp( OboFormatTag.TAG_COMMENT.getTag()); add(fac.getOWLAnnotationAssertionAxiom(ap, childAnnotProp.getIRI(), trLiteral(clause.getValue2()))); OWLAnnotationProperty parentAnnotProp = trTagToAnnotationProp(t); for (Clause clause : headerFrame.getClauses(t)) { Object[] values = clause.getValues().toArray(); OWLAnnotationProperty childAnnotProp = trAnnotationProp(values[0].toString()); IRI childIRI = childAnnotProp.getIRI(); Set<OWLAnnotation> annotations = trAnnotations(clause); add(fac.getOWLSubAnnotationPropertyOfAxiom(childAnnotProp, parentAnnotProp, annotations)); OWLAnnotationProperty ap = trTagToAnnotationProp( OboFormatTag.TAG_NAME.getTag()); add(fac.getOWLAnnotationAssertionAxiom(ap, childIRI, trLiteral(values[1]))); if (values.length > 2 && !values[2].toString().isEmpty()) { ap = trTagToAnnotationProp(OboFormatTag.TAG_SCOPE.getTag()); add(fac.getOWLAnnotationAssertionAxiom(ap, childIRI, trTagToAnnotationProp(values[2].toString()) .getIRI()));
if (Boolean.TRUE.equals(tagValue)) { String id = checkNotNull(typedefFrame.getId()); OWLAnnotationProperty p = trAnnotationProp(id); add(fac.getOWLDeclarationAxiom(p)); String xid = translateShorthandIdToExpandedId(id); if (!id.equals(xid)) { OWLAxiom ax = fac .getOWLAnnotationAssertionAxiom(trTagToAnnotationProp("shorthand"), p.getIRI(), trLiteral(id), new HashSet<OWLAnnotation>()); add(ax); typedefFrame.getClauses(tag).forEach(c -> add(trGenericClause(p, tag, c)));
Collection<QualifierValue> quals) { Frame relFrame = obodoc.getTypedefFrame(relId); OWLObjectPropertyExpression pe = trObjectProp(relId); OWLClassExpression ce = trClass(classId); Integer exact = getQVInt("cardinality", quals); Integer min = getQVInt("minCardinality", quals); Integer max = getQVInt("maxCardinality", quals); boolean allSome = getQVBoolean("all_some", quals); boolean allOnly = getQVBoolean("all_only", quals); add(fac.getOWLDeclarationAxiom((OWLClass) ce)); .equals(relFrame.getTagValue(OboFormatTag.TAG_IS_CLASS_LEVEL_TAG))) { ex = fac.getOWLObjectHasValue(pe, trIndividual(classId)); } else {
/** * Tr term frame. * * @param termFrame the term frame * @return the oWL class expression */ public OWLClassExpression trTermFrame(Frame termFrame) { OWLClass cls = trClass(checkNotNull(termFrame.getId())); add(fac.getOWLDeclarationAxiom(cls)); termFrame.getTags().stream().filter(OboFormatTag.TAG_ALT_ID.getTag()::equals).forEach(t -> // Generate deprecated and replaced_by details for alternate // identifier add(translateAltIds(termFrame.getClauses(t), cls.getIRI(), true))); termFrame.getTags().forEach(t -> add(trTermFrameClauses(cls, termFrame.getClauses(t), t))); return cls; }
Set<OWLAnnotation> annotations = trAnnotations(clause); Collection<Object> values = clause.getValues(); Object v = clause.getValue(); if (values.size() == 2) { OWLAnnotationProperty prop = trAnnotationProp((String) v); OWLAnnotationValue value = trAnnotationProp(v2.toString()).getIRI(); OWLAnnotation ontAnn = fac.getOWLAnnotation(prop, value, annotations); AddOntologyAnnotation addAnn = new AddOntologyAnnotation(getOwlOntology(), ontAnn); apply(addAnn); } else if (values.size() == 3) { OWLAnnotationProperty prop = trAnnotationProp((String) v); OWLAnnotation ontAnn = fac.getOWLAnnotation(prop, value, annotations); AddOntologyAnnotation addAnn = new AddOntologyAnnotation(getOwlOntology(), ontAnn); apply(addAnn); } else { LOG.error("Cannot translate: {}", clause);
/** * Static convenience method which: (1) creates an Obo2Owl bridge object (2) * parses an obo file from a URL (3) converts that to an OWL ontology (4) * saves the OWL ontology as RDF/XML. * * @param iri the iri * @param outFile the out file * @param manager manager to use * @throws IOException Signals that an I/O exception has occurred. * @throws OWLOntologyCreationException the oWL ontology creation exception * @throws OWLOntologyStorageException the oWL ontology storage exception * @throws OBOFormatParserException the oBO format parser exception */ public static void convertURL(String iri, String outFile, OWLOntologyManager manager) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException { OWLAPIObo2Owl bridge = new OWLAPIObo2Owl(manager); OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new URL(iri)); OWLOntology ontology = bridge.convert(obodoc); IRI outputStream = IRI.create(outFile); OWLDocumentFormat format = new RDFXMLDocumentFormat(); LOG.info("saving to {} fmt={}", outputStream, format); manager.saveOntology(ontology, format, outputStream); }
String xid = translateShorthandIdToExpandedId(id); if (!xid.equals(id)) { return oboIdToIRI(xid); db = getDefaultIDSpace() + '#'; localId = id; } else { db = getDefaultIDSpace() + '#'; localId = idParts[0];
/** * Tr tag to annotation prop. * * @param tag the tag * @return the oWL annotation property */ protected OWLAnnotationProperty trTagToAnnotationProp(String tag) { IRI iri = trTagToIRI(tag); OWLAnnotationProperty ap = fac.getOWLAnnotationProperty(iri); if (!apToDeclare.contains(ap)) { apToDeclare.add(ap); add(fac.getOWLDeclarationAxiom(ap)); Obo2OWLVocabulary vocab = Obo2OWLConstants.getVocabularyObj(tag); if (vocab != null) { add(fac.getOWLAnnotationAssertionAxiom(iri, fac.getRDFSLabel(vocab.getLabel()))); } } return ap; }
@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; }
/** * Adds the. * * @param axiom the axiom */ protected void add(@Nullable OWLAxiom axiom) { if (axiom == null) { LOG.error("no axiom"); return; } add(Collections.singleton(axiom)); }
/** * Adds the. * * @param axioms the axioms */ protected void add(@Nullable Set<OWLAxiom> axioms) { if (axioms == null || axioms.isEmpty()) { LOG.error("no axiom"); return; } getOwlOntology().add(axioms); }
/** * Apply the change. * * @param change the change */ protected void apply(OWLOntologyChange change) { apply(CollectionFactory.list(change)); }
/** * Creates an OBOFormatParser object to parse a file and then converts it * using the convert method. * * @param oboFile the obo file * @return ontology * @throws OWLOntologyCreationException the oWL ontology creation exception */ public OWLOntology convert(String oboFile) throws OWLOntologyCreationException { try { OBOFormatParser p = new OBOFormatParser(); return convert(p.parse(oboFile)); } catch (IOException ex) { throw new OWLOntologyCreationException( "Error Occured while parsing OBO '" + oboFile + '\'', ex); } catch (OBOFormatParserException ex) { throw new OWLOntologyCreationException( "Syntax error occured while parsing OBO '" + oboFile + '\'', ex); } }
/** * See section "header macros" and treat-xrefs-as-equivalent. * * @param id the id * @return mapped id */ protected String mapPropId(String id) { Frame f = obodoc.getTypedefFrame(id); if (f != null) { Collection<Xref> xrefs = f.getTagValues(OboFormatTag.TAG_XREF, Xref.class); for (Xref x : xrefs) { String xid = x.getIdref(); if (OBODoc.isTreatXrefsAsEquivalent(getIdPrefix(xid))) { return xid; } } } return id; }
OWLAnnotationProperty parentAnnotProp = trTagToAnnotationProp(t); for (Clause clause : headerFrame.getClauses(t)) { OWLAnnotationProperty childAnnotProp = trAnnotationProp( clause.getValue(String.class)); Set<OWLAnnotation> annotations = trAnnotations(clause); add(fac.getOWLSubAnnotationPropertyOfAxiom(childAnnotProp, parentAnnotProp, annotations)); OWLAnnotationProperty ap = trTagToAnnotationProp( OboFormatTag.TAG_COMMENT.getTag()); add(fac.getOWLAnnotationAssertionAxiom(ap, childAnnotProp.getIRI(), trLiteral(clause.getValue2()))); OWLAnnotationProperty parentAnnotProp = trTagToAnnotationProp(t); for (Clause clause : headerFrame.getClauses(t)) { Object[] values = clause.getValues().toArray(); OWLAnnotationProperty childAnnotProp = trAnnotationProp(values[0].toString()); IRI childIRI = childAnnotProp.getIRI(); Set<OWLAnnotation> annotations = trAnnotations(clause); add(fac.getOWLSubAnnotationPropertyOfAxiom(childAnnotProp, parentAnnotProp, annotations)); OWLAnnotationProperty ap = trTagToAnnotationProp( OboFormatTag.TAG_NAME.getTag()); add(fac.getOWLAnnotationAssertionAxiom(ap, childIRI, trLiteral(values[1]))); if (values.length > 2 && !values[2].toString().isEmpty()) { ap = trTagToAnnotationProp(OboFormatTag.TAG_SCOPE.getTag()); add(fac.getOWLAnnotationAssertionAxiom(ap, childIRI, trTagToAnnotationProp(values[2].toString()) .getIRI()));
if (Boolean.TRUE.equals(tagValue)) { String id = checkNotNull(typedefFrame.getId()); OWLAnnotationProperty p = trAnnotationProp(id); add(fac.getOWLDeclarationAxiom(p)); String xid = translateShorthandIdToExpandedId(id); if (!id.equals(xid)) { OWLAxiom ax = fac .getOWLAnnotationAssertionAxiom(trTagToAnnotationProp("shorthand"), p.getIRI(), trLiteral(id), new HashSet<OWLAnnotation>()); add(ax); typedefFrame.getClauses(tag).forEach(c -> add(trGenericClause(p, tag, c)));