Skip to content

Describe lists containing lists, as motivated by GeoJSON. #41

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 4 commits into from
Aug 11, 2018
Merged
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
190 changes: 184 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
prevVersion: "https://www.w3.org/TR/2014/REC-json-ld-20140116/",
previousPublishDate: "2014-01-16",
previousMaturity: "REC",
github: "https://github.com/w3c/json-ld-syntax/",

// if there a publicly available Editor's Draft, this is the link
edDraftURI: "https://w3c.github.io/json-ld/",

includePermalinks: true,
doJsonLd: true,
testSuiteURIkey: "https://json-ld.org/test-suite/",
postProcess: [internalizeTermListReferences],

// if you want to have extra CSS, append them to this list
Expand Down Expand Up @@ -95,8 +95,6 @@
note: "v1.0" }
],

github: "https://github.com/w3c/json-ld-syntax/",

// name of the WG
wg: "JSON-LD Working Group",

Expand Down Expand Up @@ -2301,9 +2299,188 @@ <h2>Sets and Lists</h2>
-->
</pre>

<p class="note">List of lists in the form of <a>list objects</a>
are not allowed in this version of JSON-LD. This decision was made due to the
extreme amount of added complexity when processing lists of lists.</p>
<p>The implementation of <a>lists</a> in RDF depends on linking anonymous nodes
together using the properties <code>rdf:first</code> and
<code>rdf:rest</code>, with the end of the list defined as the resource
<code>rdf:nil</code>. This can be represented as triples, as the following
example shows:</p>

<table class="example">
<thead><tr>
<th>Subject</th>
<th>Property</th>
<th>Value</th>
</tr></thead>
<tbody>
<tr>
<td>http://example.org/people#joebob</td>
<td>foaf:nick</td>
<td>_:b0</td>
</tr>
<tr>
<td>_:b0</td>
<td>rdf:first</td>
<td>joe</td>
</tr>
<tr>
<td>_:b0</td>
<td>rdf:rest</td>
<td>_:b1</td>
</tr>
<tr>
<td>_:b1</td>
<td>rdf:first</td>
<td>bob</td>
</tr>
<tr>
<td>_:b1</td>
<td>rdf:rest</td>
<td>_:b2</td>
</tr>
<tr>
<td>_:b2</td>
<td>rdf:first</td>
<td>jaybee</td>
</tr>
<tr>
<td>_:b2</td>
<td>rdf:rest</td>
<td>rdf:nil</td>
</tr>
</tbody>
</table>

<p>JSON-LD provides a syntactic shortcut for these lists. In Turtle, the graph would be expressed as follows:</p>

<pre class="example" data-transform="updateExample"
data-content-type="text/turtle"
title="An ordered collection of values in Turtle">
<!--
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://example.org/people#joebob> foaf:nick ("joe" "bob" "jaybe") .
-->
</pre>

<p class="changed">In JSON-LD 1.1, lists of lists, where the value of
a <a>list object</a>, may itself be a <a>list object</a>, are
fully supported. For example, in <em>GeoJSON</em> (see [[RFC7946]]),
<em>coordinates</em> are an ordered list of <em>positions</em>, which are
represented as an array of two or more numbers:</p>

<pre class="example changed"
data-content-type="application/json"
title="Coordinates expressed in GeoJSON">
{
"type": "Feature",
"bbox": [-10.0, -10.0, 10.0, 10.0],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-10.0, -10.0],
[10.0, -10.0],
[10.0, 10.0],
[-10.0, -10.0]

Choose a reason for hiding this comment

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

I feel that GeoJSON examples can be made less confusing with respect to longitude, latitude ordering by using real-world coordinates like [-105.615115, 40.255014] (latitude: 40.255 degrees N, longitude: 105.615 degrees W).

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the lists of lists feature does not preclude #34, although it becomes less important, and it does add significantly more complexity to the processing model.

]
]
}
//...
}
</pre>

<p class="changed">For these examples, it's important that values
expressed within <em>bbox</em> and <em>coordinates</em> maintain their order,
which requires the use of embedded list structures. In JSON-LD 1.1, we can
express this using recursive lists, by simply adding the appropriate context
definion:</p>

<pre class="example changed"
data-content-type="application/json"
data-transform="updateExample"
title="Coordinates expressed in JSON-LD">
{
"@context": {
"@vocab": "https://purl.org/geojson/vocab#",
"type": "@type",
"bbox": {"@container": "@list"},
"coordinates": {"@container": "@list"}

Choose a reason for hiding this comment

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

In geojson/geojson-ld#34 we discussed an @ndarray, but @list looks just as good, or better in that it's easier to explain and understand.

},
"type": "Feature",
"bbox": [-10.0, -10.0, 10.0, 10.0],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-10.0, -10.0],
[10.0, -10.0],
[10.0, 10.0],
[-10.0, -10.0]
]
]
}
####//...####
}
</pre>

<p>This is equivalent to the expanded form, which uses <a>list objects</a>:</p>

<pre class="example changed"
data-content-type="application/json"
data-transform="updateExample"
title="Coordinates expressed in JSON-LD (expanded)">
[{
"@type": ["https://purl.org/geojson/vocab#Feature"],
"https://purl.org/geojson/vocab#bbox": [{
"@list": [
{"@value": -10.0},
{"@value": -10.0},
{"@value": 10.0},
{"@value": 10.0}
]
}],
"https://purl.org/geojson/vocab#geometry": [{
"@type": ["https://purl.org/geojson/vocab#Polygon"],
"https://purl.org/geojson/vocab#coordinates": [{
"@list": [{
"@list": [
{"@list": [{"@value": -10.0}, {"@value": -10.0}]},
{"@list": [{"@value": 10.0}, {"@value": -10.0}]},
{"@list": [{"@value": 10.0}, {"@value": 10.0}]},
{"@list": [{"@value": -10.0}, {"@value": -10.0}]}

Choose a reason for hiding this comment

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

This is fine. Tagential question: is there a way to indicate to JSON-LD users that the first element of these 2-tuples is longitude and the second is latitude?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really. If the vocabulary were modeled in OWL, there may be some way to do this at that level, @iherman may know better.

Copy link
Member

Choose a reason for hiding this comment

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

To be honest, even in OWL I don't see a way to do that.

Copy link
Member

Choose a reason for hiding this comment

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

@sgillies FWIW, we've got an issue to discuss/address that. See: #7 "support @values for describing multidimensional containers"

Copy link
Member

Choose a reason for hiding this comment

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

From a graph modeling perspective, the fact that the lat/long were originally presented in a list isn't important, is it? Only the "outer" list of coordinates has value to the graph (afaict).

Copy link
Contributor

Choose a reason for hiding this comment

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

What @gkellogg and @iherman said. In JSON-LD it will just be surface syntax of arrays. At the RDF level, it will be nested rdf:Lists with no further semantics. If more semantics are required, then a different structure would also be required.

]
}]
}]
}]
}]
</pre>

<p class="changed">Note that <em>coordinates</em> includes three levels of lists.
When expressed in Turtle, this would be the following:</p>

<pre class="example changed"
data-content-type="text/turtle"
title="Coordinates expressed in Turtle">
<!--
@prefix geojson: <https://purl.org/geojson/vocab#>.

[
a geojson:Feature ;
geojson:bbox (-10.0 -10.0 10.0 10.0) ;
geojson:geometry [
a geojson:Polygon ;
geojson:coordinates (
(
(-10.0 -10.0)
(10.0 -10.0)
(10.0 10.0)
(-10.0 -10.0)
)
)
]
] .
-->
</pre>

<p>While <code>@list</code> is used to describe <em>ordered lists</em>,
the <code>@set</code> keyword is used to describe <em>unordered sets</em>.
Expand Down Expand Up @@ -5118,6 +5295,7 @@ <h2>Changes since 1.0 Recommendation of 16 January 2014</h2>
a context. When this is set, vocabulary-relative IRIs, such as the
keys of <a>node objects</a>, are expanded or compacted relative
to the <a>base IRI</a> using string concatenation.</li>
<li><a>Lists</a> may now have members which are themselves <a>lists</a>.</li>
</ul>
</section>

Expand Down