Wikidata/Development/Phase 2 JSON: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
→‎Specification: simplifying strongly
Line 62: Line 62:


==== Other datatypes ====
==== Other datatypes ====
Will be defined as we go.
Will be defined as we go. Most of them have to be objects. Here are a few drafts.

Geo:
<syntaxhighlight lang="javascript">
{
"latitude" : 32.233,
"longitude" : -2.233,
"altitude" : 0,
"precision" : 0.001,
"sphere" : "q123"
}
</syntaxhighlight>

Points in time:
<syntaxhighlight lang="javascript">
{
"value" : "1900-01-01T00:00:00",
"precision" : "century"
}
</syntaxhighlight>


== Example ==
== Example ==

Revision as of 14:49, 4 October 2012

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

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:

 { 
   "property" : property_id,
   "value" : serialization_of_value,
   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 simple key-value pairs.

Value serialization

The value serialization depends on the snak type and the data type.

Datatype item

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

  "q123"

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

  "none"

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

  "unknown"

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

Datatype commons media

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

  "File:Photo.jpg"

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

Other datatypes

Will be defined as we go. Most of them have to be objects. Here are a few drafts.

Geo:

 { 
   "latitude" : 32.233,
   "longitude" : -2.233,
   "altitude" : 0,
   "precision" : 0.001,
   "sphere" : "q123"
 }

Points in time:

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

Example

  berlin = {
    "id": "q109",
    "sitelinks": {
      "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"
          }]
        }
      }
    }
  }

Slightly more readable example

The following replaces the IDs with the labels. Not up to date!!

  berlin = {
    "id": 109,
    "sitelinks": {
      "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" : {
      "location" : { 
        "statement28" : { 
          "value" : "Germany",
          "type" : "item", 
          "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"
            }
          }			
        }
      }
    }
  }

See also