Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce uncompressible URIs in seeAlso relations to literals #322

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/pyobo/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,17 +1146,24 @@ def _handle_prop(
obj_reference = _parse_identifier(
value_type, strict=strict, ontology_prefix=ontology_prefix, node=node
)
if obj_reference is None:
if not UNHANDLED_PROP_OBJECTS[prop_reference, value_type]:
logger.warning(
"[%s - %s] could not parse object: %s",
node.curie,
prop_reference.curie,
value_type,
)
UNHANDLED_PROP_OBJECTS[prop_reference, value_type] += 1
return None
return Annotation(prop_reference, obj_reference)
if obj_reference is not None:
return Annotation(prop_reference, obj_reference)

# TODO if the predicate is part of a sacred class (e.g., rdfs:seeAlso)
# and the value_type looks like a URL, store it
if prop_reference in {v.see_also} and value_type.startswith("http"):
return Annotation(prop_reference, OBOLiteral.uri(value_type))

if not UNHANDLED_PROP_OBJECTS[prop_reference, value_type]:
logger.warning(
"[%s - %s] could not parse object: %s",
node.curie,
prop_reference.curie,
value_type,
)
UNHANDLED_PROP_OBJECTS[prop_reference, value_type] += 1
return None


try:
value, datatype = value_type.rsplit(" ", 1) # second entry is the value type
Expand Down
19 changes: 19 additions & 0 deletions tests/test_obo_reader/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,25 @@ def test_12_property_literal_object(self) -> None:
self.assertIn(see_also.reference, term.properties)
self.assertEqual("hgnc:1234", term.get_property(see_also))

def test_12_property_convert_uri(self) -> None:
"""Test that unparsable URIs for seeAlso are stored as literals."""
ontology = from_str("""\
ontology: chebi

[Term]
id: CHEBI:1234
property_value: rdfs:seeAlso https://example.org
""")
term = self.get_only_term(ontology)
self.assertEqual(1, len(list(term.properties)))
self.assertIn(see_also.reference, term.properties)
properties = term.properties[see_also.reference]
self.assertEqual(1, len(properties))
prop = properties[0]
self.assertIsInstance(prop, OBOLiteral)
self.assertEqual("https://example.org", prop.value)
self.assertEqual(v.xsd_uri, prop.datatype)

def test_13_parent(self) -> None:
"""Test parsing out a parent."""
ontology = from_str("""\
Expand Down
Loading