Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 60 additions & 39 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5459,7 +5459,28 @@ <h3>Algorithm</h3>
<a>RDF literal</a>:
<ol>
<li>Initialize a new empty <a class="changed">map</a> result.</li>
<li>Initialize <var>converted value</var> to <var>value</var>.</li>
<li>
Initialize <var>converted value</var> to <var>null</var>.
<div class="candidate correction" id="change_api_pr670">
<span class="marker">Candidate Correction 10</span>
<p>
Let <var>converted value</var> be initially unset, and only
actively set if a native type can be used. Then group the
other cases in an else block, defaulting to use the lexical
form of <var>value</var>. Since <var>type</var> is set in the
final else clause (unless it equals <var>xsd:string</var>),
there is no need to set it in the clause for
<var>useNativeTypes</var>.
</p>
<p>
Previously, the else clause was never reached even if a
native type couldn't be used, leaving only plain strings
where, e.g., language-tagged string literals were the source.
For more information, refer to
<a href="https://github.com/w3c/json-ld-api/issues/670">issue 670</a>.
</p>
</div>
</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">
Expand All @@ -5480,12 +5501,8 @@ <h3>Algorithm</h3>
of <var>value</var> equals <code>xsd:boolean</code>, set
<var>converted value</var> to <code>true</code> if the
<a>lexical form</a>

of <var>value</var> matches <code>"true"</code> or <code>"1"</code>, or <code>false</code>
if it matches <code>"false"</code> or <code>"0"</code>.

If it matches neither,
set <var>type</var> to <code>xsd:boolean</code>.</li>
of <var>value</var> matches <code>"true"</code> or <code>"1"</code>, or <code>false</code>
if it matches <code>"false"</code> or <code>"0"</code>.</li>
<li>Otherwise, if the
<a>datatype IRI</a>
of <var>value</var> equals <code>xsd:integer</code> or
Expand All @@ -5505,46 +5522,47 @@ <h3>Algorithm</h3>
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>

</li>
</ol>
</li>
<li class="changed">Otherwise, if <a>processing mode</a> is not `json-ld-1.0`,
and <var>value</var> is a <a>JSON literal</a>,
set <var>converted value</var> to the result of
turning the lexical value of <var>value</var>
into the <a>JSON-LD internal representation</a>, and set <var>type</var> to <code>@json</code>.
If the lexical value of <var>value</var> is not valid JSON according to
the <a data-cite="RFC8259#section-2">JSON Grammar</a> [[RFC8259]],
an <a data-link-for="JsonLdErrorCode">invalid JSON literal</a>
error has been detected and processing is aborted.</li>
<li class="changed">Otherwise, if the <a>datatype IRI</a> of <var>value</var> starts with `https://www.w3.org/ns/i18n#`,
and {{JsonLdOptions/rdfDirection}} is `i18n-datatype`:
<ol>
<li class="changed">
If <var>converted value</var> is <code>null</code>,
<ol class="changed">
<li>Set <var>converted value</var> to the <a>lexical form</a> of <var>value</var>.</li>
<li>If the string prefix of the <a data-cite="RFC3986#section-3.5">fragment identifier</a>
of the <a>datatype IRI</a> up until the underscore (`"_"`) is not empty,
add an <a>entry</a> `@language` to <var>result</var> and set its value to that prefix.
<div class="note">As `@direction` may be used without `@language`,
it is possible, and legitimate, to create a datatype IRI
such as `http://w3.org/ns/i18n#_ltr`, which does not encode a language tag.</div></li>
<li>Add an <a>entry</a> `@direction` to <var>result</var> and set its value to the substring of the
<a data-cite="RFC3986#section-3.5">fragment identifier</a> following
the underscore (`"_"`).</li>
<li>If <a>processing mode</a> is not `json-ld-1.0`,
and <var>value</var> is a <a>JSON literal</a>,
set <var>converted value</var> to the result of
turning the lexical value of <var>value</var>
into the <a>JSON-LD internal representation</a>, and set <var>type</var> to <code>@json</code>.
If the lexical value of <var>value</var> is not valid JSON according to
the <a data-cite="RFC8259#section-2">JSON Grammar</a> [[RFC8259]],
an <a data-link-for="JsonLdErrorCode">invalid JSON literal</a>
error has been detected and processing is aborted.</li>
<li>Otherwise, if the <a>datatype IRI</a> of <var>value</var> starts with `https://www.w3.org/ns/i18n#`,
and {{JsonLdOptions/rdfDirection}} is `i18n-datatype`:
<ol>
<li>If the string prefix of the <a data-cite="RFC3986#section-3.5">fragment identifier</a>
of the <a>datatype IRI</a> up until the underscore (`"_"`) is not empty,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
of the <a>datatype IRI</a> up until the underscore (`"_"`) is not empty,
of the <a>datatype IRI</a> up until the underscore ("`_`") is not empty,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a total of 11 occurrences of:

underscore (`"_"`)

in this document. I suggest making a separate PR to change this, rather than make this the odd one out.

add an <a>entry</a> `@language` to <var>result</var> and set its value to that prefix.
<div class="note">As `@direction` may be used without `@language`,
it is possible, and legitimate, to create a datatype IRI
such as `http://w3.org/ns/i18n#_ltr`, which does not encode a language tag.</div></li>
<li>Add an <a>entry</a> `@direction` to <var>result</var> and set its value to the substring of the
<a data-cite="RFC3986#section-3.5">fragment identifier</a> following
the underscore (`"_"`).</li>
</ol>
</li>
<li>Otherwise, if <var>value</var> is a
<a>language-tagged string</a>
add an <a>entry</a> <code>@language</code> to <var>result</var> and set its value to the
<a>language tag</a> of <var>value</var>.</li>
<li>Otherwise, set <var>type</var> to the
<a>datatype IRI</a>
of <var>value</var>, unless it equals <code>xsd:string</code> which is ignored.</li>
</ol>
</li>
<li>Otherwise, if <var>value</var> is a
<a>language-tagged string</a>
add an <a>entry</a> <code>@language</code> to <var>result</var> and set its value to the
<a>language tag</a> of <var>value</var>.</li>
<li>Otherwise, set <var>type</var> to the
<a>datatype IRI</a>
of <var>value</var>, unless it equals <code>xsd:string</code> which is ignored.</li>
<li>Add an <a>entry</a> <code>@value</code> to <var>result</var> whose value
is set to <var>converted value</var>.</li>
<li>If <var>type</var> is not <code>null</code>, add an <a>entry</a> <code>@type</code>
Expand Down Expand Up @@ -7088,6 +7106,9 @@ <h2>Change log</h2>
as described in <a href="#change_api_638">Candidate Correction 8</a></li>
<li>2025-02-28: Simplify the <a href="#algorithm-1">Inverse Context Creation algorithm</a>
as described in <a href="#change_pr639">Candidate Correction 8</a></li>
<li>2026-06-06: Fix unconditional skip of other clauses when
<a data-link-for="JsonLdOptions">useNativeTypes</a> is `true`, as
described in <a href="#change_api_pr670">Candidate Correction 10</a>.</li>
</ul>
</details>

Expand Down
10 changes: 10 additions & 0 deletions tests/fromRdf-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@
},
"input": "fromRdf/0027-in.nq",
"expect": "fromRdf/0027-out.jsonld"
}, {
"@id": "#t0028",
"@type": ["jld:PositiveEvaluationTest", "jld:FromRDFTest"],
"name": "use native types flag with non-native values",
"purpose": "Ensure that useNativeTypes flag being true does not interfere with values that cannot be serialized into a native value.",
"option": {
"useNativeTypes": true
},
"input": "fromRdf/0028-in.nq",
"expect": "fromRdf/0028-out.jsonld"
}, {
"@id": "#tdi01",
"@type": [ "jld:PositiveEvaluationTest", "jld:FromRDFTest" ],
Expand Down
5 changes: 5 additions & 0 deletions tests/fromRdf/0028-in.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<http://example.com> <http://example.com/property> "string" .
<http://example.com> <http://example.com/property> "hello"@en .
<http://example.com> <http://example.com/property> "No"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<http://example.com> <http://example.com/property> "AAA"^^<http://www.w3.org/2001/XMLSchema#double> .
<http://example.com> <http://example.com/property> "{\"x\": 1}"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#JSON> .
28 changes: 28 additions & 0 deletions tests/fromRdf/0028-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"@id": "http://example.com",
"http://example.com/property": [
{
"@value": "string"
},
{
"@language": "en",
"@value": "hello"
},
{
"@value": "No",
"@type": "http://www.w3.org/2001/XMLSchema#boolean"
},
{
"@value": "AAA",
"@type": "http://www.w3.org/2001/XMLSchema#double"
},
{
"@value": {
"x": 1
},
"@type": "@json"
}
]
}
]
Loading