Skip to content

Commit 273cf64

Browse files
authored
Handle term tracker item as URI (#534)
1 parent 2b338ca commit 273cf64

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/pyobo/struct/obo/reader.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import networkx as nx
1717
from curies import ReferenceTuple
1818
from curies.preprocessing import BlocklistError
19-
from curies.vocabulary import SynonymScope
19+
from curies.vocabulary import SynonymScope, xsd_datetime
2020
from more_itertools import pairwise
2121
from pystow.utils import open_zipfile, safe_open
2222
from tqdm.auto import tqdm
@@ -40,6 +40,7 @@
4040
)
4141
from ..struct_utils import Annotation, Stanza
4242
from ..typedef import default_typedefs, has_comment, has_ontology_root_term
43+
from ..vocabulary import term_tracker_item, xsd_uri
4344
from ...constants import DATE_FORMAT, PROVENANCE_PREFIXES
4445
from ...identifier_utils import (
4546
NotCURIEError,
@@ -735,7 +736,6 @@ def _handle_xref(
735736

736737
SUBSET_ERROR_COUNTER: Counter[tuple[str, str]] = Counter()
737738

738-
739739
SubsetTypeDefs: TypeAlias = dict[Reference, str]
740740

741741

@@ -1254,6 +1254,10 @@ def iterate_node_properties(
12541254

12551255
UNHANDLED_PROPS: Counter[tuple[str, str]] = Counter()
12561256

1257+
PREDICATE_TO_DATATYPE = {
1258+
term_tracker_item: xsd_uri,
1259+
}
1260+
12571261

12581262
def _handle_prop(
12591263
prop_value_type: str,
@@ -1286,7 +1290,9 @@ def _handle_prop(
12861290
value_type = value_type.strip()
12871291
datatype: Reference | None
12881292
if " " not in value_type:
1289-
value, datatype = value_type, None
1293+
value = value_type
1294+
# this automatically upgrades the datatype in some cases
1295+
datatype = PREDICATE_TO_DATATYPE.get(prop_reference)
12901296
else:
12911297
value, datatype_raw = (s.strip() for s in value_type.rsplit(" ", 1))
12921298
match _parse_str_or_curie_or_uri_helper(
@@ -1319,7 +1325,7 @@ def _handle_prop(
13191325

13201326
# first, special case datetimes. Whether it's quoted or not,
13211327
# we always deal with this first
1322-
if datatype and datatype.curie == "xsd:dateTime":
1328+
if datatype == xsd_datetime:
13231329
try:
13241330
obo_literal = OBOLiteral.datetime(value)
13251331
except ValueError:
@@ -1330,7 +1336,7 @@ def _handle_prop(
13301336
else:
13311337
return Annotation(prop_reference, obo_literal)
13321338

1333-
if datatype and datatype.curie == "xsd:anyURI":
1339+
if datatype == xsd_uri:
13341340
match _parse_str_or_curie_or_uri_helper(
13351341
value,
13361342
node=node,

src/pyobo/struct/vocabulary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def _c(c: curies.Reference) -> Reference:
6969
has_ontology_root_term = _c(_v.has_ontology_root_term)
7070
has_ontology_hierarchy_predicate = _c(_v.has_ontology_hierarchical_property)
7171
has_term_editor = _c(_v.has_term_editor)
72+
term_tracker_item = _c(_v.term_tracker_item)
7273

7374
see_also = _c(_v.see_also)
7475
comment = _c(_v.has_comment)

tests/test_obo_reader/test_reader.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
see_also,
2323
term_replaced_by,
2424
)
25-
from pyobo.struct.vocabulary import CHARLIE
25+
from pyobo.struct.vocabulary import CHARLIE, term_tracker_item
2626
from tests import cases
2727
from tests.cases import TermMixin
2828

@@ -1095,6 +1095,24 @@ def test_12_property_object_with_string_dtype(self) -> None:
10951095
self.assertEqual(1, len(xx))
10961096
self.assertEqual(Reference(prefix="pubmed", identifier="17921072"), xx[0])
10971097

1098+
def test_12_property_bare_term_tracker_type(self) -> None:
1099+
"""Test parsing a property whose datatype should get inferred."""
1100+
ontology = from_str("""\
1101+
ontology: ro
1102+
1103+
[Term]
1104+
id: RO:0002160
1105+
property_value: IAO:0000233 https://github.com/obophenotype/human-phenotype-ontology/issues/11573
1106+
""")
1107+
term = self.get_only_term(ontology)
1108+
self.assertEqual(1, len(list(term.properties)))
1109+
xx = term.get_property_literals(term_tracker_item)
1110+
self.assertEqual(1, len(xx))
1111+
self.assertEqual(
1112+
OBOLiteral.uri("https://github.com/obophenotype/human-phenotype-ontology/issues/11573"),
1113+
xx[0],
1114+
)
1115+
10981116
def test_13_parent(self) -> None:
10991117
"""Test parsing out a parent."""
11001118
ontology = from_str("""\

0 commit comments

Comments
 (0)