diff --git a/bmt/toolkit.py b/bmt/toolkit.py index 83f91e4..1fe8c95 100644 --- a/bmt/toolkit.py +++ b/bmt/toolkit.py @@ -967,7 +967,13 @@ def get_element(self, name: str) -> Optional[Element]: element = self.get_element(name.replace("_", " ")) if element is None: for e, el in self.view.all_elements().items(): - if el.name.lower() == name.lower(): + el_normalized = el.name.lower().replace(' ', '').replace('_', '') + name_normalized = name.lower().replace(' ', '').replace('_', '') + parsed_normalized = parsed_name.lower().replace(' ', '').replace('_', '') + if (el.name.lower() == name.lower() or + el.name.lower() == parsed_name.lower() or + el_normalized == name_normalized or + el_normalized == parsed_normalized): element = el if type(element) == ClassDefinition and element.class_uri is None: diff --git a/poetry.lock b/poetry.lock index 2b71e4c..42aec3b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.2 and should not be changed by hand. [[package]] name = "alabaster" @@ -343,7 +343,7 @@ description = "Read metadata from Python packages" optional = false python-versions = ">=3.8" groups = ["dev"] -markers = "python_version < \"3.10\"" +markers = "python_version == \"3.9\"" files = [ {file = "importlib_metadata-7.1.0-py3-none-any.whl", hash = "sha256:30962b96c0c223483ed6cc7280e7f0199feb01a0e40cfae4d4450fc6fab1f570"}, {file = "importlib_metadata-7.1.0.tar.gz", hash = "sha256:b78938b926ee8d5f020fc4772d487045805a55ddbad2ecf21c6d60938dc7fcd2"}, @@ -1466,7 +1466,7 @@ description = "Backport of pathlib-compatible object wrapper for zip files" optional = false python-versions = ">=3.8" groups = ["dev"] -markers = "python_version < \"3.10\"" +markers = "python_version == \"3.9\"" files = [ {file = "zipp-3.19.2-py3-none-any.whl", hash = "sha256:f091755f667055f2d02b32c53771a7a6c8b47e1fdbc4b72a8b9072b3eef8015c"}, {file = "zipp-3.19.2.tar.gz", hash = "sha256:bf1dcf6450f873a13e952a29504887c89e6de7506209e5b1bcc3460135d4de19"}, diff --git a/tests/unit/test_toolkit.py b/tests/unit/test_toolkit.py index 5b4396c..1a56047 100644 --- a/tests/unit/test_toolkit.py +++ b/tests/unit/test_toolkit.py @@ -1223,3 +1223,52 @@ def test_get_all_types(toolkit): def test_get_all_multivalued_slots(toolkit): assert "synonym" in toolkit.get_all_multivalued_slots() assert "id" not in toolkit.get_all_multivalued_slots() + + +def test_get_descendants_with_biolink_prefix(toolkit): + assert 'noncoding RNA product' in toolkit.get_descendants("noncoding RNA product") + assert 'microRNA' in toolkit.get_descendants("noncoding RNA product") + assert 'siRNA' in toolkit.get_descendants("noncoding RNA product") + + assert 'noncoding RNA product' in toolkit.get_descendants("biolink:NoncodingRNAProduct") + assert 'microRNA' in toolkit.get_descendants("biolink:NoncodingRNAProduct") + assert 'siRNA' in toolkit.get_descendants("biolink:NoncodingRNAProduct") + + assert 'microRNA' in toolkit.get_descendants("biolink:MicroRNA") + assert 'siRNA' in toolkit.get_descendants("biolink:SiRNA") + + +def test_get_element_with_biolink_prefix_edge_cases(toolkit): + elem = toolkit.get_element("biolink:NoncodingRNAProduct") + assert elem is not None + assert elem.name == "noncoding RNA product" + + elem = toolkit.get_element("biolink:MicroRNA") + assert elem is not None + assert elem.name == "microRNA" + + elem = toolkit.get_element("biolink:SiRNA") + assert elem is not None + assert elem.name == "siRNA" + + elem = toolkit.get_element("biolink:gene_fusion_with") + assert elem is not None + assert elem.name == "gene_fusion_with" + + elem = toolkit.get_element("biolink:genetic_neighborhood_of") + assert elem is not None + assert elem.name == "genetic_neighborhood_of" + + +def test_get_parent_with_biolink_prefix(toolkit): + parent = toolkit.get_parent('microRNA') + assert parent == 'noncoding RNA product' + + parent_curie = toolkit.get_parent('microRNA', formatted=True) + assert parent_curie == 'biolink:NoncodingRNAProduct' + + parent_from_curie = toolkit.get_parent('biolink:microRNA') + assert parent_from_curie == 'noncoding RNA product' + + parent_from_curie_formatted = toolkit.get_parent('biolink:microRNA', formatted=True) + assert parent_from_curie_formatted == 'biolink:NoncodingRNAProduct'