From 51026022cbedc720d5b47f5888d296630ca3af1d Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Mon, 15 Jan 2024 11:39:53 +0100 Subject: [PATCH] Update api.py --- src/curies/api.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/curies/api.py b/src/curies/api.py index 0cbfe2b..02026b1 100644 --- a/src/curies/api.py +++ b/src/curies/api.py @@ -48,7 +48,10 @@ "DuplicateValueError", "DuplicatePrefixes", "DuplicateURIPrefixes", + # Utilities "chain", + "clean_prefix_map", + # Loaders "load_extended_prefix_map", "load_prefix_map", "load_jsonld_context", @@ -2194,7 +2197,22 @@ def _get_shacl_line(prefix: str, uri_prefix: str, pattern: Optional[str] = None) def clean_prefix_map(prefix_map: Mapping[str, str]) -> List[Record]: - """Convert a problematic prefix map (i.e., not bijective) into a list of records.""" + """Convert a problematic prefix map (i.e., not bijective) into a list of records. + + :param prefix_map: A mapping whose keys represent CURIE prefixes and values represent URI prefixes + :return: A list of :class:`curies.Record` objects that together constitute an extended prefix map + + >>> from curies import Converter, clean_prefix_map + >>> pm = {"a": "https://example.com/a/", "b": "https://example.com/a/"} + >>> records = clean_prefix_map(pm) + >>> converter = Converter(records) + >>> converter.expand("a:1") + 'https://example.com/a/1' + >>> converter.expand("b:1") + 'https://example.com/a/1' + >>> converter.compress("https://example.com/a/1") + 'a:1' + """ dd = defaultdict(list) for curie_prefix, uri_prefix in prefix_map.items(): dd[uri_prefix].append(curie_prefix)