Wikidata/Development/Phase 2 JSON: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
Undo revision 20323430 by 2600:387:0:809:0:0:0:71 (talk)
Tag: Undo
 
(7 intermediate revisions by 3 users not shown)
Line 18: Line 18:
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
{
{
"property" : property_id,
"value" : serialization_of_value_as_an_object,
"value" : serialization_of_value_as_an_object,
serialization_of_qualifiers,
serialization_of_qualifiers,
Line 30: Line 29:
Qualifiers are serialized as a key-value pair with the key being the property id of the qualifier and the value being an array of serialized values (an array because the same qualifier can be used several times).
Qualifiers are serialized as a key-value pair with the key being the property id of the qualifier and the value being an array of serialized values (an array because the same qualifier can be used several times).


The different snaks are represented in the values. This allows for the qualifiers to be simple key-value pairs.
The different snaks are represented through the value serialization. This allows for the qualifiers to be key-value pairs.


== Example ==
=== Value serialization ===
The value serialization depends on the snak type and the data type. The snak type is given explicitly. If the snak type is "none" or "some", then no "value" key is present.

==== Datatype item ====
The following serializes a value of type "item" with a PropertyValueSnak:
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
{
berlin = {
"id": "q109",
"snaktype" : "value",
"sitelinks": {
"value" : "q123"
}
"enwiki": {
"site": "enwiki",
"title": "Berlin"
},
"dewiki": {
"site": "dewiki",
"title": "Berlin"
}
},
"labels": {
"en": {
"language": "en",
"value": "Berlin"
}
},
"descriptions": {
"en": {
"language": "en",
"value": "The capital of Germany"
}
},
"aliases": {
"en": [{
"language": "en",
"value": "City of Berlin"
}, {
"language": "en",
"value": "B\u00e4rlin"
}]
},
"statements" : {
"p17" : {
"s28" : {
"property" : "p17",
"value" : {
"value" : "q123",
"type" : "item"
}
"references" : {
"r21" : {
"p32" : [{
"value" : "q1234",
"type" : "item"
}],
"p23" : [{
"value" : 171,
"type" : "number"
}]
},
"r38" : {
"p32" : [{
"value" : "q372",
"type" : "item"
}]
}
}
}
},
"p2313" : {
"s33" : {
"property" : "p2313",
"value" : {
"value" : "3500000",
"type" : "number",
"accuracy" : "100000"
},
"p1234" : [{
"value" : "2011-01-01T00:00:00",
"type" : "time",
"accuracy" : "year"
}]
},
"s43" : {
"property" : "p2313",
"value" : {
"value" : "5000",
"type" : "number",
"accuracy" : "1000"
},
"p1234" : [{
"value" : "1500-01-01-T00:00:00",
"type" : "time",
"accuracy" : "century"
}]
}
}
}
}
</syntaxhighlight>
</syntaxhighlight>


The following serializes a value of type "item" with a PropertyNoValueSnak:
=== Slightly more readable example ===
<syntaxhighlight lang="javascript">
The following replaces the IDs with the labels. Not up to date!!
{
"snaktype" : "none"
}
</syntaxhighlight>


The following serializes a value of type "item" with a PropertySomeValueSnak:
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
{
berlin = {
"id": 109,
"snaktype" : "some"
}
"sitelinks": {
</syntaxhighlight>
"enwiki": {

"site": "enwiki",
PropertyIntervalSnak and PropertySomeIntervalSnak can not be used with datatype "item".
"title": "Berlin"

},
==== Datatype commons media ====
"dewiki": {
The following serializes a value of type "Commons media" with a PropertyValueSnak.
"site": "dewiki",
<syntaxhighlight lang="javascript">
"title": "Berlin"
{
}
},
"snaktype" : "value",
"labels": {
"value" : "File:Photo.jpg"
}
"en": {
</syntaxhighlight>
"language": "en",

"value": "Berlin"
All other snak types are not supported for the datatype commons media.
}

},
==== Other datatypes ====
"descriptions": {
Will be defined as we go. Here are a few drafts.
"en": {

"language": "en",
Geo:
"value": "The capital of Germany"
<syntaxhighlight lang="javascript">
}
{
},
"aliases": {
"snaktype" : "value",
"en": [{
"latitude" : 32.233,
"language": "en",
"longitude" : -2.233,
"precision" : 0.001,
"value": "City of Berlin"
}, {
"sphere" : "q123"
}
"language": "en",
</syntaxhighlight>
"value": "B\u00e4rlin"

}]
Points in time:
},
<syntaxhighlight lang="javascript">
"statements" : {
{
"location" : {
"statement28" : {
"snaktype" : "value",
"value" : "Germany",
"value" : "1900-01-01T00:00:00",
"type" : "item",
"precision" : "century"
}
"references" : {
"reference21" : {
"book" : {
"value" : "CIA World Fact book",
"type" : "item"
},
"page" : {
"value" : 171,
"type" : "number"
}
},
"reference38" : {
"book" : "GeoTextbook Europe",
"type" : "item"
}
}
}
},
"population" : {
"statement33" : {
"value" : {
"value" : 3500000,
"type" : "number",
"accuracy" : {
"value" : 100000
}
},
"as of" : {
"value" : "2011-01-01T00:00:00",
"type" : "time",
"accuracy" : {
"value" : "1",
"unit" : "year"
}
}
},
"statement43" : {
"value" : {
"value" : 5000,
"type" : "number",
"accuracy" : {
"value" : 1000
}
},
"as of" : {
"value" : "1450-01-01T00:00:00",
"type" : "time",
"accuracy" : {
"value" : "100",
"unit" : "year"
}
}
}
}
}
}
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 10:59, 31 July 2020

This document is a draft, and should not be assumed to represent the ultimate structure.

This is a draft for how Phase 2 JSON could look like. You can copy and paste it into a JS engine to play around with it.

Specification[edit]

The following draft describes how to serialize statements. We omit labels, descriptions, aliases and sitelinks as they are already implemented.

A property has a simple key-value pair "type" : type-id, e.g. "type" : "item", to designate its type.

Statements are given as a value to the "statements" key (like "sitelinks", "labels", etc.) on the top level of an entity. The value is an associative array with all statements.

The keys of the statement value are the property ids. The value is an associative array with all statements for a given property.

The keys of that value are the statement ids. The value is an associative array describing a statement. This looks as follows:

 { 
   "value" : serialization_of_value_as_an_object,
   serialization_of_qualifiers,
   "references" : {
     serialization_of_references
   },
   "rank" : rank-id
 }

Qualifiers are serialized as a key-value pair with the key being the property id of the qualifier and the value being an array of serialized values (an array because the same qualifier can be used several times).

The different snaks are represented through the value serialization. This allows for the qualifiers to be key-value pairs.

Value serialization[edit]

The value serialization depends on the snak type and the data type. The snak type is given explicitly. If the snak type is "none" or "some", then no "value" key is present.

Datatype item[edit]

The following serializes a value of type "item" with a PropertyValueSnak:

 { 
   "snaktype" : "value",
   "value" : "q123"
 }

The following serializes a value of type "item" with a PropertyNoValueSnak:

 { 
   "snaktype" : "none"
 }

The following serializes a value of type "item" with a PropertySomeValueSnak:

 { 
   "snaktype" : "some"
 }

PropertyIntervalSnak and PropertySomeIntervalSnak can not be used with datatype "item".

Datatype commons media[edit]

The following serializes a value of type "Commons media" with a PropertyValueSnak.

 { 
   "snaktype" : "value",
   "value" : "File:Photo.jpg"
 }

All other snak types are not supported for the datatype commons media.

Other datatypes[edit]

Will be defined as we go. Here are a few drafts.

Geo:

 { 
   "snaktype" : "value",
   "latitude" : 32.233,
   "longitude" : -2.233,
   "precision" : 0.001,
   "sphere" : "q123"
 }

Points in time:

 { 
   "snaktype" : "value",
   "value" : "1900-01-01T00:00:00",
   "precision" : "century"
 }

See also[edit]