Skip to content

Commit f3a7af5

Browse files
committed
First stab at describing @direction in the syntax document.
Note that examples won't build properly until it's fully supported in the Ruby implementation. For #11.
1 parent 3a9dbec commit f3a7af5

File tree

3 files changed

+253
-11
lines changed

3 files changed

+253
-11
lines changed

common/extract-examples.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ def table_to_dataset(table)
119119
# We might think something was an IRI, but determine that it's not
120120
object = RDF::Literal(object.to_s, language: cell.to_sym)
121121
end
122+
when 'Direction'
123+
case cell
124+
when '-', /^\s*$/
125+
else
126+
value = object.to_s
127+
language = object.language
128+
object = RDF::Node.new
129+
repo << RDF::Statement.new(object, RDF.value, RDF::Literal(value))
130+
repo << RDF::Statement.new(object, RDF.to_uri + "language", RDF::Literal(language.to_s)) if language
131+
repo << RDF::Statement.new(object, RDF.to_uri + "direction", RDF::Literal(cell.to_s))
132+
# We might think something was an IRI, but determine that it's not
133+
end
122134
end
123135
end
124136
repo << RDF::Statement.new(subject, predicate, object, graph_name: gname)

common/terms.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@
174174
whose value MUST be a <a>string</a> representing a [[BCP47]] language code or <code>null</code>.</dd>
175175
<dt><dfn data-cite="JSON-LD11#dfn-default-object">default object</dfn></dt><dd>
176176
A <a>default object</a> is a <a>map</a> that has a <code>@default</code> key.</dd>
177+
<dt><dfn data-cite="JSON-LD11#dfn-text-direction">default text direction</dfn></dt><dd>
178+
The <a>default text direction</a> is the direction used when a string does not have a direction associated with it directly.
179+
It can be set in the <a>context</a> using the <code>@direction</code> key
180+
whose value MUST be one of the strings `"ltr"`, `"rtl"`, or <code>null</code>.</dd>
177181
<dt><dfn data-cite="JSON-LD11#dfn-embedded-context">embedded context</dfn></dt><dd>
178182
An embedded <a>context</a> is a context which appears
179183
as the <code>@context</code> <a>entry</a> of one of the following:

index.html

Lines changed: 237 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ <h2>Syntax Tokens and Keywords</h2>
522522
developers to express specific identifiers in a compact manner. The
523523
<code>@context</code> keyword is described in detail in
524524
<a class="sectionRef" href="#the-context"></a>.</dd>
525+
<dt class="changed"><code>@direction</code></dt>
526+
<dd class="changed">Used to set the <dfn>text direction</dfn> of a <a>JSON-LD value</a>,
527+
which are not <a>typed values</a> (e.g. <a>strings</a>, or <a>language-tagged strings</a>).
528+
This keyword is described in
529+
<a class="sectionRef" href="#string-internationalization"></a>.</dd>
525530
<dt><code>@id</code></dt>
526531
<dd>Used to uniquely identify <a>node objects</a> that are being described in the document
527532
with <a>IRIs</a> or
@@ -4460,7 +4465,7 @@ <h3>Using the Document Base for the Default Vocabulary</h3>
44604465

44614466
<p>When transformed into RDF, the JSON literal will have a lexical form based on
44624467
a specific serialization of the JSON,
4463-
as described in <a data-cite="JSON-LD11-API#round-tripping">Compaction algorithm</a> of [[JSON-LD11-API]]
4468+
as described in <a data-cite="JSON-LD11-API#compaction-algorithm">Compaction algorithm</a> of [[JSON-LD11-API]]
44644469
and <a href="#the-rdf-json-datatype" class="sectionRef">the JSON datatype</a>.</p>
44654470

44664471
<p>The following example shows an example of a <a>JSON Literal</a> contained as the
@@ -4944,7 +4949,6 @@ <h3>Using the Document Base for the Default Vocabulary</h3>
49444949
</section>
49454950

49464951
<section class="informative"><h2>String Internationalization</h2>
4947-
49484952
<p>At times, it is important to annotate a <a>string</a>
49494953
with its language. In JSON-LD this is possible in a variety of ways.
49504954
First, it is possible to define a <a>default language</a> for a JSON-LD document
@@ -5009,8 +5013,9 @@ <h3>Using the Document Base for the Default Vocabulary</h3>
50095013
</aside>
50105014

50115015
<p>The example above would associate the <code>ja</code> language
5012-
code with the two <a>strings</a> <em>花澄</em> and <em>科学者</em>.
5013-
<a data-cite="BCP47#section-2">Languages codes</a> are defined in [[BCP47]]. The <a>default language</a> applies to all
5016+
code with the two <a>strings</a> <em>花澄</em> and <em>科学者</em>
5017+
<a data-cite="BCP47#section-2">Languages codes</a> are defined in [[BCP47]].
5018+
The <a>default language</a> applies to all
50145019
<a>string</a> values that are not <a href="#type-coercion">type coerced</a>.</p>
50155020

50165021
<p>To clear the <a>default language</a> for a subtree, <code>@language</code> can
@@ -5156,6 +5161,204 @@ <h3>Using the Document Base for the Default Vocabulary</h3>
51565161

51575162
<p>See <a href="#language-maps" class="sectionRef"></a> for a description
51585163
of using <a>language maps</a> to set the language of mapped values.</p>
5164+
5165+
<section class="changed informative"><h3>Text Direction</h3>
5166+
<p>It is also possible to annotate a <a>string</a>, or <a>language-tagged string</a>,
5167+
with its <a>text direction</a>.
5168+
As with language, it is possible to define a <a>default text direction</a> for a JSON-LD document
5169+
by setting the `@direction` key in the <a>context</a>:</p>
5170+
5171+
<aside class="example ds-selector-tabs changed"
5172+
title="Setting the default text direction of a JSON-LD document">
5173+
<div class="selectors">
5174+
<button class="selected" data-selects="compacted">Compacted (Input)</button>
5175+
<button data-selects="expanded">Expanded (Result)</button>
5176+
<button data-selects="statements">Statements</button>
5177+
<button data-selects="turtle">Turtle (drops direction)</button>
5178+
<button data-selects="turtle-dt">Turtle (with datatype)</button>
5179+
<button data-selects="turtle-bn">Turtle (with bnode structure)</button>
5180+
<a class="playground" target="_blank"></a>
5181+
</div>
5182+
<pre class="compacted input selected nohighlight" data-transform="updateExample">
5183+
<!--
5184+
{
5185+
"@context": {
5186+
"title": "http://example.org/title",
5187+
"publisher": "http://example.org/publisher",
5188+
####...####
5189+
****"@language": "ar",
5190+
"@direction": "rtl"****
5191+
},
5192+
****"title": "HTML و CSS: تصميم و إنشاء مواقع الويب"****,
5193+
"publisher": "مكتبة"****
5194+
}
5195+
-->
5196+
</pre>
5197+
<pre class="expanded result nohighlight"
5198+
data-transform="updateExample"
5199+
data-result-for="Setting the default text direction of a JSON-LD document-compacted">
5200+
<!--
5201+
[{
5202+
"http://example.org/title": [{"@value": ****"HTML و CSS: تصميم و إنشاء مواقع الويب"****, "@language": "ar", ****"@direction": "rtl"****}],
5203+
"http://example.org/publisher": [{"@value": ****"مكتبة"****, "@language": "ar", ****"@direction": "rtl"****}]
5204+
}]
5205+
-->
5206+
</pre>
5207+
<table class="statements"
5208+
data-result-for="Setting the default text direction of a JSON-LD document-expanded"
5209+
data-to-rdf>
5210+
<thead><tr><th>Subject</th><th>Property</th><th>Value</th><th>Language</th><th>Direction</th></tr></thead>
5211+
<tbody>
5212+
<tr><td>_:b0</td><td>http://example.org/title</td><td>HTML و CSS: تصميم و إنشاء مواقع الويب</td><td>ar</td><td>rtl</td></tr>
5213+
<tr><td>_:b0</td><td>http://example.org/publisher</td><td>مكتبة</td><td>ar</td><td>rtl</td></tr>
5214+
</tbody>
5215+
</table>
5216+
<pre class="turtle nohighlight"
5217+
data-content-type="text/turtle"
5218+
data-result-for="Setting the default text direction of a JSON-LD document-expanded"
5219+
data-transform="updateExample"
5220+
data-to-rdf>
5221+
<!--
5222+
@prefix ex: <http://example.org/> .
5223+
5224+
# Note that this version drops the text direction.
5225+
[
5226+
ex:title ****"HTML و CSS: تصميم و إنشاء مواقع الويب"****@ar;
5227+
ex:publisher ****"مكتبة"****@ar
5228+
] .
5229+
-->
5230+
</pre>
5231+
<pre class="turtle-dt nohighlight"
5232+
data-content-type="text/turtle"
5233+
data-result-for="Setting the default text direction of a JSON-LD document-expanded"
5234+
data-transform="updateExample"
5235+
data-to-rdf>
5236+
<!--
5237+
@prefix ex: <http://example.org/> .
5238+
@prefix i18n: <https://www.w3.org/i18n#> .
5239+
5240+
# Note that this version preserves the text direction using a datatype.
5241+
[
5242+
ex:title ****"HTML و CSS: تصميم و إنشاء مواقع الويب"^^i18n:ar_rtl****;
5243+
ex:publisher ****"مكتبة"^^i18n:ar_rtl****
5244+
] .
5245+
-->
5246+
</pre>
5247+
<pre class="turtle-bn nohighlight"
5248+
data-content-type="text/turtle"
5249+
data-result-for="Setting the default text direction of a JSON-LD document-expanded"
5250+
data-transform="updateExample"
5251+
data-to-rdf>
5252+
<!--
5253+
@prefix ex: <http://example.org/> .
5254+
5255+
# Note that this version preserves the text direction using a bnode structure.
5256+
[
5257+
ex:title ****[
5258+
rdf:value "HTML و CSS: تصميم و إنشاء مواقع الويب",
5259+
rdf:language "ar",
5260+
rdf:direction "rtl"
5261+
]****;
5262+
ex:publisher ****[
5263+
rdf:value "مكتبة",
5264+
rdf:language "ar",
5265+
rdf:direction "rtl"
5266+
]****
5267+
] .
5268+
-->
5269+
</pre>
5270+
</aside>
5271+
5272+
<p>The example above would associate the <code>ar</code> language
5273+
and "rtl" text direction
5274+
code with the two <a>strings</a> <em>HTML و CSS: تصميم و إنشاء مواقع الويب</em> and <em>مكتبة</em>.
5275+
The <a>default text direction</a> applies to all
5276+
<a>string</a> values that are not <a href="#type-coercion">type coerced</a>.</p>
5277+
5278+
<p>To clear the <a>default text direction</a> for a subtree, <code>@direction</code> can
5279+
be set to <code>null</code> in an intervening context, such as a <a>scoped context</a> as follows:</p>
5280+
5281+
<pre class="example nohighlight" data-transform="updateExample"
5282+
title="Clearing default language">
5283+
<!--
5284+
{
5285+
"@context": {
5286+
####...####
5287+
****"@version": 1.1,****
5288+
"@vocab": "http://example.com/",
5289+
"@language": "ar",
5290+
"@direction": "rtl",
5291+
"details": {
5292+
****"@context": {
5293+
"@direction": null
5294+
}****
5295+
}
5296+
},
5297+
"title": "HTML و CSS: تصميم و إنشاء مواقع الويب",
5298+
"details": {"genre": "Technical Publication"}
5299+
}
5300+
-->
5301+
</pre>
5302+
5303+
<p>Second, it is possible to associate a text direction with a specific <a>term</a>
5304+
using an <a>expanded term definition</a>:</p>
5305+
5306+
<pre class="example nohighlight" data-transform="updateExample"
5307+
title="Expanded term definition with language">
5308+
<!--
5309+
{
5310+
"@context": {
5311+
####...####
5312+
"ex": "http://example.com/vocab/",
5313+
"@language": "ar",
5314+
"@direction": "rtl",
5315+
"publisher": { "@id": "ex:name", ****"@direction": null**** },
5316+
"title": { "@id": "ex:title" },
5317+
"title_en": { "@id": "ex:title", ****"@language": "en", "@direction": "ltr"**** }
5318+
},
5319+
****"publisher": "مكتبة",
5320+
"title": "HTML و CSS: تصميم و إنشاء مواقع الويب",
5321+
"title_en": "HTML and CSS: Design and Build Websites"****####,
5322+
...####
5323+
}
5324+
-->
5325+
</pre>
5326+
5327+
<p>The example above would associate <em>مكتبة</em> with the specified default
5328+
language code <code>ar</code> and no <a>text direction</a>,
5329+
<em>HTML and CSS: Design and Build Websites</em> with the language code
5330+
<code>en</code> and <a>text direction</a> `ltr`,
5331+
and <em>HTML و CSS: تصميم و إنشاء مواقع الويب</em> with the language code <code>ar</code>
5332+
and <a>text direction</a> `rtl`.</p>
5333+
5334+
<p class="note">Text direction associations are only applied to plain
5335+
<a>strings</a> and <a>language-tagged strings</a>.
5336+
<a>Typed values</a> or values that are subject to <a href="#type-coercion">type coercion</a>
5337+
are not given a text direction.</p>
5338+
5339+
<p>Third, it is possible to override the <a>default text direction</a> by using a
5340+
<a>value object</a>:</p>
5341+
5342+
<pre class="example nohighlight" data-transform="updateExample"
5343+
title="Overriding default language using an expanded value">
5344+
<!--
5345+
{
5346+
"@context": {
5347+
####...####
5348+
"@language": "ar",
5349+
"@direction": "rtl"
5350+
},
5351+
"title": "HTML و CSS: تصميم و إنشاء مواقع الويب",
5352+
"author": ****{
5353+
"@value": "Jon Duckett",
5354+
"@language": "en"
5355+
}****
5356+
}
5357+
-->
5358+
</pre>
5359+
5360+
<p>See [[[string-meta]]] [[string-meta]] for a deeper discussion of <a>text direction</a>.</p>
5361+
</section>
51595362
</section>
51605363

51615364
</section>
@@ -11238,8 +11441,8 @@ <h1>Data Model</h1>
1123811441
<p>JSON-LD is a serialization format for Linked Data based on JSON.
1123911442
It is therefore important to distinguish between the syntax, which is
1124011443
defined by JSON in [[RFC8259]], and the <dfn>data model</dfn> which is
11241-
an extension of the <a data-cite="RDF11-CONCEPTS#data-model">RDF data model</a> [[RDF11-CONCEPTS]]. The precise
11242-
details of how JSON-LD relates to the RDF data model are given in
11444+
an extension of the <a data-cite="RDF11-CONCEPTS#data-model">RDF data model</a> [[RDF11-CONCEPTS]].
11445+
The precise details of how JSON-LD relates to the RDF data model are given in
1124311446
<a class="sectionRef" href="#relationship-to-rdf"></a>.</p>
1124411447

1124511448
<p>To ease understanding for developers unfamiliar with the RDF model, the
@@ -11320,6 +11523,9 @@ <h1>Data Model</h1>
1132011523
The language tag MUST be well-formed according to section
1132111524
<a data-cite="BCP47#section-2.2.9">2.2.9 Classes of Conformance</a>
1132211525
of [[BCP47]].</li>
11526+
<li class="changed">Either <a>strings</a>, or <a>language-tagged strings</a> may include
11527+
a <a>text direction</a>, which represents an extension to the underlying
11528+
<a data-cite="RDF11-CONCEPTS#data-model">RDF data model</a>.</li>
1132311529
<li>A <a>list</a> is a sequence of zero or more <a>IRIs</a>,
1132411530
<a>blank nodes</a>, and <a>JSON-LD values</a>.
1132511531
<a>Lists</a> are interpreted as
@@ -11744,13 +11950,17 @@ <h2>Graph Objects</h2>
1174411950
<h2>Value Objects</h2>
1174511951

1174611952
<p>A <a>value object</a> is used to explicitly associate a type or a
11747-
language with a value to create a <a>typed value</a> or a <a>language-tagged
11748-
string</a>.</p>
11953+
language with a value to create a <a>typed value</a> or a <a>language-tagged string</a>
11954+
<span class="changed">and possibly associate a <a>text direction</a></span>.</p>
1174911955

1175011956
<p>A <a>value object</a> MUST be a <a>map</a> containing the
1175111957
<code>@value</code> key. It MAY also contain an <code>@type</code>,
11752-
an <code>@language</code>, an <code>@index</code>, or an <code>@context</code> key but MUST NOT contain
11753-
both an <code>@type</code> and an <code>@language</code> key at the same time.
11958+
an <code>@language</code>,
11959+
<span class="changed">an `@direction`,</span>
11960+
an <code>@index</code>, or an <code>@context</code> key but MUST NOT contain
11961+
both an <code>@type</code> and either <code>@language</code>
11962+
<span class="changed">or `@direction`</span>
11963+
keys at the same time.
1175411964
A <a>value object</a> MUST NOT contain any other keys that expand to an
1175511965
<a>absolute IRI</a> or <a>keyword</a>.</p>
1175611966

@@ -11771,6 +11981,9 @@ <h2>Value Objects</h2>
1177111981
<p>The value associated with the <code>@language</code> key MUST have the
1177211982
<a data-cite="BCP47#section-2.1.1">lexical form</a> described in [[BCP47]], or be <a>null</a>.</p>
1177311983

11984+
<p>The value associated with the <code>@direction</code> key MUST be
11985+
one of `ltr` or `rtl`, or be <a>null</a>.</p>
11986+
1177411987
<p>The value associated with the <code>@index</code> key MUST be a
1177511988
<a>string</a>.</p>
1177611989

@@ -11786,7 +11999,12 @@ <h2>Value Patterns</h2>
1178611999
extends a <a>value object</a> to allow
1178712000
<a>entries</a> used specifically for <a>framing</a>.</p>
1178812001
<ul>
11789-
<li>The values of <code>@value</code>, <code>@language</code> and <code>@type</code> MAY additionally be
12002+
<li>The values of
12003+
<code>@value</code>,
12004+
<code>@language</code>,
12005+
<code class="changed">@direction</code> and
12006+
<code>@type</code>
12007+
MAY additionally be
1179012008
an empty <a>map</a> (<a data-cite="JSON-LD11-FRAMING#dfn-wildcard">wildcard</a>),
1179112009
an <a>array</a> containing only an empty <a>map</a>,
1179212010
an empty <a>array</a> (<a data-cite="JSON-LD11-FRAMING#dfn-match-none">match none</a>)
@@ -12381,6 +12599,14 @@ <h2>Relationship to RDF</h2>
1238112599
and <code>false</code>. The JSON-LD 1.1 Processing Algorithms and API specification [[JSON-LD11-API]]
1238212600
defines the <a data-cite="JSON-LD11-API#data-round-tripping">conversion rules</a>
1238312601
between JSON's native data types and RDF's counterparts to allow round-tripping.</li>
12602+
<li class="changed">As an extension to the <a data-cite="RDF11-CONCEPTS#data-model">RDF data model</a>,
12603+
<em>typed literals</em>, where the datatype is `xsd:string`, or <a>language-tagged strings</a>
12604+
MAY include a <a>text direction</a>.
12605+
As there is not yet any standardized mechanism for representing the text direction
12606+
of <a>RDF literals</a>, the JSON-LD to RDF transformation can loose this direction.
12607+
The <a data-cite="JSON-LD11-API#deserialize-json-ld-to-rdf-algorithm">Deserialize JSON-LD to RDF Algorithm</a>
12608+
also provides a means of representing <a>text direction</a>
12609+
using non-standardized mechanisms which will preserve round-tripping through RDF.</li>
1238412610
</ul>
1238512611

1238612612
<p class="note">The use of <a>blank node identifiers</a> to label properties is obsolete,

0 commit comments

Comments
 (0)