-
Notifications
You must be signed in to change notification settings - Fork 560
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
RDF Literal "1"^^xsd:boolean should _not_ coerce to True #847
Comments
thanks @ashleysommer ! Could you make a PR and I'll merge? |
Ok. I will today. |
Fixes RDFLib#847
I think this is wrong. As pointed out in #913 the XML Schema Definition Language (XSD) defines the lexical mapping of boolean as:
This is also mentioned in w3c/data-shapes#98 . As I understand it w3c/data-shapes#98 speaks about a specific case for a SHACL validation not for the general case of how to deal with #856 resp. f547599 should be reverted and a fix according to #913 should be introduced. |
@white-gecko I initially wrote this issue (and PR #856) from the perspective of the python SHACL implementation. There are spec-driven test files used to implement unit tests for all SHACL implementations. And one of these tests relies on the condition that a backing RDF implementation should treat the given Literal: rdflib doesn't have any concept of an "Invalid Literal", (which might be something to think about as a feature down the track). So the only way to get that SHACL unit test to pass correctly with rdflib's rudimentary Literal handling, was to patch the action of parsing a "1" with Note, I think there's some confusion here about the distinction between a Typed Literal, and a typeless literal. For example, for typeless literals all of these are valid:
Whereas typed literals are like the following:
@white-gecko This document is specific to RDF: https://www.w3.org/TR/swbp-xsch-datatypes/#boolean but it also seems to agree with you, it seems to agree that |
Thank you for the pointer to W3C Working Group Note XML Schema Datatypes in RDF and OWL. It states explicitly:
Regarding the parsing and serialization. I think we should distinguish between the RDFlib data model which should be abstract from the serialization formats. We should not mix the interpretation of Turtle abbreviations with the interpretation of lexical values. More comments in #913. |
I encountered this issue while working on pySHACL.
Specifically, this bug is causing a failure in one of the tests in the standard data-shapes-test-suite here uniqueLang-002-shapes.ttl.
This test relies on the fact that
"1"^^xsd:boolean
is an invalid Literal, and when testing equality of this Literal against RDF True, it should be not equal.A simple code recreation:
This is a more complete example:
https://gist.github.com/ashleysommer/87f0b9660a71de380889f98745af2f74
I've tracked down the problem to this line in the XSDToPython map:
rdflib/rdflib/term.py
Line 1484 in 5fa18be
lambda i: i.lower() in ['1', 'true']
should be changed to
lambda i: i.lower() == 'true'
The text was updated successfully, but these errors were encountered: