(Install package: OSW Docs - Core) |
(update from wiki-dev) Tag: 2017 source edit |
||
(One intermediate revision by the same user not shown) | |||
Line 63: | Line 63: | ||
JSON-LD allows the import of context(s) from other JSON documents | JSON-LD allows the import of context(s) from other JSON documents | ||
* Prefixes and mappings can be moved to a remote context | * Prefixes and mappings can be moved to a remote context | ||
<syntaxhighlight lang="json-ld"> | <nowiki>http://myschema.org/allmyquantitites.jsonld</nowiki><syntaxhighlight lang="json-ld"> | ||
{ | |||
"@context": { | |||
"qudt": "http://qudt.org/vocab/quantitykind/", | |||
"cap": "qudt:Capacitance", | |||
} | |||
} | |||
</syntaxhighlight><syntaxhighlight lang="json-ld"> | |||
{ | { | ||
"@context": [ | "@context": [ | ||
Line 74: | Line 81: | ||
"current": 10.0 | "current": 10.0 | ||
} | } | ||
</syntaxhighlight>< | </syntaxhighlight> | ||
== JSON-LD: Mapping (4) - Full example == | |||
Actually this example was oversimplified. A full semantic representation would be | |||
<nowiki>http://myschema.org/allmyquantitites.jsonld</nowiki><syntaxhighlight lang="json-ld"> | |||
{ | |||
"@context": { | |||
"qudt": "http://qudt.org/schema/qudt/", | |||
"qunit": "http://qudt.org/vocab/unit/", | |||
"qkind": "http://qudt.org/vocab/quantkind/", | |||
"unit": { | |||
"@id": "qudt:hasUnit", | |||
"@type": "@id" | |||
}, | |||
"value": "qudt:value" | |||
} | |||
} | |||
</syntaxhighlight><syntaxhighlight lang="json-ld"> | |||
{ | |||
"@context": "http://myschema.org/allmyquantitites.jsonld", | |||
"value": 4.0, | |||
"unit": "qunit:CentiM" | |||
} | |||
</syntaxhighlight>which would translate to <code><pint.Quantity(4.0, 'centimeter')></code> in python, see [https://github.com/hampusnasstrom/ontopint]<div> | |||
== JSON-LD: Advanced concepts== | |||
There are many more feature of JSON-LD - see specification [https://www.w3.org/TR/json-ld/] | |||
* Property types, object properties | |||
* Reverse Properties | |||
* Arrays and containers | |||
* Multi-language strings | |||
* Framing | |||
* ... | |||
In general JSON-LD is not only about annotation but also transformation and normalization | |||
== JSON-LD: | == JSON-LD: Scopes == | ||
A property / the related subobject can have it's own context. The global context is inherited. [https://json-ld.org/playground/#startTab=tab-expanded&json-ld=%7B%22%40context%22%3A%7B%22test%22%3A%22http%3A%2F%2Ftest.org%2F%22%2C%22id%22%3A%22test%3AHasId%22%2C%22name%22%3A%22test%3AHasName%22%2C%22subobject%22%3A%7B%22%40id%22%3A%22test%3AHasSubobject%22%2C%22%40context%22%3A%7B%22id%22%3A%22test%3AHasSubId%22%7D%7D%7D%2C%22name%22%3A%22Test%201%22%2C%22id%22%3A%221%22%2C%22subobject%22%3A%7B%22name%22%3A%22Test%201.1%22%2C%22id%22%3A%221.1%22%7D%7D&context=%7B%7D Playground] | A property / the related subobject can have it's own context. The global context is inherited. [https://json-ld.org/playground/#startTab=tab-expanded&json-ld=%7B%22%40context%22%3A%7B%22test%22%3A%22http%3A%2F%2Ftest.org%2F%22%2C%22id%22%3A%22test%3AHasId%22%2C%22name%22%3A%22test%3AHasName%22%2C%22subobject%22%3A%7B%22%40id%22%3A%22test%3AHasSubobject%22%2C%22%40context%22%3A%7B%22id%22%3A%22test%3AHasSubId%22%7D%7D%7D%2C%22name%22%3A%22Test%201%22%2C%22id%22%3A%221%22%2C%22subobject%22%3A%7B%22name%22%3A%22Test%201.1%22%2C%22id%22%3A%221.1%22%7D%7D&context=%7B%7D Playground] | ||
<syntaxhighlight lang="json-ld"> | <syntaxhighlight lang="json-ld"> | ||
Line 99: | Line 141: | ||
} | } | ||
</syntaxhighlight><div></div> | </syntaxhighlight><div></div> | ||
</div> | |||
==JSON-LD: Flatten a hierarchy== | ==JSON-LD: Flatten a hierarchy== | ||
Line 349: | Line 392: | ||
==JSON Documents: Next== | ==JSON Documents: Next== | ||
*[[Item:OSWee501c0fa6a9407d99c058b5ff9d55b4]] [{{fullurl:Item:OSWee501c0fa6a9407d99c058b5ff9d55b4|reveal=true}} Slideshow] | *[[Item:OSWee501c0fa6a9407d99c058b5ff9d55b4]] [{{fullurl:Item:OSWee501c0fa6a9407d99c058b5ff9d55b4 | ||
|reveal=true | |||
}} Slideshow] |
Latest revision as of 16:54, 9 August 2024
Description
No description found
Item | |
---|---|
Type(s)/Category(s) | Tutorial |
CreativeWork |
---|
Article |
---|
Tutorial | |
---|---|
Prerequisites (required) | JSON Tutorial |
Prerequisites (optional) | JSON-SCHEMA Tutorial |
Follow-up (recommended) | OO-LD Tutorial |
JSON-LD: Motivation
Problem: Everybody uses different keys
{
"c": 1.0
}
{
"cap": 1.0
}
Do they mean the same?
JSON-LD: Mapping (1)
Idea: Map keys to common vocabularies like https://www.qudt.org/doc/DOC_VOCAB-QUANTITY-KINDS.html
{
"@context": {
"c": "http://qudt.org/vocab/quantitykind/Capacitance"
},
"c": 1.0
}
{
"@context": {
"cap": "http://qudt.org/vocab/quantitykind/Capacitance"
},
"cap": 1.0
}
Do they mean the same? Yes!
JSON-LD: Mapping (2)
JSON-LD allows the definition of prefixes
{
"@context": {
"qudt": "http://qudt.org/vocab/quantitykind/",
"cap": "qudt:Capacitance",
},
"cap": 1.0
}
JSON-LD: Mapping (3) - Remote context
JSON-LD allows the import of context(s) from other JSON documents
- Prefixes and mappings can be moved to a remote context
http://myschema.org/allmyquantitites.jsonld
{
"@context": {
"qudt": "http://qudt.org/vocab/quantitykind/",
"cap": "qudt:Capacitance",
}
}
{
"@context": [
"http://myschema.org/allmyquantitites.jsonld"
{
"current": "qudt:Current",
}
],
"cap": 1.0,
"current": 10.0
}
JSON-LD: Mapping (4) - Full example
Actually this example was oversimplified. A full semantic representation would be
http://myschema.org/allmyquantitites.jsonld
{
"@context": {
"qudt": "http://qudt.org/schema/qudt/",
"qunit": "http://qudt.org/vocab/unit/",
"qkind": "http://qudt.org/vocab/quantkind/",
"unit": {
"@id": "qudt:hasUnit",
"@type": "@id"
},
"value": "qudt:value"
}
}
{
"@context": "http://myschema.org/allmyquantitites.jsonld",
"value": 4.0,
"unit": "qunit:CentiM"
}
which would translate to <pint.Quantity(4.0, 'centimeter')>
in python, see [1]
JSON-LD: Advanced concepts
There are many more feature of JSON-LD - see specification [2]
- Property types, object properties
- Reverse Properties
- Arrays and containers
- Multi-language strings
- Framing
- ...
In general JSON-LD is not only about annotation but also transformation and normalization
JSON-LD: Scopes
A property / the related subobject can have it's own context. The global context is inherited. Playground
{
"@context": {
"test": "http://test.org/",
"id": "test:HasId",
"name": "test:HasName",
"subobject": {
"@id": "test:HasSubobject",
"@context": {
"id": "test:HasSubId"
}
}
},
"name": "Test 1",
"id": "1",
"subobject": {
"name": "Test 1.1",
"id": "1.1"
}
}
JSON-LD: Flatten a hierarchy
{
"@context": {
"@version": 1.1,
"@vocab": "http://example.org/"
},
"@id": "http://example.org/SM1",
"@type": "Model",
"contains": {
"@id": "http://example.org/SM2",
"@type": "Submodel",
"contains": {
"@id": "http://example.org/SM3",
"@type": "Submodel",
"contains": {
"@id": "http://example.org/SM4",
"@type": "Submodel",
"hasParameter": {
"@id": "http://example.org/P2",
"@type": "Parameter",
"title": "P2",
"value": 2
},
"title": "Submodel 4"
},
"hasParameter": {
"@id": "http://example.org/P3",
"@type": "Parameter",
"title": "P3",
"value": 3
},
"title": "Submodel 3"
},
"hasParameter": null,
"title": "Submodel 2"
},
"hasParameter": {
"@id": "http://example.org/P1",
"@type": "Parameter",
"title": "P1",
"value": 1
}
}
=>
{
"@graph": [
{
"@id": "http://example.org/P1",
"@type": "http://example.org/Parameter",
"http://example.org/title": "P1",
"http://example.org/value": 1
},
{
"@id": "http://example.org/P2",
"@type": "http://example.org/Parameter",
"http://example.org/title": "P2",
"http://example.org/value": 2
},
{
"@id": "http://example.org/P3",
"@type": "http://example.org/Parameter",
"http://example.org/title": "P3",
"http://example.org/value": 3
},
{
"@id": "http://example.org/SM1",
"@type": "http://example.org/Model",
"http://example.org/contains": {
"@id": "http://example.org/SM2"
},
"http://example.org/hasParameter": {
"@id": "http://example.org/P1"
}
},
{
"@id": "http://example.org/SM2",
"@type": "http://example.org/Submodel",
"http://example.org/contains": {
"@id": "http://example.org/SM3"
},
"http://example.org/title": "Submodel 2"
},
{
"@id": "http://example.org/SM3",
"@type": "http://example.org/Submodel",
"http://example.org/contains": {
"@id": "http://example.org/SM4"
},
"http://example.org/hasParameter": {
"@id": "http://example.org/P3"
},
"http://example.org/title": "Submodel 3"
},
{
"@id": "http://example.org/SM4",
"@type": "http://example.org/Submodel",
"http://example.org/hasParameter": {
"@id": "http://example.org/P2"
},
"http://example.org/title": "Submodel 4"
}
]
}
JSON-LD: Rebuild a hierarchy
{
"@context": {
"@vocab": "http://example.org/",
"ex": "http://example.org/",
"contains": {
"@type": "@id"
},
"hasParameter": {"@type": "@id"},
"parameterOf": {"@type": "@id", "@reverse": "hasParameter"},
"submodels": "@graph"
},
"@id": "ex:SM1",
"@type": "Model",
"contains": "ex:SM2",
"hasParameter": "ex:P1",
"submodels": [
{
"@id": "ex:SM2",
"@type": "Submodel",
"title": "Submodel 2",
"contains": "ex:SM3"
},
{
"@id": "ex:SM3",
"@type": "Submodel",
"title": "Submodel 3",
"contains": "ex:SM4"
},
{
"@id": "ex:SM4",
"@type": "Submodel",
"title": "Submodel 4",
"hasParameter": "ex:P2"
},
{
"@type": "Parameter",
"@id": "ex:P1",
"title": "P1",
"value": 1.0
},
{
"@type": "Parameter",
"@id": "ex:P2",
"title": "P2",
"value": 2.0
},
{
"@type": "Parameter",
"@id": "ex:P3",
"title": "P3",
"value": 3.0,
"parameterOf": "ex:SM3"
}
]
}
{
"@context": {
"@version": 1.1,
"@vocab": "http://example.org/"
},
"@type": "Model",
"contains": {
"@type": "Submodel",
"contains": {
"@type": "Submodel"
},
"hasParameter": {
"@type": "Parameter"
}
},
"hasParameter": {
"@type": "Parameter"
}
}
{
"@context": {
"@version": 1.1,
"@vocab": "http://example.org/"
},
"@id": "http://example.org/SM1",
"@type": "Model",
"contains": {
"@id": "http://example.org/SM2",
"@type": "Submodel",
"contains": {
"@id": "http://example.org/SM3",
"@type": "Submodel",
"contains": {
"@id": "http://example.org/SM4",
"@type": "Submodel",
"hasParameter": {
"@id": "http://example.org/P2",
"@type": "Parameter",
"title": "P2",
"value": 2
},
"title": "Submodel 4"
},
"hasParameter": {
"@id": "http://example.org/P3",
"@type": "Parameter",
"title": "P3",
"value": 3
},
"title": "Submodel 3"
},
"hasParameter": null,
"title": "Submodel 2"
},
"hasParameter": {
"@id": "http://example.org/P1",
"@type": "Parameter",
"title": "P1",
"value": 1
}
}
JSON Documents: Next
jsondata
required_predecessor |
| |||||
---|---|---|---|---|---|---|
optional_predecessor |
| |||||
type |
| |||||
uuid | "91148877-1ea4-49a6-a340-51f8213d7f2f" | |||||
name | "JsonLdTutorial" | |||||
label |
| |||||
image | "File:OSWcdf1d2e2f5d143aeb13096013632c8cb.png" | |||||
recommended_successor |
|