-
Notifications
You must be signed in to change notification settings - Fork 64
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
Problem when validating xsd:float #140
Comments
https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#float My assumption is that Could it be that pySHACL/pyshacl/constraints/core/value_constraints.py Lines 214 to 215 in 3d67789
|
Hi @tobiasschweizer |
Sure, I will try this and come back to you asap. |
I tried the following which worked fine: "monetaryamount.ttl" <http://www.example.com/1> a <http://schema.org/MonetaryAmount> ;
<http://schema.org/value> "100000"^^<http://www.w3.org/2001/XMLSchema#float> .
|
Ok, great. Thanks, that confirms the bug lies in the JSON-LD parser. I'll create a corresponding bug in the RDFlib bug tracker. |
Ok, thanks. Let me know if I can be of further assistance to substantiate the report. |
Hi @tobiasschweizer my_json = """
{
"@context": {
"@vocab": "http://schema.org/",
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"@type": "MonetaryAmount",
"value": {
"@type": "xsd:float",
"@value": 100000
}
}
"""
g = rdflib.Graph()
g.parse(data=my_json, format="json-ld")
g.print() This prints
So it appears there is no bug in the JSON-LD parser, it parses the amount to a float, and when serializing back into turtle, it remains a float. So the issue must lie elsewhere. I'll look into it further. |
Ok, Ive worked out one key difference between the json-ld example and the turtle example. Even though the datatype of both is xsd:float, the "lexical value" of the data in the Turtle value is a string ( When setting up a Literal value, RDFLib has the ability to parse a lexical string into a real value matching the datatype, but only when the lexical value is a string. This in the past has never been an issue because in Turtle and other RDF data formats, the lexical value of any typed value is always a string. But in JSON-LD, it can clearly be something other than a string. As a simple example, replace
You will see your example now passes as expected. So now I understand that this issue lies somewhere in between the json-ld parser, and RDFLib's handling of Literal lexical values. It could possibly be fixed by adding an extra translation step in the json-ld parser, or it could be fixed by adding an extra conversion of non-string lexicals in RDFLib, or it might be easier to fix it at the PySHACL level, and modify how the datatype constraint works, allowing more kinds of values for xsd:float and xsd:double. |
Hi @ashleysommer , Apologies for butting in, but I saw a notice for this fly by and remembered an issue with default datatypes I'd encountered a while ago. Some data from my community was getting flagged after we had a "All non-integer numbers are now |
Thanks @ajnelson-nist Similarly, as per the issue described above, the lexical is an int, but the datatype is a Given that |
Thanks @ashleysommer for looking into this. So maybe the source of the problem lies in the Maybe the relations of numeric types need be taken into account here. I am no Python expert but I remember in Java you could assign an |
@ajnelson-nist this is somehow off-topic but aren't you working on lambdamusic/Ontospy#107? :-) |
Thats right. If it is possible to do that in your datafiles, that is the easiest way forward. It works because when RDFLib processes a new Literal object, it has special rules for if the lexical value is a string. When it is a string, but the literal has a known XSD datatype attached, then RDFLib will attempt to parse the string into that format. So the value of the literal will be |
Hi there,
Validating an
xsd:float
gives me an unexpected validation report.I am using "PySHACL Version: 0.19.0".
Example:
shapes graph "shapes.json":
data sample "monetaryamount.json":
pyshacl -sf json-ld -s shapes.json -df json-ld monetaryamount.json
gives me:Changing the
@value
to100000.0
or"100000"
makes it pass. However, I think all three variants should be valid, no?I tried the example above on https://shacl.org/playground/ which worked fine.
Could you tell me whether I am doing something wrong or this is a bug?
Thanks a lot!
The text was updated successfully, but these errors were encountered: