prefixmaps


Nameprefixmaps JSON
Version 0.2.4 PyPI version JSON
download
home_pageNone
SummaryA python library for retrieving semantic prefix maps
upload_time2024-04-14 23:40:13
maintainerNone
docs_urlNone
authorcmungall
requires_python<4.0,>=3.8
licenseApache-2.0
keywords semantic web bioinformatics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # prefixmaps

A Python library for retrieving semantic prefix maps.

A semantic prefix map will map a a prefix (e.g. `skos`) to a namespace (e.g `http://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 documents
- use in tools that expand CURIEs and short-form identifiers to URIs that can be used as subjects of RDF triples
- coverage of prefixes from multiple different domains
- no single authoritative source of either prefixes or prefix-namespace mappings (clash-resilient)
- preferred semantic namespace is prioritized over web URLs
- authority preferred prefix is prioritized where possible
- each individual prefix map is case-insensitive bijective
- prefix map composition and custom ordering of prefixmaps
- lightweight / low footprint
- fast (TODO)
- network-independence / versioned prefix maps
- optional ability to retrieve latest from external authority on network

What this is NOT intended for:

- a general source of metadata about either prefixes or namespaces
- a mechanism for resolving identifiers to web URLs for humans to find information

## Installation

```shell
pip install prefixmaps
```

## Usage

To use in combination with [curies](https://github.com/cthoyt/curies) library:

```python
from prefixmaps import load_converter
from curies import Converter

converter: 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 resilience

- prefix.cc uses the prefix `geo` for geosparql `http://www.opengis.net/ont/geosparql#`
- OBO uses prefix `GEO` for the [Geographical Entity Ontology](https://obofoundry.org/ontology/geo), expanding to `http://purl.obolibrary.org/obo/GEO_`
- the Bioregistry uses the prefix [`geo`](https://bioregistry.io/registry/geo) for NCBI GEO, and "re-mints" a [`geogeo`](https://bioregistry.io/registry/geogeo) prefix for the OBO ontology

If we prioritize prefix.cc the OBO prefix is ignored:

```python
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 push `bioregistry` at the start of the list then GEOGEO can be used as the prefix for the OBO ontology:

```python
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 of `bioregistry`:

```python
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:

```python
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:

```python
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 versions

By 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:

```python
converter = load_converter("obo", refresh=True)
```

This will perform a fetch from http://obofoundry.org/registry/obo_prefixes.ttl

## Context Metadata

See [contexts.curated.yaml](src/prefixmaps/data/contexts.curated.yaml)

See the description fields

## Repository organization

Data files containing pre-build prefix maps using sources like OBO and Bioregistry are distributed alongside the python

Location:

 * [src/prefixmaps/data](src/prefixmaps/data/)

### CSV field descriptions

1. context: a unique handle for this context. This MUST be the same as the basename of the file
2. prefix: corresponds to http://www.w3.org/ns/shacl#prefix
3. namespace: corresponds to http://www.w3.org/ns/shacl#namespace
4. canonical: true if this satisfies bijectivity


### Refreshing the Data

The data can be refreshed in several ways:

1. Locally, you can use `tox` with:

   ```shell
   pip install tox tox-poetry
   tox -e refresh
   ```
2. Manually running and automatically committing via [this GitHub Actions workflow](https://github.com/linkml/prefixmaps/blob/main/.github/workflows/refresh.yaml).
3. Running makefile (warning, this requires some pre-configuration
    
    ```shell
    make etl
    ```

TODO: make a github action that auto-releases new versions

Note that PRs should *not* be made against the individual CSV files. These are generated from upstream sources.

We temporarily house a small number of curated prefixmaps such as [linked_data.yaml](https://github.com/linkml/prefixmaps/blob/main/src/prefixmaps/data/linked_data.curated.yaml), with the CSV generated from the YAML.

Our goal is to ultimately cede these to upstream sources.



## Requesting new prefixes

This repo is NOT a prefix registry. Its job is simply to aggregate
different prefix maps. Request changes upstream.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "prefixmaps",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "semantic web, bioinformatics",
    "author": "cmungall",
    "author_email": "cjm@berkeleybop.org",
    "download_url": "https://files.pythonhosted.org/packages/7a/31/06f3ac634bb7d89b0263138c7c34d573bf45ea849f396d55cc6cc7a89cbf/prefixmaps-0.2.4.tar.gz",
    "platform": null,
    "description": "# prefixmaps\n\nA Python library for retrieving semantic prefix maps.\n\nA semantic prefix map will map a a prefix (e.g. `skos`) to a namespace (e.g `http://www.w3.org/2004/02/skos/core#`).\n\nThis repository and the corresponding library is designed to satisfy the following requirements:\n\n- generation of prefix maps in headers of RDF documents\n- use in tools that expand CURIEs and short-form identifiers to URIs that can be used as subjects of RDF triples\n- coverage of prefixes from multiple different domains\n- no single authoritative source of either prefixes or prefix-namespace mappings (clash-resilient)\n- preferred semantic namespace is prioritized over web URLs\n- authority preferred prefix is prioritized where possible\n- each individual prefix map is case-insensitive bijective\n- prefix map composition and custom ordering of prefixmaps\n- lightweight / low footprint\n- fast (TODO)\n- network-independence / versioned prefix maps\n- optional ability to retrieve latest from external authority on network\n\nWhat this is NOT intended for:\n\n- a general source of metadata about either prefixes or namespaces\n- a mechanism for resolving identifiers to web URLs for humans to find information\n\n## Installation\n\n```shell\npip install prefixmaps\n```\n\n## Usage\n\nTo use in combination with [curies](https://github.com/cthoyt/curies) library:\n\n```python\nfrom prefixmaps import load_converter\nfrom curies import Converter\n\nconverter: Converter = load_converter([\"obo\", \"bioregistry.upper\", \"linked_data\", \"prefixcc\"])\n\n>>> converter.expand(\"CHEBI:1\")\n'http://purl.obolibrary.org/obo/CHEBI_1'\n>>> converter.expand(\"GEO:1\")\n'http://purl.obolibrary.org/obo/GEO_1'\n>>> converter.expand(\"owl:Class\")\n'http://www.w3.org/2002/07/owl#Class'\n>>> converter.expand(\"FlyBase:FBgn123\")\n'http://identifiers.org/fb/FBgn123'\n```\n\n### Alternate orderings / clash resilience\n\n- prefix.cc uses the prefix `geo` for geosparql `http://www.opengis.net/ont/geosparql#`\n- OBO uses prefix `GEO` for the [Geographical Entity Ontology](https://obofoundry.org/ontology/geo), expanding to `http://purl.obolibrary.org/obo/GEO_`\n- the Bioregistry uses the prefix [`geo`](https://bioregistry.io/registry/geo) for NCBI GEO, and \"re-mints\" a [`geogeo`](https://bioregistry.io/registry/geogeo) prefix for the OBO ontology\n\nIf we prioritize prefix.cc the OBO prefix is ignored:\n\n```python\nconverter = load_converter([\"prefixcc\", \"obo\"])\n\n>>> converter.expand(\"GEO:1\")\n>>> converter.expand(\"geo:1\")\n'http://www.opengis.net/ont/geosparql#1'\n```\n\nEven though prefix expansion is case-sensitive, we intentionally block conflicts that differ only in case.\n\nIf we push `bioregistry` at the start of the list then GEOGEO can be used as the prefix for the OBO ontology:\n\n```python\nconverter = load_converter([\"bioregistry\", \"prefixcc\", \"obo\"])\n\n>>> converter.expand(\"geo:1\")\n'http://identifiers.org/geo/1'\n>>> converter.expand(\"GEO:1\")\n>>> converter.expand(\"GEOGEO:1\")\n'http://purl.obolibrary.org/obo/GEO_1'\n```\n\nNote that from the OBO perspective, GEOGEO is non-canonical.\n\nWe get similar results using the upper-normalized variant of `bioregistry`:\n\n```python\nconverter = load_converter([\"bioregistry.upper\", \"prefixcc\", \"obo\"])\n\n>>> converter.expand(\"GEO:1\")\n'http://identifiers.org/geo/1'\n>>> converter.expand(\"geo:1\")\n>>> converter.expand(\"GEOGEO:1\")\n'http://purl.obolibrary.org/obo/GEO_1'\n```\n\nUsers of OBO ontologies will want to place OBO at the start of the list:\n\n```python\nconverter = load_converter([\"obo\", \"bioregistry.upper\", \"prefixcc\"])\n\n>>> converter.expand(\"geo:1\")\n>>> converter.expand(\"GEO:1\")\n'http://purl.obolibrary.org/obo/GEO_1'\n>>> converter.expand(\"GEOGEO:1\")\n```\n\nNote under this ordering there is no prefix for NCBI GEO. This is not\na major limitation as there is no canonical semantic rendering of NCBI\nGEO. This could be added in future with a unique OBO prefix.\n\nYou can use the ready-made \"merged\" prefix set, which prioritizes OBO:\n\n```python\nconverter = load_converter(\"merged\")\n\n>>> converter.expand(\"GEOGEO:1\")\n>>> converter.expand(\"GEO:1\")\n'http://purl.obolibrary.org/obo/GEO_1'\n>>> converter.expand(\"geo:1\")\n```\n\n### Network independence and requesting latest versions\n\nBy default, this will make use of metadata distributed alongside the package. This has certain advantages in terms\nof reproducibility, but it means if a new ontology or prefix is added to an upstream source you won't see this.\n\nTo refresh and use the latest upstream:\n\n```python\nconverter = load_converter(\"obo\", refresh=True)\n```\n\nThis will perform a fetch from http://obofoundry.org/registry/obo_prefixes.ttl\n\n## Context Metadata\n\nSee [contexts.curated.yaml](src/prefixmaps/data/contexts.curated.yaml)\n\nSee the description fields\n\n## Repository organization\n\nData files containing pre-build prefix maps using sources like OBO and Bioregistry are distributed alongside the python\n\nLocation:\n\n * [src/prefixmaps/data](src/prefixmaps/data/)\n\n### CSV field descriptions\n\n1. context: a unique handle for this context. This MUST be the same as the basename of the file\n2. prefix: corresponds to http://www.w3.org/ns/shacl#prefix\n3. namespace: corresponds to http://www.w3.org/ns/shacl#namespace\n4. canonical: true if this satisfies bijectivity\n\n\n### Refreshing the Data\n\nThe data can be refreshed in several ways:\n\n1. Locally, you can use `tox` with:\n\n   ```shell\n   pip install tox tox-poetry\n   tox -e refresh\n   ```\n2. Manually running and automatically committing via [this GitHub Actions workflow](https://github.com/linkml/prefixmaps/blob/main/.github/workflows/refresh.yaml).\n3. Running makefile (warning, this requires some pre-configuration\n    \n    ```shell\n    make etl\n    ```\n\nTODO: make a github action that auto-releases new versions\n\nNote that PRs should *not* be made against the individual CSV files. These are generated from upstream sources.\n\nWe temporarily house a small number of curated prefixmaps such as [linked_data.yaml](https://github.com/linkml/prefixmaps/blob/main/src/prefixmaps/data/linked_data.curated.yaml), with the CSV generated from the YAML.\n\nOur goal is to ultimately cede these to upstream sources.\n\n\n\n## Requesting new prefixes\n\nThis repo is NOT a prefix registry. Its job is simply to aggregate\ndifferent prefix maps. Request changes upstream.\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A python library for retrieving semantic prefix maps",
    "version": "0.2.4",
    "project_urls": {
        "Bug Tracker": "https://github.com/linkml/prefixmaps/issues",
        "homepage": "https://github.com/linkml/prefixmaps",
        "repository": "https://github.com/linkml/prefixmaps"
    },
    "split_keywords": [
        "semantic web",
        " bioinformatics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cc8d74e7f4f183ca0a660f9aea5eff2355384d405bebc67b73314f3c075abb9",
                "md5": "70536c5ff794ba31b8ad04c585bd2cb0",
                "sha256": "89bf0e6fb08c276f754f9624c42adf2e87c64ee92a3dde1f7eff01f22d85b512"
            },
            "downloads": -1,
            "filename": "prefixmaps-0.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "70536c5ff794ba31b8ad04c585bd2cb0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 746669,
            "upload_time": "2024-04-14T23:40:11",
            "upload_time_iso_8601": "2024-04-14T23:40:11.613874Z",
            "url": "https://files.pythonhosted.org/packages/6c/c8/d74e7f4f183ca0a660f9aea5eff2355384d405bebc67b73314f3c075abb9/prefixmaps-0.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a3106f3ac634bb7d89b0263138c7c34d573bf45ea849f396d55cc6cc7a89cbf",
                "md5": "851f9f23e05c4439e6a028c04562f66f",
                "sha256": "ae86a1b31189d0516d199756d5808f75f44b39e86546c356cc78c0fe8d2078af"
            },
            "downloads": -1,
            "filename": "prefixmaps-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "851f9f23e05c4439e6a028c04562f66f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 701864,
            "upload_time": "2024-04-14T23:40:13",
            "upload_time_iso_8601": "2024-04-14T23:40:13.829715Z",
            "url": "https://files.pythonhosted.org/packages/7a/31/06f3ac634bb7d89b0263138c7c34d573bf45ea849f396d55cc6cc7a89cbf/prefixmaps-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-14 23:40:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "linkml",
    "github_project": "prefixmaps",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "prefixmaps"
}
        
Elapsed time: 0.21859s