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 5 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
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,9 @@

{
"@context": {
"@vocab": "http://schema.org/"
},
"@id": "https://digitalbazaar.com/author/dlongley/",
"@type": "Person",
"name": "Dave Longley"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<table class="statements" data-result-for="Combining multiple JSON-LD script elements into a single dataset-original" data-to-rdf>
<thead><tr>
<th>Subject</th>
<th>Property</th>
<th>Value</th>
</tr></thead>
<tbody>
<tr>
<td>https://digitalbazaar.com/author/dlongley/</td>
<td>rdf:type</td>
<td>schema:Person</td>
</tr>
<tr>
<td>https://digitalbazaar.com/author/dlongley/</td>
<td>schema:name</td>
<td>Dave Longley</td>
</tr>
<tr>
<td>http://greggkellogg.net/foaf#me</td>
<td>rdf:type</td>
<td>schema:Person</td>
</tr>
<tr>
<td>http://greggkellogg.net/foaf#me</td>
<td>schema:name</td>
<td>Gregg Kellogg</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@prefix schema: <http://schema.org/> .
<https://digitalbazaar.com/author/dlongley/> a schema:Person;
schema:name "Dave Longley" .
<http://greggkellogg.net/foaf#me> a schema:Person;
schema:name "Gregg Kellogg" .
10 changes: 10 additions & 0 deletions examples/Embedding-JSON-LD-in-HTML-expanded.jsonld
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"}
]
}]
8 changes: 8 additions & 0 deletions examples/Embedding-JSON-LD-in-HTML-original.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

{
"@context": "https://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}
28 changes: 28 additions & 0 deletions examples/Embedding-JSON-LD-in-HTML-statements.table
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<table class="statements" data-result-for="Embedding JSON-LD in HTML-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>
6 changes: 6 additions & 0 deletions examples/Embedding-JSON-LD-in-HTML-turtle.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://dbpedia.org/resource/John_Lennon> foaf:name "John Lennon";
schema:birthDate "1940-10-09"^^xsd:date;
schema:spouse <http://dbpedia.org/resource/Cynthia_Lennon> .
10 changes: 10 additions & 0 deletions examples/Embedding-JSON-LD-in-HTML-with-comments-expanded.jsonld
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,8 @@

{
"@context": "https://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}
28 changes: 28 additions & 0 deletions examples/Embedding-JSON-LD-in-HTML-with-comments-statements.table
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<table class="statements" data-result-for="Embedding JSON-LD in HTML with comments-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>
6 changes: 6 additions & 0 deletions examples/Embedding-JSON-LD-in-HTML-with-comments-turtle.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://dbpedia.org/resource/John_Lennon> foaf:name "John Lennon";
schema:birthDate "1940-10-09"^^xsd:date;
schema:spouse <http://dbpedia.org/resource/Cynthia_Lennon> .
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

{
"@context": {
"@vocab": "http://schema.org/"
},
"@id": "https://digitalbazaar.com/author/dlongley/",
"@type": "Person",
"name": "Dave Longley"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<table class="statements" data-result-for="Targeting a specific script element by id-original" data-to-rdf data-target="#gregg">
<thead><tr>
<th>Subject</th>
<th>Property</th>
<th>Value</th>
</tr></thead>
<tbody>
<tr>
<td>http://greggkellogg.net/foaf#me</td>
<td>rdf:type</td>
<td>schema:Person</td>
</tr>
<tr>
<td>http://greggkellogg.net/foaf#me</td>
<td>schema:name</td>
<td>Gregg Kellogg</td>
</tr>
</tbody>
</table>
3 changes: 3 additions & 0 deletions examples/Targeting-a-specific-script-element-by-id-turtle.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@prefix schema: <http://schema.org/> .
<http://greggkellogg.net/foaf#me> a schema:Person;
schema:name "Gregg Kellogg" .
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> .
Loading