Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement URI or CURIE functionality #92

Merged
merged 11 commits into from
Nov 13, 2023
Merged

Implement URI or CURIE functionality #92

merged 11 commits into from
Nov 13, 2023

Conversation

cthoyt
Copy link
Member

@cthoyt cthoyt commented Nov 6, 2023

The Converter.expand function turns a CURIE into a URI. This PR implements Converter.expand_or_standardize, which works like the normal Converter.expand, but if a URI is given, then it standardizes it and returns it. The other mechanics for "strict" and "passthrough" work the same.

This PR also implements Converter.compress_or_standardize as a counterpart for Converter.compress

Demo

The expansion and compression demos use a very simple extended prefix map:

from curies import Converter, Record

converter = Converter.from_extended_prefix_map([
    Record(
        prefix="CHEBI",
        prefix_synonyms=["chebi"],
        uri_prefix="http://purl.obolibrary.org/obo/CHEBI_",
        uri_prefix_synonyms=["https://identifiers.org/chebi:"],
    ),
])

Expansion

# Expand CURIEs
>>> converter.expand_or_standardize("CHEBI:138488")
'http://purl.obolibrary.org/obo/CHEBI_138488'
>>> converter.expand_or_standardize("chebi:138488")
'http://purl.obolibrary.org/obo/CHEBI_138488'

# Standardize URIs
>>> converter.expand_or_standardize("http://purl.obolibrary.org/obo/CHEBI_138488")
'http://purl.obolibrary.org/obo/CHEBI_138488'
>>> converter.expand_or_standardize("https://identifiers.org/chebi:138488")
'http://purl.obolibrary.org/obo/CHEBI_138488'

# Handle cases that aren't valid w.r.t. the converter
>>> converter.expand_or_standardize("missing:0000000")
>>> converter.expand_or_standardize("https://example.com/missing:0000000")

Compression

# Compress URIs
>>> converter.compress_or_standardize("http://purl.obolibrary.org/obo/CHEBI_138488")
'CHEBI:138488'
>>> converter.compress_or_standardize("https://identifiers.org/chebi:138488")
'CHEBI:138488'

# Standardize CURIEs
>>> converter.compress_or_standardize("CHEBI:138488")
'CHEBI:138488'
>>> converter.compress_or_standardize("chebi:138488")
'CHEBI:138488'

# Handle cases that aren't valid w.r.t. the converter
>>> converter.compress_or_standardize("missing:0000000")
>>> converter.compress_or_standardize("https://example.com/missing:0000000")

Known Use Cases

TODO

  • I am looking for a better name for this before merging it.
  • Add docs for bulk operations
  • Add corresponding compress operation (after picking a better nomenclature)

@cthoyt cthoyt changed the title Implement ambiguous expansion functionality Implement URI or CURIE to URI functionality Nov 6, 2023
@cthoyt cthoyt changed the title Implement URI or CURIE to URI functionality Implement URI or CURIE functionality Nov 13, 2023
@cthoyt cthoyt marked this pull request as ready for review November 13, 2023 23:26
@cthoyt cthoyt merged commit 8351f92 into main Nov 13, 2023
8 checks passed
@cthoyt cthoyt deleted the uri-or-curie branch November 13, 2023 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant