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
editThere are two main classes: TypeFactory
, Type
, and, from the ValueHandler extension, DataValue
.
The TypeFactory
is used to
- get a list of all
Type
s - get an instance of
Type
The Type
is used to
- get labels of itself
- create
DataValue
s - parse a string and get a
DataValue
- get
Formatter
s
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
editNormally, 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 aDataValue
into a serialization - a
Parser
turns a serialization into aDataValue
- a
Validator
checks aDataValue
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.