Skip to content

Commit

Permalink
Add reverse bimap (#136)
Browse files Browse the repository at this point in the history
Closes #135
  • Loading branch information
cthoyt authored Dec 7, 2024
1 parent 3213a88 commit a63ce62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/curies/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit a63ce62

Please sign in to comment.