Package: prefixmaps
prefixmapsA Python library for retrieving semantic prefix maps.A semantic prefix map will map a a prefix (e.g.skos) to a namespace (e.ghttp://www.w3.org/2004/02/skos/core#).This repository and the corresponding library is designed to satisfy the following requirements:generation of prefix maps in headers of RDF documentsuse in tools that expand CURIEs and short-form identifiers to URIs that can be used as subjects of RDF triplescoverage of prefixes from multiple different domainsno single authoritative source of either prefixes or prefix-namespace mappings (clash-resilient)preferred semantic namespace is prioritized over web URLsauthority preferred prefix is prioritized where possibleeach individual prefix map is case-insensitive bijectiveprefix map composition and custom ordering of prefixmapslightweight / low footprintfast (TODO)network-independence / versioned prefix mapsoptional ability to retrieve latest from external authority on networkWhat this is NOT intended for:a general source of metadata about either prefixes or namespacesa mechanism for resolving identifiers to web URLs for humans to find informationInstallationpipinstallprefixmapsUsageTo use in combination withcurieslibrary:fromprefixmapsimportload_converterfromcuriesimportConverterconverter:Converter=load_converter(["obo","bioregistry.upper","linked_data","prefixcc"])>>>converter.expand("CHEBI:1")'http://purl.obolibrary.org/obo/CHEBI_1'>>>converter.expand("GEO:1")'http://purl.obolibrary.org/obo/GEO_1'>>>converter.expand("owl:Class")'http://www.w3.org/2002/07/owl#Class'>>>converter.expand("FlyBase:FBgn123")'http://identifiers.org/fb/FBgn123'Alternate orderings / clash resilienceprefix.cc uses the prefixgeofor geosparqlhttp://www.opengis.net/ont/geosparql#OBO uses prefixGEOfor theGeographical Entity Ontology, expanding tohttp://purl.obolibrary.org/obo/GEO_the Bioregistry uses the prefixgeofor NCBI GEO, and "re-mints" ageogeoprefix for the OBO ontologyIf we prioritize prefix.cc the OBO prefix is ignored:converter=load_converter(["prefixcc","obo"])>>>converter.expand("GEO:1")>>>converter.expand("geo:1")'http://www.opengis.net/ont/geosparql#1'Even though prefix expansion is case-sensitive, we intentionally block conflicts that differ only in case.If we pushbioregistryat the start of the list then GEOGEO can be used as the prefix for the OBO ontology:converter=load_converter(["bioregistry","prefixcc","obo"])>>>converter.expand("geo:1")'http://identifiers.org/geo/1'>>>converter.expand("GEO:1")>>>converter.expand("GEOGEO:1")'http://purl.obolibrary.org/obo/GEO_1'Note that from the OBO perspective, GEOGEO is non-canonical.We get similar results using the upper-normalized variant ofbioregistry:converter=load_converter(["bioregistry.upper","prefixcc","obo"])>>>converter.expand("GEO:1")'http://identifiers.org/geo/1'>>>converter.expand("geo:1")>>>converter.expand("GEOGEO:1")'http://purl.obolibrary.org/obo/GEO_1'Users of OBO ontologies will want to place OBO at the start of the list:converter=load_converter(["obo","bioregistry.upper","prefixcc"])>>>converter.expand("geo:1")>>>converter.expand("GEO:1")'http://purl.obolibrary.org/obo/GEO_1'>>>converter.expand("GEOGEO:1")Note under this ordering there is no prefix for NCBI GEO. This is not
a major limitation as there is no canonical semantic rendering of NCBI
GEO. This could be added in future with a unique OBO prefix.You can use the ready-made "merged" prefix set, which prioritizes OBO:converter=load_converter("merged")>>>converter.expand("GEOGEO:1")>>>converter.expand("GEO:1")'http://purl.obolibrary.org/obo/GEO_1'>>>converter.expand("geo:1")Network independence and requesting latest versionsBy default, this will make use of metadata distributed alongside the package. This has certain advantages in terms
of reproducibility, but it means if a new ontology or prefix is added to an upstream source you won't see this.To refresh and use the latest upstream:converter=load_converter("obo",refresh=True)This will perform a fetch fromhttp://obofoundry.org/registry/obo_prefixes.ttlContext MetadataSeecontexts.curated.yamlSee the description fieldsRepository organizationData files containing pre-build prefix maps using sources like OBO and Bioregistry are distributed alongside the pythonLocation:src/prefixmaps/dataCSV field descriptionscontext: a unique handle for this context. This MUST be the same as the basename of the fileprefix: corresponds tohttp://www.w3.org/ns/shacl#prefixnamespace: corresponds tohttp://www.w3.org/ns/shacl#namespacecanonical: true if this satisfies bijectivityRefreshing the DataThe data can be refreshed in several ways:Locally, you can usetoxwith:pipinstalltoxtox-poetry
tox-erefreshManually running and automatically committing viathis GitHub Actions workflow.Running makefile (warning, this requires some pre-configurationmakeetlTODO: make a github action that auto-releases new versionsNote that PRs shouldnotbe made against the individual CSV files. These are generated from upstream sources.We temporarily house a small number of curated prefixmaps such aslinked_data.yaml, with the CSV generated from the YAML.Our goal is to ultimately cede these to upstream sources.Requesting new prefixesThis repo is NOT a prefix registry. Its job is simply to aggregate
different prefix maps. Request changes upstream.