diff --git a/pronto/parsers/rdfxml.py b/pronto/parsers/rdfxml.py
index 1bb6514..4ea7219 100644
--- a/pronto/parsers/rdfxml.py
+++ b/pronto/parsers/rdfxml.py
@@ -802,14 +802,27 @@ def _process_axiom(self, elem: etree.Element, curies: Dict[str, str]):
)
return
- type_ = elem.find(_NS["oboInOwl"]["hasSynonymType"])
+ # extract synonym type name or IRI
+ elem_type = elem.find(_NS["oboInOwl"]["hasSynonymType"])
+ if elem_type is None:
+ type_ = None
+ elif _NS["rdf"]["resource"] in elem_type.attrib:
+ type_iri = elem_type.attrib[_NS["rdf"]["resource"]]
+ type_ = curies.get(type_iri) or self._compact_id(type_iri)
+ else:
+ type_ = elem_type.text
+
try:
+ # recover existing synonym on the entity if there's one already
synonym = next(
s._data()
for s in entity.synonyms
if s.description == elem_target.text
and s.scope == _SYNONYMS[property]
)
+ # update synonym type of existing synonym if we got one
+ if type_ is not None:
+ synonym.type = type_
except StopIteration:
description = elem_target.get(_NS["rdf"]["resource"], elem_target.text)
if description is None:
@@ -822,7 +835,7 @@ def _process_axiom(self, elem: etree.Element, curies: Dict[str, str]):
synonym = SynonymData(
description,
scope=_SYNONYMS[property],
- type=type_.text if type_ is not None else None,
+ type=type_,
)
entity._data().synonyms.add(typing.cast(SynonymData, synonym))
diff --git a/tests/test_parser/test_rdfxml.py b/tests/test_parser/test_rdfxml.py
index bff01ce..8e5e665 100644
--- a/tests/test_parser/test_rdfxml.py
+++ b/tests/test_parser/test_rdfxml.py
@@ -449,3 +449,58 @@ def test_relationship_symmetric(self):
)
self.assertIn("TST:001", ont.relationships())
self.assertTrue(ont.get_relationship("TST:001").symmetric)
+
+ def test_existing_synonym_type_extraction(self):
+ ont = self.get_ontology(
+ """
+
+
+
+ BRAND NAME
+
+
+
+
+ Cataflam
+ CHEBI:4508
+
+
+
+
+ Cataflam
+ DrugBank
+
+
+ """
+ )
+ syntype, = ont.metadata.synonymtypedefs
+ synonym, = ont["CHEBI:4508"].synonyms
+ self.assertEqual(synonym.scope, "RELATED")
+ self.assertEqual(synonym.type, syntype)
+
+ def test_missing_synonym_type_extraction(self):
+ ont = self.get_ontology(
+ """
+
+
+
+ BRAND NAME
+
+
+
+
+ CHEBI:4508
+
+
+
+
+ Cataflam
+ DrugBank
+
+
+ """
+ )
+ syntype, = ont.metadata.synonymtypedefs
+ synonym, = ont["CHEBI:4508"].synonyms
+ self.assertEqual(synonym.scope, "RELATED")
+ self.assertEqual(synonym.type, syntype)
\ No newline at end of file