From a63ce627d666ecec82f1ad1d1a6ef8e189c9b8d5 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sat, 7 Dec 2024 12:46:19 +0100 Subject: [PATCH] Add reverse bimap (#136) Closes #135 --- src/curies/api.py | 5 +++++ tests/test_api.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/curies/api.py b/src/curies/api.py index b11e62e..39d4573 100644 --- a/src/curies/api.py +++ b/src/curies/api.py @@ -566,6 +566,11 @@ def bimap(self) -> Mapping[str, str]: """Get the bijective mapping between CURIE prefixes and URI prefixes.""" return {r.prefix: r.uri_prefix for r in self.records} + @property + def reverse_bimap(self) -> Mapping[str, str]: + """Get the bijective mapping between URI CURIE prefixes and CURIE prefixes.""" + return {r.uri_prefix: r.prefix for r in self.records} + def _match_record( self, external: Record, case_sensitive: bool = True ) -> Mapping[RecordKey, list[str]]: diff --git a/tests/test_api.py b/tests/test_api.py index 01256c1..9e1d94b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -396,7 +396,9 @@ def test_convert(self): def _assert_convert(self, converter: Converter): self.assertIn("GO", converter.prefix_map) self.assertIn("GO", converter.bimap) + self.assertIn("GO", converter.reverse_bimap.values()) self.assertIn("http://purl.obolibrary.org/obo/GO_", converter.reverse_prefix_map) + self.assertIn("http://purl.obolibrary.org/obo/GO_", converter.reverse_bimap) self.assertIn("http://purl.obolibrary.org/obo/GO_", converter.trie) self.assertIn("http://purl.obolibrary.org/obo/GO_", converter.bimap.values()) for curie, uri in [