Item:OSW911488771ea449a6a34051f8213d7f2f
(Install package: OSW Docs - Core) |
(Update package: OSW Docs - Core) |
||
Line 349: | Line 349: | ||
==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 07:11, 13 November 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) | JSON Application Tutorial |
JSON-LD: Motivation
Problem: Everybody uses different keys
JSON Dataset 1
{
"c": 1.0
}
JSON Dataset 2
{
"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
JSON Dataset 1
{
"@context": {
"c": "http://qudt.org/vocab/quantitykind/Capacitance"
},
"c": 1.0
}
JSON Dataset 2
{
"@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
{
"@context": [
"http://myschema.org/allmyquantitites.jsonld"
{
"current": "qudt:Current",
}
],
"cap": 1.0,
"current": 10.0
}
JSON-LD: Mapping (3) - Nested context
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
Input
{
"@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
}
}
=>
Flattened output
{
"@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
Input
{
"@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"
}
]
}
Frame
{
"@context": {
"@version": 1.1,
"@vocab": "http://example.org/"
},
"@type": "Model",
"contains": {
"@type": "Submodel",
"contains": {
"@type": "Submodel"
},
"hasParameter": {
"@type": "Parameter"
}
},
"hasParameter": {
"@type": "Parameter"
}
}
Framed output
{
"@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 |
|