Skip to content

Commit 0044b99

Browse files
balhoffignazio1977
authored andcommitted
Allow arbitrary annotation properties as qualifier tags in OBO #1099
Allowing arbitrary defined annotation properties as qualifier tags. Use oboInOWL as the default namespace when looking up tag IRIs. This helps with backwards compatibility for undeclared annotation properties. Enforce oio namespace for created_by and creation_date.
1 parent 4bc5d44 commit 0044b99

File tree

5 files changed

+161
-6
lines changed

5 files changed

+161
-6
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.obolibrary.oboformat;
2+
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
4+
5+
import java.util.Collections;
6+
import java.util.Set;
7+
import java.util.stream.Collectors;
8+
import java.util.stream.Stream;
9+
10+
import org.junit.jupiter.api.Test;
11+
import org.semanticweb.owlapi.api.test.baseclasses.TestBase;
12+
import org.semanticweb.owlapi.model.IRI;
13+
import org.semanticweb.owlapi.model.OWLAnnotation;
14+
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
15+
import org.semanticweb.owlapi.model.OWLAxiom;
16+
import org.semanticweb.owlapi.model.OWLClass;
17+
import org.semanticweb.owlapi.model.OWLLiteral;
18+
import org.semanticweb.owlapi.model.OWLOntology;
19+
import org.semanticweb.owlapi.vocab.OWL2Datatype;
20+
21+
class TagIRIsTest extends TestBase {
22+
23+
@Test
24+
void testTagIRIMapping() {
25+
OWLAnnotationProperty definition =
26+
df.getOWLAnnotationProperty(IRI.create("http://purl.obolibrary.org/obo/IAO_0000115"));
27+
OWLAnnotationProperty oioCreatedBy = df.getOWLAnnotationProperty(
28+
IRI.create("http://www.geneontology.org/formats/oboInOwl#created_by"));
29+
OWLAnnotationProperty oioInventedBy = df.getOWLAnnotationProperty(
30+
IRI.create("http://www.geneontology.org/formats/oboInOwl#invented_by"));
31+
OWLAnnotationProperty source =
32+
df.getOWLAnnotationProperty(IRI.create("http://purl.obolibrary.org/obo/MYONT_20"));
33+
OWLOntology ont = loadOntology("obo/tag_iris.obo", m);
34+
Set<OWLAxiom> axioms = ont.getAxioms();
35+
OWLClass term1 = df.getOWLClass(IRI.create("http://purl.obolibrary.org/obo/MYONT_1"));
36+
OWLClass term2 = df.getOWLClass(IRI.create("http://purl.obolibrary.org/obo/MYONT_2"));
37+
OWLClass term3 = df.getOWLClass(IRI.create("http://purl.obolibrary.org/obo/MYONT_3"));
38+
OWLClass term4 = df.getOWLClass(IRI.create("http://purl.obolibrary.org/obo/MYONT_4"));
39+
Set<OWLAnnotation> annotations = Stream
40+
.of(df.getOWLAnnotation(df.getRDFSComment(), string("Here is a sub-annotation.")),
41+
df.getOWLAnnotation(df.getRDFSSeeAlso(), string("A nested see also value.")))
42+
.collect(Collectors.toSet());
43+
assertTrue(axioms.contains(df.getOWLAnnotationAssertionAxiom(definition, term1.getIRI(),
44+
string("Definition of term one."), annotations)));
45+
assertTrue(axioms.contains(df.getOWLAnnotationAssertionAxiom(df.getRDFSSeeAlso(),
46+
term1.getIRI(), string("See also value."))));
47+
assertTrue(axioms.contains(df.getOWLAnnotationAssertionAxiom(definition, term2.getIRI(),
48+
string("Definition of term two."), Collections
49+
.singleton(df.getOWLAnnotation(source, string("A nested annotation value."))))));
50+
assertTrue(axioms.contains(df.getOWLAnnotationAssertionAxiom(definition, term3.getIRI(),
51+
string("Definition of term three."), Collections
52+
.singleton(df.getOWLAnnotation(source, string("A definition source value."))))));
53+
assertTrue(
54+
axioms.contains(
55+
df.getOWLAnnotationAssertionAxiom(oioCreatedBy, term3.getIRI(), string("goc:bro"))),
56+
"created_by is built in and should not be overridden by a typedef");
57+
assertTrue(
58+
axioms.contains(df.getOWLAnnotationAssertionAxiom(definition, term4.getIRI(),
59+
string("Definition of term four."),
60+
Collections
61+
.singleton(df.getOWLAnnotation(oioInventedBy, string("An inventor value."))))),
62+
"An undeclared tag should have oio namespace");
63+
64+
}
65+
66+
protected OWLLiteral string(String l) {
67+
return df.getOWLLiteral(l, OWL2Datatype.XSD_STRING);
68+
}
69+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
format-version: 1.2
2+
ontology: myont
3+
4+
[Term]
5+
id: MYONT:1
6+
name: term one
7+
def: "Definition of term one." [] {comment="Here is a sub-annotation.", seeAlso="A nested see also value."}
8+
property_value: seeAlso "See also value." xsd:string
9+
10+
[Term]
11+
id: MYONT:2
12+
name: term two
13+
def: "Definition of term two." [] {MYONT:20="A nested annotation value."}
14+
property_value: MYONT:21 "A top level annotation value." xsd:string
15+
16+
[Term]
17+
id: MYONT:3
18+
name: term three
19+
def: "Definition of term three." [] {source="A definition source value."}
20+
intersection_of: MYONT:2 ! term two
21+
intersection_of: results_in_transport_across GO:0005739 ! mitochondrion
22+
created_by: goc:bro
23+
24+
[Term]
25+
id: MYONT:4
26+
name: term four
27+
def: "Definition of term four." [] {invented_by="An inventor value."}
28+
29+
[Typedef]
30+
id: source
31+
name: source
32+
xref: MYONT:20
33+
is_metadata_tag: true
34+
35+
[Typedef]
36+
id: MYONT:21
37+
name: source2
38+
is_metadata_tag: true
39+
40+
[Typedef]
41+
id: seeAlso
42+
name: see also
43+
xref: http://www.w3.org/2000/01/rdf-schema#seeAlso
44+
is_metadata_tag: true
45+
46+
[Typedef]
47+
id: results_in_transport_across
48+
name: results in transport across
49+
namespace: external
50+
xref: RO:0002342
51+
52+
[Typedef]
53+
id: created_by
54+
name: created by
55+
namespace: external
56+
xref: http://purl.org/dc/terms/creator

oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIObo2Owl.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.obolibrary.obo2owl;
22

33
import static org.obolibrary.obo2owl.Obo2OWLConstants.DEFAULT_IRI_PREFIX;
4+
import static org.obolibrary.obo2owl.Obo2OWLConstants.OIOVOCAB_IRI_PREFIX;
45
import static org.semanticweb.owlapi.util.OWLAPIPreconditions.verifyNotNull;
56

67
import java.io.File;
@@ -1518,6 +1519,15 @@ public static IRI trTagToIRI(String tag) {
15181519
return iri;
15191520
}
15201521

1522+
@Nonnull
1523+
private IRI trTagToIRIIncludingTypedefs(String tag) {
1524+
IRI iri = ANNOTATIONPROPERTYMAP.get(tag);
1525+
if (iri == null) {
1526+
iri = oboIdToIRI(tag, true);
1527+
}
1528+
return iri;
1529+
}
1530+
15211531
/**
15221532
* Translate tag to annotation prop.
15231533
*
@@ -1526,7 +1536,7 @@ public static IRI trTagToIRI(String tag) {
15261536
*/
15271537
@Nonnull
15281538
protected OWLAnnotationProperty trTagToAnnotationProp(@Nonnull String tag) {
1529-
IRI iri = trTagToIRI(tag);
1539+
IRI iri = trTagToIRIIncludingTypedefs(tag);
15301540
OWLAnnotationProperty ap = fac.getOWLAnnotationProperty(iri);
15311541
if (!apToDeclare.contains(ap)) {
15321542
apToDeclare.add(ap);
@@ -1624,22 +1634,31 @@ protected OWLAnnotationValue trLiteral(@Nonnull Object inputValue) {
16241634
*/
16251635
@Nonnull
16261636
public IRI oboIdToIRI(@Nonnull String id) {
1637+
return oboIdToIRI(id, false);
1638+
}
1639+
1640+
private IRI oboIdToIRI(@Nonnull String id, boolean oboInOwlDefault) {
16271641
IRI iri = idToIRICache.get(id);
16281642
if (iri == null) {
1629-
iri = oboIdToIRI_load(id);
1643+
iri = oboIdToIRI_load(id, oboInOwlDefault);
16301644
idToIRICache.put(id, iri);
16311645
}
16321646
return iri;
16331647
}
16341648

1649+
@Nonnull
1650+
public IRI oboIdToIRI_load(@Nonnull String id) {
1651+
return oboIdToIRI_load(id, false);
1652+
}
1653+
16351654
/**
16361655
* Obo id to iri.
16371656
*
16381657
* @param id the id
16391658
* @return the iri
16401659
*/
16411660
@Nonnull
1642-
public IRI oboIdToIRI_load(@Nonnull String id) {
1661+
public IRI oboIdToIRI_load(@Nonnull String id, boolean oboInOwlDefault) {
16431662
if (id.contains(" ")) {
16441663
LOG.error("id contains space: \"{}\"", id);
16451664
throw new OWLParserException("spaces not allowed: '" + id + '\'');
@@ -1704,10 +1723,16 @@ public IRI oboIdToIRI_load(@Nonnull String id) {
17041723
// if(id.contains("_"))
17051724
// db += "_";
17061725
localId = idParts[0];// Unprefixed-ID
1726+
17071727
}
1708-
String uriPrefix = DEFAULT_IRI_PREFIX + db;
1709-
if (idSpaceMap.containsKey(db)) {
1710-
uriPrefix = idSpaceMap.get(db);
1728+
String uriPrefix;
1729+
if (oboInOwlDefault) {
1730+
uriPrefix = OIOVOCAB_IRI_PREFIX;
1731+
} else {
1732+
uriPrefix = DEFAULT_IRI_PREFIX + db;
1733+
if (idSpaceMap.containsKey(db)) {
1734+
uriPrefix = idSpaceMap.get(db);
1735+
}
17111736
}
17121737
String safeId;
17131738
try {

oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIOwl2Obo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,8 @@ public static String owlObjectToTag(OWLObject obj) {
18691869
String prefix = Obo2OWLConstants.OIOVOCAB_IRI_PREFIX;
18701870
if (iri.startsWith(prefix)) {
18711871
tag = iri.substring(prefix.length());
1872+
} else {
1873+
tag = getIdentifier(iriObj);
18721874
}
18731875
}
18741876
return tag;

oboformat/src/main/java/org/obolibrary/obo2owl/Obo2OWLConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public enum Obo2OWLVocabulary implements HasIRI {
5555
/**IRI_IAO_0100001*/ IRI_IAO_0100001(DEFAULT_IRI_PREFIX, "IAO_0100001", "term replaced by", OboFormatTag.TAG_REPLACED_BY.getTag()),
5656
/**IRI_OIO_shorthand*/ IRI_OIO_shorthand(OIOVOCAB_IRI_PREFIX, "shorthand", "shorthand", "shorthand"),
5757
/**IRI_OIO_consider*/ IRI_OIO_consider(OIOVOCAB_IRI_PREFIX, "consider", "consider", OboFormatTag.TAG_CONSIDER.getTag()),
58+
/**IRI_OIO_id*/ IRI_OIO_id(OIOVOCAB_IRI_PREFIX, "id", "id", OboFormatTag.TAG_ID.getTag()),
59+
/**IRI_OIO_created_by*/ IRI_OIO_created_by(OIOVOCAB_IRI_PREFIX, "created_by", "created by", OboFormatTag.TAG_CREATED_BY.getTag()),
60+
/**IRI_OIO_creation_date*/ IRI_OIO_creation_date(OIOVOCAB_IRI_PREFIX, "creation_date", "creation date", OboFormatTag.TAG_CREATION_DATE.getTag()),
5861
/**IRI_OIO_hasOBOFormatVersion*/ IRI_OIO_hasOBOFormatVersion(OIOVOCAB_IRI_PREFIX, "hasOBOFormatVersion", "has_obo_format_version", OboFormatTag.TAG_FORMAT_VERSION.getTag()),
5962
/**IRI_OIO_treatXrefsAsIsA*/ IRI_OIO_treatXrefsAsIsA(OIOVOCAB_IRI_PREFIX, "treat-xrefs-as-is_a", "treat-xrefs-as-is_a", OboFormatTag.TAG_TREAT_XREFS_AS_IS_A.getTag()),
6063
/**IRI_OIO_treatXrefsAsHasSubClass*/ IRI_OIO_treatXrefsAsHasSubClass(OIOVOCAB_IRI_PREFIX, "treat-xrefs-as-has-subclass", "treat-xrefs-as-has-subclass", OboFormatTag.TAG_TREAT_XREFS_AS_HAS_SUBCLASS.getTag()),

0 commit comments

Comments
 (0)