Skip to content
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

Add support for xsd:float as native type #462

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pduchesne
Copy link

Currently, when parsing RDF using 'useNativeTypes', xsd:float is not recognized.
This fixes it.

@davidlehn
Copy link
Member

I believe the omission of xsd:float was done on purpose. I think it was due to how native JSON numbers are handled and problems with round trips of the data. Or maybe some other edge cases. It was simpler to just handle all data as doubles and map to how JSON is normally processed. I need some help remembering the details of all this.

This kind of change would need a handful of tests. Need to text various combinations of doubles and floats, context datatypes, serializing and deserializing the data, overflow edge cases, etc. It's probably also something to bring up with the JSON-LD community to see if it's an issue that should have broad support across implementations. In that case the main JSON-LD test suite and spec would need updating too.

@gkellogg
Copy link
Collaborator

Yes, the JSON number format doesn't distinguish between Integers Double or Floats. We have some logic to distinguish between Integers and Doubles, but there is really no way to distinguish a Double from a Float.

Of course, a native number may be used in a value object where @type is set to xsd:float, for example, but only as part of a value object. This is defined by the spec, not the implementation.

@pduchesne
Copy link
Author

Thank you for your feedback.

First some context to explain my usecase : i'm using fromRDF, chained with jsonld framing, to turn third-party RDF into plain JSON, and I need native numbers in that JSON. And it'd be a shame to have to do yet another stage of postprocessing to do that number parsing.

But Indeed, I hear your point: silently converting xsd:float to native JSON numbers would lose information as it would conflate xsd:float with xsd:double.

As far as I'm concerned, I've modified my branch to still parse to native type, but keep the 'xsd:float' type. With the appropriate frame, the jsonld framing algo can then easily reduce a {"@value": 0.01, @type: "xsd:float"} object to a plain number.
I let you be the judges of whether that's an appropriate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants