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

Add option for checking w3c specification on expand() #104

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

cthoyt
Copy link
Member

@cthoyt cthoyt commented Feb 28, 2024

References #103.

This PR adds a w3c_validation flag to instantiation of a converter and to Converter.expand() that turns on W3C CURIE specification validation. For now, it's not a "true" implementation of the W3C standard since this will take a huge amount of effort to implement and test (for, IMO, small returns), but it hits the main pain points Chris mentioned in #103 (specifically, the square bracket issue).

This PR also begins developing a benchmarking suite of CURIEs (both valid and invalid)

Demo

This can be used when expanding a CURIE:

import curies

converter = curies.Converter.from_prefix_map({
    "smiles": "https://bioregistry.io/smiles:",
})

>>> converter.expand("smiles:CC(=O)NC([H])(C)C(=O)O")
https://bioregistry.io/smiles:CC(=O)NC([H])(C)C(=O)O

>>> converter.expand("smiles:CC(=O)NC([H])(C)C(=O)O", w3c_validation=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/cthoyt/dev/curies/src/curies/api.py", line 1362, in expand
    raise W3CValidationError(f"CURIE is not valid under W3C spec: {curie}")
W3CValidationError: CURIE is not valid under W3C spec: smiles:CC(=O)NC([H])(C)C(=O)O

This can be used when instantiating a converter:

import curies

>>> curies.Converter.from_prefix_map(
...     {"4dn.biosource": "https://data.4dnucleome.org/biosources/"},
...     w3c_validation=True,
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/cthoyt/dev/curies/src/curies/api.py", line 816, in from_prefix_map
    return cls(
           ^^^^
  File "/Users/cthoyt/dev/curies/src/curies/api.py", line 527, in __init__
    raise W3CValidationError(f"Records not conforming to W3C:\n\n{msg}")
curies.api.W3CValidationError: Records not conforming to W3C:

  - Record(prefix='4dn.biosource', uri_prefix='https://data.4dnucleome.org/biosources/', prefix_synonyms=[], uri_prefix_synonyms=[], pattern=None)

Caveats

@cthoyt cthoyt marked this pull request as ready for review March 11, 2024 10:11
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