You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
, 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:
The default namespace prefix is inaccessible per the above
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?
The text was updated successfully, but these errors were encountered:
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
added
bug
Something isn't working
core
Relates to core functionality of RDFLib, i.e. `rdflib.{graph,store,term}`
labels
Apr 11, 2023
…ceManager.curie()
- including tests for both methods, including expected failure-cases for expand_curie().
- this should fixRDFLib#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().
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]>
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 byexpand_curie()
as invalid. It seems like it should be valid though, based on https://www.w3.org/TR/curie/#s_syntax, in particularrdflib 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 berdflib/rdflib/namespace/__init__.py
Line 618 in 5c3c78a
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?
The text was updated successfully, but these errors were encountered: