Repository: biopragmatics/bioregistry

Issue:
Rewiring from prescriptive context is ignored

Comments:

Patch:
diff --git a/exports/contexts/obo.context.jsonld b/exports/contexts/obo.context.jsonld
index 87f6613ff..1ec1187ef 100644
--- a/exports/contexts/obo.context.jsonld
+++ b/exports/contexts/obo.context.jsonld
@@ -254,7 +254,7 @@
         "PLANA": "http://purl.obolibrary.org/obo/PLANA_",
         "PLANP": "http://purl.obolibrary.org/obo/PLANP_",
         "PLO": "http://purl.obolibrary.org/obo/PLO_",
-        "PMID": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
+        "PMID": "https://www.ncbi.nlm.nih.gov/pubmed/",
         "PO": "http://purl.obolibrary.org/obo/PO_",
         "PORO": "http://purl.obolibrary.org/obo/PORO_",
         "PPO": "http://purl.obolibrary.org/obo/PPO_",
diff --git a/exports/contexts/obo.context.ttl b/exports/contexts/obo.context.ttl
index b2a060a28..5f6b1ca5d 100644
--- a/exports/contexts/obo.context.ttl
+++ b/exports/contexts/obo.context.ttl
@@ -257,7 +257,7 @@
     [ sh:prefix "PLANA" ; sh:namespace "http://purl.obolibrary.org/obo/PLANA_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
     [ sh:prefix "PLANP" ; sh:namespace "http://purl.obolibrary.org/obo/PLANP_"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
     [ sh:prefix "PLO" ; sh:namespace "http://purl.obolibrary.org/obo/PLO_"^^xsd:anyURI  ],
-    [ sh:prefix "PMID" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
+    [ sh:prefix "PMID" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
     [ sh:prefix "PO" ; sh:namespace "http://purl.obolibrary.org/obo/PO_"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
     [ sh:prefix "PORO" ; sh:namespace "http://purl.obolibrary.org/obo/PORO_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
     [ sh:prefix "PPO" ; sh:namespace "http://purl.obolibrary.org/obo/PPO_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
diff --git a/exports/contexts/obo.epm.json b/exports/contexts/obo.epm.json
index 957e24d25..a784428fa 100644
--- a/exports/contexts/obo.epm.json
+++ b/exports/contexts/obo.epm.json
@@ -4366,7 +4366,7 @@
             "pmid",
             "pubmed"
         ],
-        "uri_prefix": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
+        "uri_prefix": "https://www.ncbi.nlm.nih.gov/pubmed/",
         "uri_prefix_synonyms": [
             "http://bio2rdf.org/pubmed:",
             "http://bioregistry.io/MEDLINE:",
@@ -4382,6 +4382,7 @@
             "http://pubmed.ncbi.nlm.nih.gov/",
             "http://purl.uniprot.org/citations/",
             "http://purl.uniprot.org/pubmed/",
+            "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
             "http://scholia.toolforge.org/pubmed/",
             "http://www.hubmed.org/display.cgi?uids=",
             "http://www.ncbi.nlm.nih.gov/pubmed/",
@@ -4401,8 +4402,7 @@
             "https://purl.uniprot.org/pubmed/",
             "https://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
             "https://scholia.toolforge.org/pubmed/",
-            "https://www.hubmed.org/display.cgi?uids=",
-            "https://www.ncbi.nlm.nih.gov/pubmed/"
+            "https://www.hubmed.org/display.cgi?uids="
         ]
     },
     {
diff --git a/exports/contexts/obo_synonyms.context.jsonld b/exports/contexts/obo_synonyms.context.jsonld
index 5ec744242..a6ccfc1e3 100644
--- a/exports/contexts/obo_synonyms.context.jsonld
+++ b/exports/contexts/obo_synonyms.context.jsonld
@@ -297,7 +297,7 @@
         "MC": "http://purl.obolibrary.org/obo/MC_",
         "MCO": "http://purl.obolibrary.org/obo/MCO_",
         "MCRO": "http://purl.obolibrary.org/obo/MCRO_",
-        "MEDLINE": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
+        "MEDLINE": "https://www.ncbi.nlm.nih.gov/pubmed/",
         "MEDRA": "http://purl.bioontology.org/ontology/MDRFRE/",
         "MESH": "http://id.nlm.nih.gov/mesh/",
         "MESHA": "http://id.nlm.nih.gov/mesh/",
@@ -437,7 +437,7 @@
         "PLO": "http://purl.obolibrary.org/obo/PLO_",
         "PMC": "http://europepmc.org/articles/",
         "PMCID": "http://europepmc.org/articles/",
-        "PMID": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
+        "PMID": "https://www.ncbi.nlm.nih.gov/pubmed/",
         "PO": "http://purl.obolibrary.org/obo/PO_",
         "PORO": "http://purl.obolibrary.org/obo/PORO_",
         "PPO": "http://purl.obolibrary.org/obo/PPO_",
@@ -459,7 +459,7 @@
         "Progenetix": "https://progenetix.org/services/ids/",
         "PuRO": "http://purl.org/spar/pro/",
         "PubChem_Compound_CID": "http://rdf.ncbi.nlm.nih.gov/pubchem/compound/CID",
-        "PubMed": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
+        "PubMed": "https://www.ncbi.nlm.nih.gov/pubmed/",
         "Pubchem": "http://rdf.ncbi.nlm.nih.gov/pubchem/compound/CID",
         "RBO": "http://purl.obolibrary.org/obo/RBO_",
         "RCSB_PDB": "https://rdf.wwpdb.org/pdb/",
@@ -1657,7 +1657,7 @@
         "pmap.substratedb": "https://identifiers.org/pmap.substratedb:",
         "pmc": "http://europepmc.org/articles/",
         "pmdb": "https://bioinformatics.cineca.it/PMDB/user//search.php?idsearch=",
-        "pmid": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
+        "pmid": "https://www.ncbi.nlm.nih.gov/pubmed/",
         "pmp": "http://purl.uniprot.org/uniprot/",
         "pmr": "https://models.physiomeproject.org/exposure/",
         "pmr.workspace": "https://models.physiomeproject.org/workspace/",
@@ -1697,7 +1697,7 @@
         "pubchem_id": "http://rdf.ncbi.nlm.nih.gov/pubchem/compound/CID",
         "publons.publication": "https://publons.com/publon/",
         "publons.researcher": "https://publons.com/researcher/",
-        "pubmed": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
+        "pubmed": "https://www.ncbi.nlm.nih.gov/pubmed/",
         "px": "http://proteomecentral.proteomexchange.org/cgi/GetDataset?ID=",
         "pypi": "https://pypi.org/project/",
         "qb": "http://purl.org/linked-data/cube#",
diff --git a/exports/contexts/obo_synonyms.context.ttl b/exports/contexts/obo_synonyms.context.ttl
index 7a1617eb6..2dc12eb7c 100644
--- a/exports/contexts/obo_synonyms.context.ttl
+++ b/exports/contexts/obo_synonyms.context.ttl
@@ -338,11 +338,11 @@
     [ sh:prefix "PLANA" ; sh:namespace "http://purl.obolibrary.org/obo/PLANA_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
     [ sh:prefix "PLANP" ; sh:namespace "http://purl.obolibrary.org/obo/PLANP_"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
     [ sh:prefix "PLO" ; sh:namespace "http://purl.obolibrary.org/obo/PLO_"^^xsd:anyURI  ],
-    [ sh:prefix "PMID" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
-    [ sh:prefix "MEDLINE" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
-    [ sh:prefix "PubMed" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
-    [ sh:prefix "pmid" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
-    [ sh:prefix "pubmed" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
+    [ sh:prefix "PMID" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
+    [ sh:prefix "MEDLINE" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
+    [ sh:prefix "PubMed" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
+    [ sh:prefix "pmid" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
+    [ sh:prefix "pubmed" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
     [ sh:prefix "PO" ; sh:namespace "http://purl.obolibrary.org/obo/PO_"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
     [ sh:prefix "PORO" ; sh:namespace "http://purl.obolibrary.org/obo/PORO_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
     [ sh:prefix "PPO" ; sh:namespace "http://purl.obolibrary.org/obo/PPO_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
diff --git a/src/bioregistry/record_accumulator.py b/src/bioregistry/record_accumulator.py
index 1dad79705..ef9b06ea5 100644
--- a/src/bioregistry/record_accumulator.py
+++ b/src/bioregistry/record_accumulator.py
@@ -117,6 +117,7 @@ def get_converter(
     strict: bool = False,
     blacklist: Optional[Collection[str]] = None,
     remapping: Optional[Mapping[str, str]] = None,
+    rewiring: Optional[Mapping[str, str]] = None,
 ) -> Converter:
     """Generate a converter from resources."""
     records = _get_records(
@@ -130,6 +131,8 @@ def get_converter(
     converter = curies.Converter(records)
     if remapping:
         converter = curies.remap_curie_prefixes(converter, remapping)
+    if rewiring:
+        converter = curies.rewire(converter, rewiring)
     return converter
 
 
diff --git a/src/bioregistry/resource_manager.py b/src/bioregistry/resource_manager.py
index 279fc8408..d1c3c0a39 100644
--- a/src/bioregistry/resource_manager.py
+++ b/src/bioregistry/resource_manager.py
@@ -640,6 +640,7 @@ class Manager:
         include_prefixes: bool = False,
         strict: bool = False,
         remapping: Optional[Mapping[str, str]] = None,
+        rewiring: Optional[Mapping[str, str]] = None,
         blacklist: Optional[typing.Collection[str]] = None,
     ) -> curies.Converter:
         """Get a converter from this manager.
@@ -657,6 +658,7 @@ class Manager:
             If true, errors on URI prefix collisions. If false, sends logging
             and skips them.
         :param remapping: A mapping from bioregistry prefixes to preferred prefixes.
+        :param rewiring: A mapping from bioregistry prefixes to new URI prefixes.
         :param blacklist:
             A collection of prefixes to skip
 
@@ -677,6 +679,7 @@ class Manager:
             strict=strict,
             blacklist=blacklist,
             remapping=remapping,
+            rewiring=rewiring,
         )
         return converter
 
@@ -727,6 +730,7 @@ class Manager:
         prefix_priority: Optional[Sequence[str]] = None,
         include_synonyms: bool = False,
         remapping: Optional[Mapping[str, str]] = None,
+        rewiring: Optional[Mapping[str, str]] = None,
         blacklist: Optional[typing.Collection[str]] = None,
     ) -> Mapping[str, str]:
         """Get a mapping from Bioregistry prefixes to their URI prefixes .
@@ -740,6 +744,7 @@ class Manager:
         :param include_synonyms: Should synonyms of each prefix also be included as additional prefixes, but with
             the same URI prefix?
         :param remapping: A mapping from Bioregistry prefixes to preferred prefixes.
+        :param rewiring: A mapping from Bioregistry prefixes to URI prefixes.
         :param blacklist: Prefixes to skip
         :return: A mapping from prefixes to URI prefixes.
         """
@@ -747,15 +752,10 @@ class Manager:
             prefix_priority=prefix_priority,
             uri_prefix_priority=uri_prefix_priority,
             remapping=remapping,
+            rewiring=rewiring,
             blacklist=blacklist,
         )
-        rv = {}
-        for record in converter.records:
-            rv[record.prefix] = record.uri_prefix
-            if include_synonyms:
-                for prefix in record.prefix_synonyms:
-                    rv[prefix] = record.uri_prefix
-        return rv
+        return converter.prefix_map if include_synonyms else converter.bimap
 
     def get_curie_pattern(self, prefix: str, *, use_preferred: bool = False) -> Optional[str]:
         r"""Get the CURIE pattern for this resource.
@@ -1586,6 +1586,7 @@ class Manager:
             uri_prefix_priority=context.uri_prefix_priority,
             strict=strict,
             remapping=context.prefix_remapping,
+            rewiring=context.custom_prefix_map,
             blacklist=context.blacklist,
             include_prefixes=include_prefixes,
         )
@@ -1606,6 +1607,7 @@ class Manager:
             prefix_priority=context.prefix_priority,
             include_synonyms=include_synonyms,
             blacklist=context.blacklist,
+            rewiring=context.custom_prefix_map,
         )
         prescriptive_pattern_map = self.get_pattern_map(
             remapping=context.prefix_remapping,


Test patch:
diff --git a/tests/test_contexts.py b/tests/test_contexts.py
index 7428da168..dab8798b5 100644
--- a/tests/test_contexts.py
+++ b/tests/test_contexts.py
@@ -46,6 +46,7 @@ class TestContexts(unittest.TestCase):
         self.assertEqual(f"{p}/FBcv_", prefix_map["FBcv"])
         self.assertIn("GEO", prefix_map)
         self.assertEqual(f"{p}/GEO_", prefix_map["GEO"])
+        self.assertEqual("https://www.ncbi.nlm.nih.gov/pubmed/", prefix_map["PMID"])
 
         self.assertNotIn("biomodels.kisao", prefix_map)
 
@@ -64,6 +65,7 @@ class TestContexts(unittest.TestCase):
         self.assertEqual("Orphanet", converter.standardize_prefix("ordo"))
         self.assertEqual("GO", converter.standardize_prefix("GO"))
         self.assertEqual("GO", converter.standardize_prefix("gomf"))
+        self.assertEqual("https://www.ncbi.nlm.nih.gov/pubmed/", converter.bimap["PMID"])
         # FIXME later, handle adding canonical bioregistry prefix
         #  as synonym when non-default prefix priority ordering is given
         # self.assertEqual("GO", converter.standardize_prefix("go"))