Skip to content

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

Open
cthoyt wants to merge 28 commits into
mainfrom
add-w3c-strict
Open

Add option for checking w3c specification on expand()#104
cthoyt wants to merge 28 commits into
mainfrom
add-w3c-strict

Conversation

@cthoyt
Copy link
Copy Markdown
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
@cthoyt cthoyt mentioned this pull request Dec 19, 2024
4 tasks
cthoyt added a commit that referenced this pull request Dec 19, 2024
This PR splits out some of #104 to implement regular expressions for
testing prefix and CURIE validity against the W3C standard
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