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

(closes #555) Fall back to default logic in useNativeTypes mode for RDF numbers which are not JSON numbers #625

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Support JetBrains IDEs
.idea
# JetBrains IDEs
.idea/

# pyenv version file
.python-version
38 changes: 34 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5456,6 +5456,12 @@ <h3>Algorithm</h3>
<li>Initialize <var>converted value</var> to <var>value</var>.</li>
<li>Initialize <var>type</var> to <code>null</code></li>
<li>If <a data-link-for="JsonLdOptions">useNativeTypes</a> is <code>true</code>
<div class="candidate correction" id="change_5">
<span class="marker">Candidate Correction 5</span>
<p>This changes behavior when using native numbers where <a data-link-for="JsonLdOptions">useNativeTypes</a> is `true`.
For more information, refer to <a href="https://github.com/w3c/json-ld-api/issues/555">issue 555</a>.
</p>
</div>
<ol>
<li>If the
<a>datatype IRI</a>
Expand All @@ -5477,10 +5483,31 @@ <h3>Algorithm</h3>
<code>xsd:double</code> and its
<a>lexical form</a>
is a valid <code>xsd:integer</code> or <code>xsd:double</code>
according [[XMLSCHEMA11-2]], set <var>converted value</var>
to the result of converting the
<a>lexical form</a>
to a JSON <a>number</a>.</li>
according to [[XMLSCHEMA11-2]]<del cite="#change_5">,
set <var>converted value</var>
to the result of converting the
<a>lexical form</a>
to a JSON <a>number</a>.
</del><ins cite="#change_5">:
anatoly-scherbakov marked this conversation as resolved.
Show resolved Hide resolved
<ol>
<li>
Attempt to convert the <a>lexical form</a> to a <a>JSON number</a>
according to the
[[RFC8785]] <a data-cite="RFC8785#name-serialization-of-numbers">
JSON Serialization Scheme (JCS) 3.2.2.3 Serialization of Numbers
</a> procedure.
</li>
<li>
If the conversion is successful, set <var>converted value</var>
to its result.
</li>
<li>
Otherwise, set <var>type</var> to <a>datatype IRI</a>
of <var>value</var>.
</li>
</ol>
</ins>
</li>
</ol>
</li>
<li class="changed">Otherwise, if <a>processing mode</a> is not `json-ld-1.0`,
Expand Down Expand Up @@ -7056,6 +7083,9 @@ <h2>Change log</h2>
<a data-cite="JSON-LD11#embedding-json-ld-in-html-documents">Embedding JSON-LD in HTML Documents</a> [[JSON-LD11]]
for treating script elements as a single document,
as described in <a href="#change_4">Candidate Correction 4</a>.</li>
<li>2025-01-25: Correct some corner cases in transforming RDF Number Literals
to JSON numbers when <a data-link-for="JsonLdOptions">useNativeTypes</a> is `true`,
as described in <a href="#change_5">Candidate Correction 5</a>.</li>
<li>2024-01-25: Change processing step for <a>LoadDocumentCallback</a>
to not presume that the content type is for JSON,
as described in <a href="#change_6">Candidate Correction 6</a></li>
Expand Down
4 changes: 2 additions & 2 deletions tests/expand-manifest.html
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ <h2>
</dl>
</dd>
<dt id='t0041'>
Test t0041 @language: null resets the default language
Test t0041 @language: null
</dt>
<dd>
<dl class='entry'>
Expand All @@ -950,7 +950,7 @@ <h2>
<dt>Type</dt>
<dd>jld:PositiveEvaluationTest, jld:ExpandTest</dd>
<dt>Purpose</dt>
<dd></dd>
<dd>@language: null resets the default language</dd>
<dt>input</dt>
<dd>
<a href='expand/0041-in.jsonld'>expand/0041-in.jsonld</a>
Expand Down
28 changes: 28 additions & 0 deletions tests/fromRdf-manifest.html
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,34 @@ <h2>
</dd>
</dl>
</dd>
<dt id='t0027'>
Test t0027 use native types flag with values that cannot be serialized to JSON
</dt>
<dd>
<dl class='entry'>
<dt>id</dt>
<dd>#t0027</dd>
<dt>Type</dt>
<dd>jld:PositiveEvaluationTest, jld:FromRDFTest</dd>
<dt>Purpose</dt>
<dd>useNativeTypes flag being true is disregarded for a value that cannot be serialized into a native JSON value.</dd>
<dt>input</dt>
<dd>
<a href='fromRdf/0027-in.nq'>fromRdf/0027-in.nq</a>
</dd>
<dt>expect</dt>
<dd>
<a href='fromRdf/0027-out.jsonld'>fromRdf/0027-out.jsonld</a>
</dd>
<dt>Options</dt>
<dd>
<dl class='options'>
<dt>useNativeTypes</dt>
<dd>true</dd>
</dl>
</dd>
</dl>
</dd>
<dt id='tdi01'>
Test tdi01 rdfDirection: null with i18n literal with direction and no language
</dt>
Expand Down
10 changes: 10 additions & 0 deletions tests/fromRdf-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@
"purpose": "Check list generation with rdf:first property and rdf:nil value.",
"input": "fromRdf/0026-in.nq",
"expect": "fromRdf/0026-out.jsonld"
}, {
"@id": "#t0027",
"@type": ["jld:PositiveEvaluationTest", "jld:FromRDFTest"],
"name": "use native types flag with values that cannot be serialized to JSON",
"purpose": "useNativeTypes flag being true is disregarded for a value that cannot be serialized into a native JSON value.",
"option": {
"useNativeTypes": true
},
"input": "fromRdf/0027-in.nq",
"expect": "fromRdf/0027-out.jsonld"
}, {
"@id": "#tdi01",
"@type": [ "jld:PositiveEvaluationTest", "jld:FromRDFTest" ],
Expand Down
11 changes: 11 additions & 0 deletions tests/fromRdf/0027-in.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<http://example.com/boolean-native> <http://example.com/example> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<http://example.com/boolean-native> <http://example.com/example> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .

<http://example.com/boolean-object> <http://example.com/example> "True"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<http://example.com/boolean-object> <http://example.com/example> "False"^^<http://www.w3.org/2001/XMLSchema#boolean> .

<http://example.com/number-native> <http://example.com/example> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .

<http://example.com/number-object> <http://example.com/example> "0.1e999999999999999"^^<http://www.w3.org/2001/XMLSchema#double> .
<http://example.com/number-object> <http://example.com/example> "+INF"^^<http://www.w3.org/2001/XMLSchema#double> .
<http://example.com/number-object> <http://example.com/example> "-INF"^^<http://www.w3.org/2001/XMLSchema#double> .
56 changes: 56 additions & 0 deletions tests/fromRdf/0027-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"@graph": [
{
"@id": "http://example.com/boolean-native",
"http://example.com/example": [
{
"@type": "http://www.w3.org/2001/XMLSchema#boolean",
"@value": true
},
{
"@type": "http://www.w3.org/2001/XMLSchema#boolean",
"@value": false
}
]
},
{
"@id": "http://example.com/boolean-object",
"http://example.com/example": [
{
"@type": "http://www.w3.org/2001/XMLSchema#boolean",
"@value": "True"
},
{
"@type": "http://www.w3.org/2001/XMLSchema#boolean",
"@value": "False"
}
]
},
{
"@id": "http://example.com/number-native",
"http://example.com/example": [
{
"@type": "http://www.w3.org/2001/XMLSchema#integer",
"@value": 1
}
]
},
{
"@id": "http://example.com/number-object",
"http://example.com/example": [
{
"@type": "http://www.w3.org/2001/XMLSchema#double",
"@value": "0.1e999999999999999"
},
{
"@type": "http://www.w3.org/2001/XMLSchema#double",
"@value": "+INF"
},
{
"@type": "http://www.w3.org/2001/XMLSchema#double",
"@value": "-INF"
}
]
}
]
}