NamespaceManager.expand_curie() does not handle the default prefix · Issue #2348 · RDFLib/rdflib (original) (raw)

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?