Skip to content

Commit 7ac7698

Browse files
committed
webanno: using JSON-LD contexts
This revises some parts of the previous commit, keeping things simpler and foregoing the need to interpret JSON-LD contexts.
1 parent cb4055c commit 7ac7698

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ The following overriding constraints apply only for compatibility with RDF:
167167
* The public identifier of keys *MUST* be able to be transformed into an IRI as follows:
168168
* It it already an IRI by itself (no transformation necessary).
169169
* It forms an IRI when appended to the public identifier of the annotation data set. If identifier of the annotation data set does not end in `/` or `#`, an extra `/` *SHOULD* be inserted as delimiter in the concatenation.
170+
* An exception to this rule is if the intended output is JSON-LD. A dataset identifier *MAY* be explicitly exempted via a parameter and keys *SHOULD* then be propagated as-is (they may function as aliases) and it is up to the JSON-LD context to resolve them.
170171
* There *SHOULD* be a public identifier for each `Annotation`
171172

172173
### Offsets

extensions/stam-webannotations/README.md

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ the JSON-LD file then correspond one-to-one to the STAM datakeys in the set.
5656
This allows us to use much of the web annotation vocabulary from STAM without
5757
any complicated mappings. We will refer to this as the w3anno set in this
5858
documentation, simply to avoid having to mention the full URI every time.
59+
The full mechanism that enables this behaviour is explained in the section on
60+
referencing external resources and using JSON-LD contexts.
5961

6062
Let's illustrate this with an example. Consider the following STAM
6163
Annotation in STAM JSON (partial excerpt) in which we express an annotation
@@ -400,7 +402,7 @@ A `MultiSelector` *MAY* also be mapped simply to multiple `target` elements in
400402
the WebAnnotation output. Recall that this means that the annotation applies to
401403
all of targets equally, individually and independently.
402404

403-
### Referencing external resources and interpreting JSON-LD contexts
405+
### Referencing external resources and using JSON-LD contexts
404406

405407
A lot of the value in using linked data comes from the ability to actually
406408
*link* to external resources, which may live anywhere and are identified by an
@@ -413,12 +415,32 @@ If we convert from STAM to Web Annotations, the distinction between
413415
IRIs and string literals becomes important again. Fortunately, the JSON-LD
414416
serialization solves this problem for us. JSON by itself does
415417
not have the distinction either, but the JSON-LD context adds these semantics.
416-
When converting from STAM to Web Annotations, users *SHOULD* be able to specify
417-
additional JSON-LD contexts with are then added to the `@context` part of the
418-
output. For this to work, the converter *SHOULD* parse the specified JSON-LD
419-
contexts and use the aliases defined in it.
420418

421-
If this is to abstract, consider the following STAM JSON example (partial excerpt):
419+
For this to work a STAM to Web Annotation converter *SHOULD* accept the following parameter:
420+
421+
* one or **JSON-LD Context URL**s: This will be propagated directly to the `@context` portion of the output.
422+
The converter is *NOT REQUIRED* to actually parse and interpret the JSON-LD context.
423+
424+
The URL to a JSON-LD context doubles as STAM dataset identifier: Any STAM dataset
425+
passed via this parameter *MUST* have its keys directly passed as-is, as if
426+
they are aliases. There is one exception: this *MUST NOT* be applies to keys that are already full IRIs.
427+
That means the standard rules for forming IRIs by concatenating the dataset ID (if an IRI)
428+
and the key ID (if not an IRI) will be bypassed in this case.
429+
430+
The `http://www.w3.org/ns/anno.jsonld` context *MUST* be implied already by
431+
the converter and does not need to be passed explicitly. Converters *MAY* implement
432+
an additional parameter (opt-in or opt-out) to automatically detect whether there are any used dataset
433+
IDs ending in `.json` or `.jsonld` and add them to this list. This simplifies things for the caller.
434+
435+
It is always the responsibility of the caller (not the converter) to ensure
436+
that the keys from these datasets are indeed defined as aliases in the JSON-LD
437+
context. If this is not the case, then the resulting JSON-LD output can contain
438+
aliases that do not expand to IRIs and therefore are not valid RDF. It is also
439+
the responsibility of the caller to ensure that keys from multiple such
440+
datasets do not conflict, as this effectively strips the namespace function
441+
datasets normally fulfill.
442+
443+
This can all sound rather abstract, so let's illustrate it with the following STAM JSON example (partial excerpt):
422444

423445
```json
424446
{
@@ -427,7 +449,7 @@ If this is to abstract, consider the following STAM JSON example (partial excerp
427449
"data": [
428450
{
429451
"@type": "AnnotationData",
430-
"set": "https://example.org/my_vocab"
452+
"set": "https://example.org/my_vocab.jsonld"
431453
"key": "review",
432454
"value": "https://example.org/my_review",
433455
},
@@ -438,27 +460,25 @@ If this is to abstract, consider the following STAM JSON example (partial excerp
438460
}
439461
```
440462

441-
This translates to the following web annotation (partial excerpt) in JSON-LD:
463+
This translates to the following web annotation (partial excerpt) in JSON-LD, provided that we explicitly pass `https://example.org/my_vocab.jsonld` as parameter to the converter, telling it to add it to the context:
442464

443465

444466
```json
445467
{
446-
"@context": "http://www.w3.org/ns/anno.jsonld",
468+
"@context": [ "http://www.w3.org/ns/anno.jsonld", "https://example.org/my_vocab.jsonld" ]
447469
"id": "https://example.org/annotation1",
448-
"creator": "proycon",
449470
"body": {
450471
"type": "DataSet",
451-
"https://example.org/my_vocab/review": "https://example.org/my_review",
472+
"review": "https://example.org/my_review",
452473
}
453474
"target": {
454475
...
455476
}
456477
}
457478
```
458479

459-
At this point `https://example.org/my_review` would be just string literal. To
460-
solve this, we make a JSON-LD context for our vocabulary, let's pretend we
461-
host this at `https://example.org/my_vocab.jsonld`:
480+
At this point the interpretation of `review` as either an IRI or string literal, is determined by the JSON-LD context.
481+
Assume we create the following JSON-LD context and serve it at `https://example.org/my_vocab.jsonld`:
462482

463483
```json
464484
{
@@ -472,31 +492,13 @@ host this at `https://example.org/my_vocab.jsonld`:
472492
}
473493
```
474494

475-
Now all we have to do is pass our STAM to web annotation converter our extra
476-
context to include. STAM to Webannotation converters parse this JSON-LD context
477-
and resolve the full IRIs to the aliases mentioned. We then get the following
478-
output instead:
479-
480-
```json
481-
{
482-
"@context": [ "http://www.w3.org/ns/anno.jsonld","https://example.org/my_vocab.jsonld"],
483-
"id": "https://example.org/annotation1",
484-
"creator": "proycon",
485-
"body": {
486-
"type": "DataSet",
487-
"review": "https://example.org/my_review",
488-
}
489-
"target": {
490-
...
491-
}
492-
}
493-
```
494-
495-
The predicate which we saw in expanded form before is now resolved to its alias and any JSON-LD capable parser will now
496-
interpret the value as an IRI rather than a string literal, as that is how it is defined in the context (via `@type`: `@id`).
495+
This will ensure the predicate is value interpreted as an IRI rather than a
496+
string literal, by any JSON-LD aware processors.
497497

498-
Because of the extra type information and cleaner web annotation output, the
499-
use of JSON-LD contexts for your vocabulary is *RECOMMENDED*.
498+
Because of the extra type information, the simpler STAM representation and the
499+
cleaner web annotation output that is a one-to-one mapping of the former, the
500+
use of JSON-LD contexts in your dataset IDs is *RECOMMENDED* if you do
501+
conversion to web annotation.
500502

501503
### Hierarchical data structures
502504

0 commit comments

Comments
 (0)