Skip to content

JSON-LD in HTML #68

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

Merged
merged 12 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions common/extract-examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
$stdout.write "F".colorize(:red)
next
end

# Get base from document, if present
html_base = doc.at_xpath('/html/head/base/@href')
ex[:base] = html_base.to_s if html_base

script_content = doc.at_xpath(xpath)
if script_content
# Remove (faked) XML comments and unescape sequences
Expand Down Expand Up @@ -439,6 +444,11 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
args[0] = if examples[ex[:result_for]][:ext] == 'html' && method == :expand
# If we are expanding, and the reference is HTML, find the first script element.
doc = Nokogiri::HTML.parse(examples[ex[:result_for]][:content])

# Get base from document, if present
html_base = doc.at_xpath('/html/head/base/@href')
options[:base] = html_base.to_s if html_base

script_content = doc.at_xpath(xpath)
unless script_content
errors << "Example #{ex[:number]} at line #{ex[:line]} references example #{ex[:result_for].inspect} with no JSON-LD script element"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[{
"@id": "http://dbpedia.org/resource/John_Lennon",
"http://xmlns.com/foaf/0.1/name": [{"@value": "John Lennon"}],
"http://schema.org/birthDate": [
{"@value": "1940-10-09", "@type": "http://www.w3.org/2001/XMLSchema#date"}
],
"http://schema.org/spouse": [
{"@id": "http://dbpedia.org/resource/Cynthia_Lennon"}
]
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

{
"@context": "https://json-ld.org/contexts/person.jsonld",
"@id": "John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "Cynthia_Lennon"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<table class="statements" data-result-for="Using the document base URL to establish the default base IRI-expanded" data-to-rdf>
<thead><tr>
<th>Subject</th>
<th>Property</th>
<th>Value</th>
<th>Value Type</th>
</tr></thead>
<tbody>
<tr>
<td>http://dbpedia.org/resource/John_Lennon</td>
<td>foaf:name</td>
<td>John Lennon</td>
<td> </td>
</tr>
<tr>
<td>http://dbpedia.org/resource/John_Lennon</td>
<td>schema:birthDate</td>
<td>1940-10-09</td>
<td>xsd:date</td>
</tr>
<tr>
<td>http://dbpedia.org/resource/John_Lennon</td>
<td>schema:spouse</td>
<td>http://dbpedia.org/resource/Cynthia_Lennon</td>
<td> </td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@base <http://dbpedia.org/resource/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<John_Lennon> foaf:name "John Lennon";
schema:birthDate "1940-10-09"^^xsd:date;
schema:spouse <Cynthia_Lennon> .
90 changes: 87 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8482,7 +8482,9 @@ <h3>Graph Containers</h3>
<p>If JSON-LD content is extracted as RDF [[RDF11-CONCEPTS]], it MUST be expanded into an
<a>RDF Dataset</a> using the
<a data-cite="JSON-LD11-API#deserialize-json-ld-to-rdf-algorithm">Deserialize JSON-LD to RDF Algorithm</a>
[[JSON-LD11-API]]. All <a data-cite="HTML52/semantics-scripting.html#the-script-element">script elements</a>
[[JSON-LD11-API]]. Unless a specific script is targeted
(see <a href="#locating-a-specific-json-ld-script-element" class="sectionRef"></a>),
all <a data-cite="HTML52/semantics-scripting.html#the-script-element">script elements</a>
with <code>type</code> <code>application/ld+json</code> MUST be processed and merged
into a single <a>dataset</a> with equivalent <a>blank node identifiers</a> contained in
separate script elements treated as if they were in a single document (i.e.,
Expand Down Expand Up @@ -8558,10 +8560,92 @@ <h3>Graph Containers</h3>

<p>When processing a JSON-LD
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script element</a>,
only the resolved document location of the
containing HTML document is used to establish the default <a>base IRI</a> of the enclosed
the <a data-cite="HTML52/infrastructure.html#document-base-url">Document Base URL</a>
of the containing HTML document,
as defined in [[HTML52]],
is used to establish the default <a>base IRI</a> of the enclosed
JSON-LD content.</p>

<aside class="example ds-selector-tabs"
title="Using the document base URL to establish the default base IRI">
<div class="selectors">
<button class="selected" data-selects="original">Original</button>
<button data-selects="expanded">Expanded</button>
<button data-selects="statements">Statements</button>
<button data-selects="turtle">Turtle</button>
</div>
<pre class="original selected" data-transform="updateExample"
data-content-type="text/html">
<!--
****<html>
<head>
<base href="http://dbpedia.org/resource/"/>****
<script type="application/ld+json">
< !--
{
"@context": "https://json-ld.org/contexts/person.jsonld",
"@id": ****"John_Lennon"****,
"name": "John Lennon",
"born": "1940-10-09",
"spouse": ****"Cynthia_Lennon"****
}
-- >
</script>
****</head>
</html>****
-->
</pre>
<pre class="expanded"
data-transform="updateExample"
data-result-for="Using the document base URL to establish the default base IRI-original">
<!--
[{
"@id": "http://dbpedia.org/resource/John_Lennon",
"http://xmlns.com/foaf/0.1/name": [{"@value": "John Lennon"}],
"http://schema.org/birthDate": [
{"@value": "1940-10-09", "@type": "http://www.w3.org/2001/XMLSchema#date"}
],
"http://schema.org/spouse": [
{"@id": "http://dbpedia.org/resource/Cynthia_Lennon"}
]
}]
-->
</pre>
<table class="statements"
data-result-for="Using the document base URL to establish the default base IRI-expanded"
data-to-rdf>
<thead><tr><th>Subject</th><th>Property</th><th>Value</th><th>Value Type</th></tr></thead>
<tbody>
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>foaf:name</td><td>John Lennon</td><td>&nbsp;</td></tr>
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:birthDate</td><td>1940-10-09</td><td>xsd:date</td></tr>
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:spouse</td><td>http://dbpedia.org/resource/Cynthia_Lennon</td><td>&nbsp;</td></tr>
</tbody>
</table>
<pre class="turtle"
data-content-type="text/turtle"
data-transform="updateExample"
data-result-for="Using the document base URL to establish the default base IRI-expanded"
data-to-rdf>
<!--
@base <http://dbpedia.org/resource/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<John_Lennon> foaf:name "John Lennon";
schema:birthDate "1940-10-09"^^xsd:date;
schema:spouse <Cynthia_Lennon> .
-->
</pre>
</aside>

<p>HTML allows for <a data-cite="HTML52/infrastructure.html#dynamic-changes-to-base-urls">Dynamic changes to base URLs</a>.
This specification does not require any specific behavior,
and to ensure that all systems process the <a>base IRI</a> equivalently, authors SHOULD
either use <a>absolute IRIs</a>, or explicitly as defined in <a href="#base-iri" class="sectionRef"></a>.
Implementations (particularly those natively operating in the [[!DOM]]) MAY take into consideration
<a data-cite="HTML52/infrastructure.html#dynamic-changes-to-base-urls">Dynamic changes to base URLs</a>.</p>

<section><h3>Locating a Specific JSON-LD Script Element</h3>
<p>A specific
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script element</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 108: Flattened and expanded form for the previous example
Example 109: Flattened and expanded form for the previous example
---
- "@id": _:b0
http://xmlns.com/foaf/0.1/name: Dave Longley
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 114: JSON-LD using native data types for numbers and boolean values
Example 115: JSON-LD using native data types for numbers and boolean values
---
"@context":
ex: http://example.com/vocab#
Expand Down
2 changes: 1 addition & 1 deletion yaml/Linked-Data-Dataset-compacted.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 106: Linked Data Dataset-compacted
Example 107: Linked Data Dataset-compacted
---
"@context":
- http://schema.org/
Expand Down
2 changes: 1 addition & 1 deletion yaml/Linked-Data-Dataset-expanded.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 106: Linked Data Dataset-expanded
Example 107: Linked Data Dataset-expanded
---
- "@id": http://example.com/people/alice
http://schema.org/name:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 121: Same book description in JSON-LD (avoiding contexts)
Example 122: Same book description in JSON-LD (avoiding contexts)
---
- "@id": http://purl.oreilly.com/works/45U8QJGZSQKDH8N
"@type": http://purl.org/vocab/frbr/core#Work
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 119: Same description in JSON-LD (context shared among node objects)
Example 120: Same description in JSON-LD (context shared among node objects)
---
"@context":
foaf: http://xmlns.com/foaf/0.1/
Expand Down
2 changes: 1 addition & 1 deletion yaml/Same-embedding-example-in-JSON-LD.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 113: Same embedding example in JSON-LD
Example 114: Same embedding example in JSON-LD
---
"@context":
foaf: http://xmlns.com/foaf/0.1/
Expand Down
2 changes: 1 addition & 1 deletion yaml/Same-example-with-a-list-of-values-in-JSON-LD.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 117: Same example with a list of values in JSON-LD
Example 118: Same example with a list of values in JSON-LD
---
"@context":
foaf: http://xmlns.com/foaf/0.1/
Expand Down
2 changes: 1 addition & 1 deletion yaml/Sample-JSON-LD-document.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 107: Sample JSON-LD document
Example 108: Sample JSON-LD document
---
"@context":
name: http://xmlns.com/foaf/0.1/name
Expand Down
2 changes: 1 addition & 1 deletion yaml/The-same-set-of-statements-serialized-in-JSON-LD.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Example 111: The same set of statements serialized in JSON-LD
Example 112: The same set of statements serialized in JSON-LD
---
"@context":
foaf: http://xmlns.com/foaf/0.1/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Example 104: Using the document base URL to establish the default base IRI-expanded
---
- "@id": http://dbpedia.org/resource/John_Lennon
http://xmlns.com/foaf/0.1/name:
- "@value": John Lennon
http://schema.org/birthDate:
- "@value": '1940-10-09'
"@type": http://www.w3.org/2001/XMLSchema#date
http://schema.org/spouse:
- "@id": http://dbpedia.org/resource/Cynthia_Lennon