Wikidata/Development/Data values and types

This page offers a draft of how data values and data types in Wikibase could interplay, and how this plays together with SMW's data values.

Interfaces

edit

There are two main classes: TypeFactory, Type, and, from the ValueHandler extension, DataValue.

The TypeFactory is used to

  • get a list of all Types
  • get an instance of Type

The Type is used to

  • get labels of itself
  • create DataValues
  • parse a string and get a DataValue
  • get Formatters

DataValue comes from the ValueHandler extension and is used to

  • store a specific value (e.g. 3km+-50 meter)

A DataValue is always stored within a Snak, that keeps track of the Type of the DataValue and can thus also provide formatting and parsing for the DataValue.

Additionally, a Property is an Entity that allows you to get its Type.

Implementation

edit

Normally, developers using values and types do not need to understand the underlying implementation, but merely the above interfaces.

The ValueHandler extension provides four components: DataValue, Formatter, Parser, and Validator. These are shared with the Validator extension, and also between Semantic MediaWiki and Wikibase.

  • a DataValue stores the actual value
  • a Formatter turns a DataValue into a serialization
  • a Parser turns a serialization into a DataValue
  • a Validator checks a DataValue for further conditions

Each of these four, and often are, subclassed, and many of them can be combined together. So, for example, there are subclasses of DataValue for geodata, numbers, etc.

In Wikibase, a Type is basically defined by composing it from the four different components provided in the ValueHandler extension. This composition is configured for TypeFactory and made programmatically accesible through it. TypeFactory uses this configuration and assembles the Type instance.