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

NamespaceManager.expand_curie() does not handle the default prefix #2348

Closed
jclerman opened this issue Apr 10, 2023 · 1 comment · Fixed by #2365
Closed

NamespaceManager.expand_curie() does not handle the default prefix #2348

jclerman opened this issue Apr 10, 2023 · 1 comment · Fixed by #2365
Labels
bug Something isn't working core Relates to core functionality of RDFLib, i.e. `rdflib.{graph,store,term}`

Comments

@jclerman
Copy link
Contributor

I have found that rdflib's handling of cURIEs for entities within an ontology's own namespace is somewhat difficult.

One of the issues is already documented (#2077) - namely, that NamesapceManager does not handle mapping multiple prefixes to a single URI.

I also see that a cURIE like :my_class is rejected by expand_curie() as invalid. It seems like it should be valid though, based on https://www.w3.org/TR/curie/#s_syntax, in particular

A host language MAY declare a default prefix value, or MAY provide a mechanism for defining a default prefix value. In such a host language, when the prefix is omitted from a CURIE, the default prefix value MUST be used.

rdflib does record the default prefix value, mapping it to the empty string, as can be seen by examining NamespaceManager.namespaces() - but that default value is never used in expand_curie(). The problematic code appears to be

if len(parts) != 2 or len(parts[0]) < 1:
, which requires that the prefix in CURIE to be expanded has non-zero length - but that's in conflict with the (correct) storage of the default prefix in namespaces().

The two issues make it difficult (impossible?) to expand a CURIE for an entity in the default namespace of an ontology:

Is there a workaround via which I could write a CURIE that maps to an item in a parsed ontology (e.g. one stored in RDF/XML), such that rdflib could expand it to the correct URI?

@aucampia
Copy link
Member

Is there a workaround via which I could write a CURIE that maps to an item in a parsed ontology (e.g. one stored in RDF/XML), such that rdflib could expand it to the correct URI?

I'm not aware of any, I will look at the multiple prefixes issue this month if I get time, though I'm going to try get our test-suite for JSON-LD up to scratch first to prepare for PyLD integration with RDFLib.

I also see that a cURIE like :my_class is rejected by expand_curie() as invalid. It seems like it should be valid though, based on https://www.w3.org/TR/curie/#s_syntax, in particular

It seems like it should be valid, and think just fixing expand_curie to allow this should be uncontroversial. I'm a bit unsure if the way RDFLib stores the default prefix is optimal, but it is what it is, and making it work for expanding curies seems pretty reasonable.

@aucampia aucampia added bug Something isn't working core Relates to core functionality of RDFLib, i.e. `rdflib.{graph,store,term}` labels Apr 11, 2023
jclerman added a commit to jclerman/rdflib that referenced this issue Apr 18, 2023
…ceManager.curie()

 - including tests for both methods, including expected failure-cases for expand_curie().
 - this should fix RDFLib#2348
 - also addresses the converse case from RDFLib#2348, mapping a URI in the default namespace to a CURIE,
   using a new method to avoid a breaking change to qname().
aucampia pushed a commit that referenced this issue May 21, 2023
Added a `curie` method to `NamespaceManager`, which can be used to generate a
CURIE from a URI.

Other changes:

- Fixed `NamespaceManager.expand_curie` to work with CURIES that have blank
  prefixes (e.g. `:something`), which are valid according to [CURIE Syntax
  1.0](https://www.w3.org/TR/2010/NOTE-curie-20101216/).
- Added a test to confirm <#2077>.

Fixes <#2348>.

---------
Co-authored-by: Iwan Aucamp <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core Relates to core functionality of RDFLib, i.e. `rdflib.{graph,store,term}`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants