-
Notifications
You must be signed in to change notification settings - Fork 35
RDF to Object conversion (closing #555) #619
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
Changes from 9 commits
3d4391c
5fb21fa
52a47a4
17edb1b
0b32f75
2f34954
fd224e1
fd89aed
2c51796
05139b0
7e5167e
35f105c
d02a82b
d4cd1f6
5161fc4
a6132a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# JetBrains IDEs | ||
.idea/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,6 +284,48 @@ | |
text-decoration: none; | ||
color: #666; | ||
} | ||
|
||
table.simple { | ||
border-collapse: collapse; | ||
width: 100%; | ||
font-size: 14px; | ||
} | ||
|
||
table.simple th, | ||
table.simple td { | ||
border: 1px solid #ddd; | ||
padding: 8px; | ||
vertical-align: top; /* Align text to the top */ | ||
} | ||
|
||
table.simple th { | ||
background-color: #f2f2f2; /* Light gray for headers */ | ||
font-weight: bold; | ||
text-align: left; | ||
} | ||
|
||
table.simple tr:nth-child(even) { | ||
background-color: #f9f9f9; /* Alternating row colors */ | ||
} | ||
|
||
table.simple tr:hover { | ||
background-color: #e9e9e9; /* Highlight on hover */ | ||
} | ||
|
||
table.simple a { | ||
color: #1a73e8; /* Make links a visible color */ | ||
text-decoration: none; | ||
} | ||
|
||
table.simple a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
table.simple td.error { | ||
background-color: #FFA500; | ||
color: #000; | ||
font-weight: bold; | ||
} | ||
</style> | ||
</head> | ||
|
||
|
@@ -5156,17 +5198,89 @@ <h3>Overview</h3> | |
and generating a JSON-LD document in expanded form for all | ||
<a>RDF literals</a>, <a>IRIs</a> | ||
and <a>blank node identifiers</a>. | ||
If the <a data-link-for="JsonLdOptions">useNativeTypes</a> flag is set to <code>true</code>, | ||
<a>RDF literals</a> with a | ||
<a>datatype IRI</a> | ||
that equals <code>xsd:integer</code> or <code>xsd:double</code> are converted | ||
to a <a>JSON numbers</a> and <a>RDF literals</a> | ||
with a <a>datatype IRI</a> | ||
that equals <code>xsd:boolean</code> are converted to <code>true</code> or | ||
<code>false</code> based on their | ||
<a>lexical form</a> | ||
as described in | ||
<a class="sectionRef" href="#data-round-tripping"></a>. | ||
|
||
If the <a data-link-for="JsonLdOptions">useNativeTypes</a> flag is set | ||
to <code>true</code>, <a>RDF literals</a> are converted to JSON values | ||
based on their <a>datatype IRI</a> and <a>lexical form</a> as described | ||
in <a class="sectionRef" href="#algorithm"></a>. | ||
anatoly-scherbakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</p> | ||
|
||
<table class="simple"> | ||
anatoly-scherbakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<thead> | ||
<th>RDF datatype</th> | ||
<th>RDF Literal</th> | ||
<th>JSON</th> | ||
</thead> | ||
anatoly-scherbakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<tbody> | ||
<tr> | ||
<th>(<em>None</em>, implying <code>xsd:string</code>)</th> | ||
<td rowspan="2">An RDF string literal</td> | ||
<td rowspan="2">JSON string literal</td> | ||
</tr> | ||
<tr> | ||
<th><code>xsd:string</code></th> | ||
</tr> | ||
anatoly-scherbakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<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 commentThe 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. |
||
<td><a>JSON Number</a></td> | ||
</tr> | ||
|
||
<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 commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this needs to be serialized as a value object with |
||
</tr> | ||
|
||
<tr> | ||
<td>Any other value</td> | ||
<td class="error">Throw <a data-link-for="JsonLdErrorCode">invalid JSON literal</a></td> | ||
</tr> | ||
Comment on lines
+5235
to
+5238
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
<tr> | ||
<th rowspan="4"><code>xsd:double</code></th> | ||
<td>Real number in the <code>[-2<sup>53</sup> + 1, 2<sup>53</sup> + 1]</code> range, representable as per [[IEEE-754-2008]]</td> | ||
<td><a>JSON Number</a></td> | ||
</tr> | ||
|
||
<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 commentThe 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. |
||
</tr> | ||
|
||
<tr> | ||
<td> | ||
Non-numeric values: | ||
|
||
<ul> | ||
<li><code>"NaN"^^xsd:double</code>,</li> | ||
<li><code>"+INF"^^xsd:double</code>,</li> | ||
<li><code>"-INF"^^xsd:double</code></li> | ||
</ul> | ||
</td> | ||
<td class="error" rowspan="2">Throw <a data-link-for="JsonLdErrorCode">invalid JSON literal</a></td> | ||
</tr> | ||
Comment on lines
+5261
to
+5262
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
<td>Any other value</td> | ||
</tr> | ||
|
||
<tr> | ||
<th rowspan="3"><code>xsd:boolean</code></th> | ||
<td><code>true</code></td> | ||
<td><code>true</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>false</code></td> | ||
<td><code>false</code></td> | ||
</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 commentThe reason will be displayed to describe this comment to others. Learn more. This is not what the algorithm is saying! |
||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<p> | ||
Unless the <a data-link-for="JsonLdOptions">useRdfType</a> flag is set to true, <code>rdf:type</code> | ||
predicates will be serialized as <code>@type</code> as long as the associated object is | ||
either an <a>IRI</a> or <a>blank node identifier</a>.</p> | ||
|
@@ -5477,10 +5591,24 @@ <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> | ||
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 numerical value | ||
outside of the range mandated by [[IEEE-754-2008]], then set | ||
anatoly-scherbakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<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> | ||
</ol> | ||
</li> | ||
<li class="changed">Otherwise, if <a>processing mode</a> is not `json-ld-1.0`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,26 @@ | |
"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": "native types flag set to true is ignored if the number provided is invalid in JSON", | ||
"purpose": "Literals with datatype xsd:boolean, xsd:integer, and xsd:double are serialized using native scalar values if possible", | ||
anatoly-scherbakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"option": { | ||
"useNativeTypes": true | ||
}, | ||
"input": "fromRdf/0027-in.nq", | ||
"expect": "fromRdf/0027-out.jsonld" | ||
}, { | ||
"@id": "#t0028", | ||
"@type": ["jld:NegativeEvaluationTest", "jld:FromRDFTest"], | ||
"name": "native types flag set to true is ignored if the number provided is invalid in JSON", | ||
"purpose": "+INF^^xsd:double causes a failure to serialize in JSON.", | ||
"option": { | ||
"useNativeTypes": true | ||
}, | ||
"input": "fromRdf/0028-in.nq", | ||
"expectErrorCode": "invalid JSON literal" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
}, { | ||
"@id": "#tdi01", | ||
"@type": [ "jld:PositiveEvaluationTest", "jld:FromRDFTest" ], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<http://example.com/Subj1> <http://example.com/prop> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> . | ||
<http://example.com/Subj1> <http://example.com/prop> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> . | ||
<http://example.com/Subj1> <http://example.com/prop> "1"^^<http://www.w3.org/2001/XMLSchema#integer> . | ||
<http://example.com/Subj1> <http://example.com/prop> "1.1"^^<http://www.w3.org/2001/XMLSchema#decimal> . | ||
<http://example.com/Subj1> <http://example.com/prop> "0.1e999999999999999"^^<http://www.w3.org/2001/XMLSchema#double> . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"@id": "http://example.com/Subj1", | ||
"http://example.com/prop": [ | ||
{ "@value": true }, | ||
{ "@value": false }, | ||
{ "@value": 1 }, | ||
{ "@value": "1.1", "@type": "http://www.w3.org/2001/XMLSchema#decimal"}, | ||
{ "@value": "0.1e999999999999999", "@type": "http://www.w3.org/2001/XMLSchema#double"} | ||
] | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<http://example.com/Subj1> <http://example.com/prop> "+INF"^^<http://www.w3.org/2001/XMLSchema#double> . |
Uh oh!
There was an error while loading. Please reload this page.