RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.18k stars 558 forks source link

jsonld - Improve handling of URNs in norm_url #2892

Closed avillar closed 2 months ago

avillar commented 3 months ago

Summary of changes

Improve handling of URNs in JSON-LD's norm_url. This mainly makes it possible to use URNs in @base.

Checklist

coveralls commented 3 months ago

Coverage Status

coverage: 90.609% (+0.004%) from 90.605% when pulling 636a1935fd7dfc044c8025e5f8988c1eb751f185 on avillar:fix-norm_url-urn into cb5d05812552ec76739b518bccb9f900c9cfe8ec on RDFLib:main.

ashleysommer commented 2 months ago

Thanks @avillar This looks good. This will make it into the upcoming v7.1.0 release.

Quick question, is it common to have URN identifiers in JSON-LD? I've never seen it before personally. Is it even part of the JSON-LD spec?

I do however see the need for this fix in RDFLib, because we support URNs in all other serializations, and we need to be able to round-trip conversions to JSON-LD and back again, so we need to ensure URNs are preserved in the serialization.

avillar commented 2 months ago

I'm not sure how common they are "in the wild", but the JSON-LD spec specifically notes that IRIs are not limited to URLs, using an example of a UUID URN. In any case, as you mention, as JSON-LD is a concrete RDF syntax, so support for IRIs (including URNs) is desirable.

In our case, we use them for plain JSON + JSON-LD context = RDF conversions that we the run through a SHACL validator, so they're useful for identifying the focus nodes while signaling to the user that we're not talking about resolvable resources.

ashleysommer commented 2 months ago

In our case, we use them for plain JSON + JSON-LD context = RDF conversions that we the run through a SHACL validator, so they're useful for identifying the focus nodes while signaling to the user that we're not talking about resolvable resources.

Nice example use case, thanks!