IRI getIRIByIdentifier(String id) { Obo2Owl b = new Obo2Owl(manager); b.setObodoc(new OBODoc()); return b.oboIdToIRI(id); }
public OWLClassExpression trTermFrame(Frame termFrame) { OWLClass cls = trClass(termFrame.getId()); add(fac.getOWLDeclarationAxiom(cls)); for (String t : termFrame.getTags()) { //System.out.println("tag:"+tag); Collection<Clause> clauses = termFrame.getClauses(t); OboFormatTag tag = OBOFormatConstants.getTag(t); if (tag == OboFormatTag.TAG_INTERSECTION_OF) { add(trIntersectionOf(cls,clauses)); } else if (tag == OboFormatTag.TAG_UNION_OF) { add(trUnionOf(cls,clauses)); } else { for (Clause clause : clauses) { add(trTermClause(cls,t,clause)); } } } return cls; }
protected void add(OWLAxiom axiom) { if (axiom == null) { LOG.log(Level.SEVERE, "no axiom"); return; } //System.out.println("adding:"+axiom); AddAxiom addAx = new AddAxiom(owlOntology, axiom); apply(addAx); }
private 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(fac.getRDFSLabel(), iri, trLiteral( vocab.getLabel()) ) ); } } return ap; }
OWLObjectProperty p = trObjectProp(id); add(fac.getOWLDeclarationAxiom(p)); String xid = translateShorthandIdToExpandedId(id); if (xid.equals(id) == false) { OWLAxiom ax = fac.getOWLAnnotationAssertionAxiom( trTagToAnnotationProp("shorthand"), p.getIRI(), trLiteral(id), new HashSet<OWLAnnotation>()); add(ax); final OWLAxiom axiom = trRelationIntersectionOf(id, p,clauses); if (axiom != null) { add(axiom); final OWLAxiom axiom = trRelationUnionOf(id, p,clauses); if (axiom != null) { add(axiom); add(trTypedefClause(p,tag,clause));
OWLAnnotationProperty parentAnnotProp = trTagToAnnotationProp(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); 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] ))); ap = trTagToAnnotationProp(OboFormatTag.TAG_SCOPE.getTag()); add (fac.getOWLAnnotationAssertionAxiom(ap, childIRI, trTagToAnnotationProp( values[2].toString() ).getIRI() )); addOntologyAnnotation(trTagToAnnotationProp(t), trLiteral(dateString), trAnnotations(clause)); addPropertyValueHeaders(headerFrame.getClauses(OboFormatTag.TAG_PROPERTY_VALUE)); } else if (tag == OboFormatTag.TAG_DATA_VERSION) {
OWLAnnotationProperty p = trAnnotationProp(id); add(fac.getOWLDeclarationAxiom(p)); final String xid = translateShorthandIdToExpandedId(id); if (id.equals(xid) == false) { OWLAxiom ax = fac.getOWLAnnotationAssertionAxiom( trTagToAnnotationProp("shorthand"), p.getIRI(), trLiteral(id), new HashSet<OWLAnnotation>()); add(ax); for (Clause clause : typedefFrame.getClauses(tag)) { add(trGenericClause(p, tag, clause));
public OWLClassExpression trRel(String relId, String classId, Collection<QualifierValue> quals) { OWLClassExpression ex; 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)); (Boolean)relFrame.getTagValue(OboFormatTag.TAG_IS_CLASS_LEVEL_TAG)) { ex = fac.getOWLObjectHasValue(pe,trIndividual(classId));
/** * 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 * @param outFile * @throws IOException * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws OBOFormatParserException */ public static void convertURL(String iri, String outFile, OWLOntologyManager manager) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, OBOFormatParserException { Obo2Owl bridge = new Obo2Owl(manager); OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new URL(iri)); OWLOntology ontology = bridge.convert(obodoc); IRI outputStream = IRI.create(outFile); OWLOntologyFormat format = new RDFXMLOntologyFormat(); LOG.log(Level.WARNING, "saving to " + outputStream + " fmt=" + format); manager.saveOntology(ontology, format, outputStream); }
String xid = translateShorthandIdToExpandedId(id); if (!xid.equals(id)) { return oboIdToIRI(xid); db = getDefaultIDSpace()+"#"; localId = id; db = getDefaultIDSpace()+"#";
private void addPropertyValueHeaders(Collection<Clause> clauses) { for (Clause clause : clauses) { final Set<OWLAnnotation> annotations = trAnnotations(clause); Collection<Object> values = clause.getValues(); Object v = clause.getValue(); OWLAnnotationProperty prop = trAnnotationProp((String)v); OWLAnnotationValue value = trAnnotationProp(v2.toString()).getIRI(); OWLAnnotation ontAnn = fac.getOWLAnnotation(prop, value, annotations); AddOntologyAnnotation addAnn = new AddOntologyAnnotation(owlOntology, ontAnn); apply(addAnn); OWLAnnotationProperty prop = trAnnotationProp((String)v); OWLAnnotation ontAnn = fac.getOWLAnnotation(prop, value, annotations); AddOntologyAnnotation addAnn = new AddOntologyAnnotation(owlOntology, ontAnn); apply(addAnn);
Obo2Owl bridge = new Obo2Owl(null); OWLOntologyManager manager = bridge.getManager(); OWLOntology ontology = bridge.convert(obodoc);
/** * Converts an OBO document to an OWL ontology * * @param obodoc * @return ontology * @throws OWLOntologyCreationException */ public OWLOntology convert(OBODoc obodoc) throws OWLOntologyCreationException { // always create a new manager, when loading a new obo document - TODO - why? // creates problems for sharing ontologies return convert(obodoc, false); }
continue; Obo2Owl.convertURL(url, getURI(dir + "/" + ontId + ".owl"), ontId, manager); long totalTime = System.nanoTime() - initTime;
/** * See section "header macros" and treat-xrefs-as-equivalent * * @param id * @return mapped id */ private 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; }
/** * See {@link #convertURL(String iri, String outFile)} * * @param iri * @param outFile * @param defaultOnt -- e.g. "go". If the obo file contains no "ontology:" header tag, this is added * @throws IOException * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws OBOFormatParserException */ public static void convertURL(String iri, String outFile, String defaultOnt, OWLOntologyManager manager) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, OBOFormatParserException { Obo2Owl bridge = new Obo2Owl(manager); OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new URL(iri)); obodoc.addDefaultOntologyHeader(defaultOnt); OWLOntology ontology = bridge.convert(obodoc); IRI outputStream = IRI.create(outFile); OWLOntologyFormat format = new RDFXMLOntologyFormat(); LOG.log(Level.WARNING, "saving to " + outputStream + " fmt=" + format); manager.saveOntology(ontology, format, outputStream); }
/** * Creates an OBOFormatParser object to parse a file and then converts it using * the convert method * * @param oboFile * @return ontology * @throws OWLOntologyCreationException */ public OWLOntology convert(String oboFile) throws OWLOntologyCreationException { try{ OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(oboFile); return convert(obodoc); }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); } }
continue; Obo2Owl.convertURL(url, getURI(dir + "/" + ontId + ".owl"), ontId, manager); long totalTime = System.nanoTime() - initTime;
private OWLOntology parse(IRI iri, OWLOntologyDocumentSource source, OWLOntology in) throws OBOFormatParserException, MalformedURLException, IOException, OWLOntologyCreationException { OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = null; if (iri != null) { obodoc = p.parse(iri.toURI().toURL()); } else { if (source.isReaderAvailable()) { obodoc = p.parse(new BufferedReader(source.getReader())); } else if (source.isInputStreamAvailable()) { obodoc = p.parse(new BufferedReader(new InputStreamReader(source .getInputStream()))); } else { return parse(source.getDocumentIRI(), null, in); } } // create a translator object and feed it the OBO Document Obo2Owl bridge = new Obo2Owl(manager); OWLOntology ontology = bridge.convert(obodoc, in); if (ontology == in) { return in; } return ontology; } }
protected void addOntologyAnnotation(OWLAnnotationProperty ap, OWLAnnotationValue v, Set<OWLAnnotation> annotations) { OWLAnnotation ontAnn = fac.getOWLAnnotation(ap, v, annotations); AddOntologyAnnotation addAnn = new AddOntologyAnnotation(owlOntology, ontAnn); apply(addAnn); }