-
Notifications
You must be signed in to change notification settings - Fork 33
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 to Object conversion (closing #555) #619
RDF to Object conversion (closing #555) #619
Conversation
a8a9101
to
5c95152
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes are to the informative summary, but the issue actually calls out 2.4.3 (was 2.3.4) which is normative; that's the important area to address.
@anatoly-scherbakov, if you can create branches at json-ld-api rather than on your own fork, it is easier for others to collaborate. |
As an alternative, we may treat these as error conditions, which is what JCS does.
|
Can you please replace the emoji in the commit titles with words. |
8f49ccd
to
93bd915
Compare
93bd915
to
17edb1b
Compare
dc53fb3
to
fd89aed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change to table head: th elements need to be wrapped inside a tr.
Co-authored-by: Gregg Kellogg <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, subject to @TallTed's suggestions. We may want to revisit what happens if Infinity
or NaN
is attempted to be serialized.
Co-authored-by: Ted Thibodeau Jr <[email protected]>
Co-authored-by: Ted Thibodeau Jr <[email protected]>
Co-authored-by: Ted Thibodeau Jr <[email protected]>
@gkellogg do you mean we could convert them to JSON Strings instead of raising a JSON-LD processing error? |
GitHub tells me that
Not sure why though, it might be related to the fact that I opened it in my fork. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments in the "Files changed" view.
<tr> | ||
<td>Any other value</td> | ||
<td class="error">Throw <a data-link-for="JsonLdErrorCode">invalid JSON literal</a></td> | ||
</tr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that is a good idea, but I'll comment on that in the algorithm itself, below.
<td class="error" rowspan="2">Throw <a data-link-for="JsonLdErrorCode">invalid JSON literal</a></td> | ||
</tr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above; I don't think that is a good idea, see my comments in the algorithm.
</tr> | ||
<tr> | ||
<td>Any other value</td> | ||
<td class="error">Throw <a data-link-for="JsonLdErrorCode">invalid JSON literal</a></td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not what the algorithm is saying!
according to [[XMLSCHEMA11-2]], and if it is a numeric value | ||
conformant to [[IEEE-754-2008]], then set <var>converted value</var> | ||
to the result of converting the | ||
<a>lexical form</a> | ||
to a JSON <a>number</a>.</li> | ||
to a JSON <a>number</a>. | ||
</li> | ||
<li> | ||
Otherwise, if <a>lexical form</a> expresses a numeric value | ||
outside of the ranges supported by [[IEEE-754-2008]], then set | ||
<var>converted value</var> to a JSON string literal containing | ||
said lexical form. | ||
</li> | ||
<li> | ||
Otherwise, if <a>lexical form</a> expresses a non-numeric value, | ||
such as <code>"+INF"^^xsd:double</code>, an | ||
<a data-link-for="JsonLdErrorCode">invalid JSON literal</a> | ||
error has been detected and processing is aborted. | ||
</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right way to change the algorithm, sorry @anatoly-scherbakov .
- this is repurposing the
invalid JSON literal
error, which was initially about "literals of type@json
", not about "JSON scalar values"... - we should definitely not raise error on well-formed literals (such as big integers or non-finite doubles).
- I would not raise errors on ill-formed numbers either, but encode them as value objects -- this is what the spec currently says, and I don't think we should change that.
- to improve round-tripping, I suggest that we use the same rules to differentiate integers and doubles as in the Object to RDF algorithm (currently, an very big xsd:integer would round trip to an xsd:double, which is not great).
So I suggest that step 2.4.3 of the original algorithm should be replaced with:
-
Otherwise, if the datatype IRI of value equals xsd:integer, its lexical form is a valid xsd:integer according to [XMKSCHEMA11-2], and its absolute value is strictly lower than 10^21, the set converted value to the result of converting its lexical form to a JSON number.
-
Otherwise, if the datatype IRI of value equals xsd:double, its lexical form is a valid xsd:double according to [XMLSCHEMA11-2] and is neither "NaN", "INF" not "-INF", then set converted value to the result of converting the lexical form to a JSON number.
Of course, the table and the tests should then be updated accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific range examples should be careful to be informative, to not get ahead of XSD. Also, it will need to be consistent with JCS.
It might be that they way to do this is to just use JCS for serializing strings, and require that the result of serializing to JCS must result that is in the value space of xsd:integer or xsd:double, respectively.
Co-authored-by: Pierre-Antoine Champin <[email protected]>
Co-authored-by: Pierre-Antoine Champin <[email protected]>
Co-authored-by: Pierre-Antoine Champin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I question if this is a class-2 editorial change; I think it's class-3 change, which will require Candidate Correction marking. We can discuss.
+1, this falls under "clears up an ambiguity or under-specified part of the specification" which is part of "class 3". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @pchampin, but we need to be clear that it needs to be valid both as xsd:double and JCS number, and fallback to the expanded representation.
|
||
<tr> | ||
<td>Whole number out of that range</td> | ||
<td>JSON string literal</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this needs to be serialized as a value object with @type
. The integer 1e54
(1000000000000000078291540404596243842305360299886116864
) is outside of that range, but the value object needs to include `"@type": "xsd:integer".
|
||
<tr> | ||
<th rowspan="3"><code>xsd:integer</code></th> | ||
<td>Whole number in the <code>[-2<sup>53</sup> + 1, 2<sup>53</sup> + 1]</code> range, representable as per [[IEEE-754-2008]]</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more constraints in the lexical form of an xsd:integer than this.
Also, while it's likely consistent with JCS/ECMAScript, such numbers also need to be representable as integers in JCS/ECMAScript. See Appendix B.
We should be careful to not mis-describe this, and just refer to XSD Datatypes 1.1 and JCS.
|
||
<tr> | ||
<td>Real number out of that range</td> | ||
<td>JSON string literal</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment; the ranges should be consistent with XSD and JCS and probably shouldn't re-define the criteria.
according to [[XMLSCHEMA11-2]], and if it is a numeric value | ||
conformant to [[IEEE-754-2008]], then set <var>converted value</var> | ||
to the result of converting the | ||
<a>lexical form</a> | ||
to a JSON <a>number</a>.</li> | ||
to a JSON <a>number</a>. | ||
</li> | ||
<li> | ||
Otherwise, if <a>lexical form</a> expresses a numeric value | ||
outside of the ranges supported by [[IEEE-754-2008]], then set | ||
<var>converted value</var> to a JSON string literal containing | ||
said lexical form. | ||
</li> | ||
<li> | ||
Otherwise, if <a>lexical form</a> expresses a non-numeric value, | ||
such as <code>"+INF"^^xsd:double</code>, an | ||
<a data-link-for="JsonLdErrorCode">invalid JSON literal</a> | ||
error has been detected and processing is aborted. | ||
</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific range examples should be careful to be informative, to not get ahead of XSD. Also, it will need to be consistent with JCS.
It might be that they way to do this is to just use JCS for serializing strings, and require that the result of serializing to JCS must result that is in the value space of xsd:integer or xsd:double, respectively.
"useNativeTypes": true | ||
}, | ||
"input": "fromRdf/0028-in.nq", | ||
"expectErrorCode": "invalid JSON literal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not invalid, it just can't be serialized as a native value.
I believe I was misunderstanding a few things when writing this PR, sorry guys. Instead of reverting much of these changes, I just created another PR: #625 And I am closing this one; it won't disappear so as to maintain the history, just will be closed. |
This was discussed during the #json-ld meeting on 15 January 2025. View the transcriptw3c/json-ld-api#619<gb> CLOSED Pull Request 619 RDF to Object conversion (closing #555) (by anatoly-scherbakov) [spec:editorial] [class-2] anatoly-scherbakov: this is an earlier version that was closed after discussion and started over. bigbluehat: Ok, I will take it out of the project <anatoly-scherbakov> w3c/json-ld-api#625 <gb> Pull Request 625 (closes #555) Fall back to default logic in `useNativeTypes` mode for RDF numbers which are not JSON numbers (by anatoly-scherbakov) |
Why
Trying to solve #555.
What
Clarify what we do when can't serialize a number from RDF into JSON.
Preview | Diff