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

RDF to Object conversion (closing #555) #619

Closed

Conversation

anatoly-scherbakov
Copy link

@anatoly-scherbakov anatoly-scherbakov commented Nov 8, 2024

Why

Trying to solve #555.

What

Clarify what we do when can't serialize a number from RDF into JSON.


Preview | Diff

@anatoly-scherbakov anatoly-scherbakov force-pushed the 555-rdf-to-object-conversion branch from a8a9101 to 5c95152 Compare November 8, 2024 16:00
@anatoly-scherbakov anatoly-scherbakov changed the title 555 rdf to object conversion RDF to Object conversion (closing #555) Nov 8, 2024
@anatoly-scherbakov anatoly-scherbakov marked this pull request as ready for review November 8, 2024 16:00
@anatoly-scherbakov
Copy link
Author

I don't think I can invite reviewers to this PR 🤔 @pchampin @gkellogg

@gkellogg
Copy link
Member

gkellogg commented Nov 8, 2024

I don't think I can invite reviewers to this PR 🤔 @pchampin @gkellogg

I'll look at your permissions, you should have full permissions on this and other repos.

@gkellogg gkellogg requested review from gkellogg and pchampin November 8, 2024 16:08
Copy link
Member

@gkellogg gkellogg left a 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.

index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
@gkellogg
Copy link
Member

gkellogg commented Nov 8, 2024

@anatoly-scherbakov, if you can create branches at json-ld-api rather than on your own fork, it is easier for others to collaborate.

@gkellogg gkellogg linked an issue Nov 8, 2024 that may be closed by this pull request
@gkellogg
Copy link
Member

gkellogg commented Nov 8, 2024

As an alternative, we may treat these as error conditions, which is what JCS does.

3.2.2.3. Serialization of Numbers
...
Note: Since Not a Number (NaN) and Infinity are not permitted in JSON, occurrences of NaN or Infinity MUST cause a compliant JCS implementation to terminate with an appropriate error.

@davidlehn
Copy link
Contributor

Can you please replace the emoji in the commit titles with words.

index.html Outdated Show resolved Hide resolved
@anatoly-scherbakov anatoly-scherbakov force-pushed the 555-rdf-to-object-conversion branch from 8f49ccd to 93bd915 Compare November 12, 2024 09:25
@anatoly-scherbakov anatoly-scherbakov force-pushed the 555-rdf-to-object-conversion branch from 93bd915 to 17edb1b Compare November 12, 2024 09:27
index.html Outdated Show resolved Hide resolved
@anatoly-scherbakov anatoly-scherbakov force-pushed the 555-rdf-to-object-conversion branch from dc53fb3 to fd89aed Compare November 13, 2024 15:31
Copy link
Member

@gkellogg gkellogg left a 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.

index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
Co-authored-by: Gregg Kellogg <[email protected]>
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
Copy link
Member

@gkellogg gkellogg left a 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.

anatoly-scherbakov and others added 3 commits November 24, 2024 12:03
Co-authored-by: Ted Thibodeau Jr <[email protected]>
Co-authored-by: Ted Thibodeau Jr <[email protected]>
@anatoly-scherbakov
Copy link
Author

@TallTed created a separate issue about the version of the IEEE754 standard we refer to: #620

@anatoly-scherbakov
Copy link
Author

@gkellogg do you mean we could convert them to JSON Strings instead of raising a JSON-LD processing error?

@anatoly-scherbakov
Copy link
Author

GitHub tells me that

You're not authorized to push to this branch. Visit https://docs.github.com/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches for more information.

Not sure why though, it might be related to the fact that I opened it in my fork.

Copy link
Contributor

@pchampin pchampin left a 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.

index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
Comment on lines +5237 to +5240
<tr>
<td>Any other value</td>
<td class="error">Throw <a data-link-for="JsonLdErrorCode">invalid JSON literal</a></td>
</tr>
Copy link
Contributor

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.

Comment on lines +5263 to +5264
<td class="error" rowspan="2">Throw <a data-link-for="JsonLdErrorCode">invalid JSON literal</a></td>
</tr>
Copy link
Contributor

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>
Copy link
Contributor

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!

index.html Outdated Show resolved Hide resolved
Comment on lines +5596 to +5613
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>
Copy link
Contributor

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 .

  1. this is repurposing the invalid JSON literal error, which was initially about "literals of type @json", not about "JSON scalar values"...
  2. we should definitely not raise error on well-formed literals (such as big integers or non-finite doubles).
  3. 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.
  4. 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.

Copy link
Member

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.

anatoly-scherbakov and others added 3 commits November 29, 2024 23:37
Co-authored-by: Pierre-Antoine Champin <[email protected]>
Co-authored-by: Pierre-Antoine Champin <[email protected]>
Co-authored-by: Pierre-Antoine Champin <[email protected]>
Copy link
Member

@gkellogg gkellogg left a 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.

@pchampin
Copy link
Contributor

pchampin commented Dec 3, 2024

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".
+1 also to discuss

Copy link
Member

@gkellogg gkellogg left a 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>
Copy link
Member

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>
Copy link
Member

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>
Copy link
Member

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.

Comment on lines +5596 to +5613
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>
Copy link
Member

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"
Copy link
Member

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.

@anatoly-scherbakov
Copy link
Author

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.

@w3cbot
Copy link

w3cbot commented Jan 15, 2025

This was discussed during the #json-ld meeting on 15 January 2025.

View the transcript

w3c/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)


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

Successfully merging this pull request may close these issues.

blind spot in RDF to object conversion
6 participants