Module Wikidata.Entity
Represents Wikidata Entities.
Why Objects?
Unlike most other Wikidata things in this library, Entities are represented by objects rather than records. This is because many Entities share fields, like how Items (Item.t) and Properties (Property.t) both have ids, labels, entity_types, descriptions, aliases, and claims.
Records are not polymorphic, and so were this library to use record types, code that uses only these shared fields would have to be duplicated to work on both Items and Properties.
By using objects, through the magic of row polymorphism, we can write code that operates on any object with compatible methods. For example, the following function can be run on both Item.ts and Property.ts:
let label_and_description lang entity : string * string =
(
entity#label lang,
entity#description lang
)Were we to use record types for Items and Properties, this function would require pattern matching and then duplicating the code to work on both Items and Properties.
Virtual Classes
These classes are not meant to be instantiated, but represent features that are implemented in the non-virtual classes Item.t and Property.t.
class virtual basic_entity : id:string -> entity_type:string -> object ... endImplements basic Entity functionality.
class virtual label_description_aliases_mixin : labels:(lang * string) list -> descriptions:(lang * string) list -> aliases:(lang * string list) list -> object ... endMixin for labels, descriptions, and aliases
class virtual statements_mixin : statements:(lang * Statement.t list) list -> object ... endMixin for Statements.
Items
module Item : sig ... endRepresents Wikidata Items.
Properties
module Property : sig ... endRepresents Wikidata Properties.
Entities
In this section, entities are represented as a variant type between different types of entities (like Item.ts and Property.ts) rather than as an object that is a subtype of both. The reason is that OCaml's object system lacks narrowing. As such, were we to return a mutual subtype of all entity types, methods that are not shared between those entity types would become inaccessible.
type t=|Item of Item.tRepresents a Wikidata Item.
|Property of Property.tRepresents a Wikidata Property.
A variant type of all supported Entity types.
Conversions
val of_string : string -> tTurns a json string representing some Entity (as described in the Wikibase JSON specification) into a
t.
val of_entities_string : string -> tReturns the first entity in a JSON string representing a group of entities as a
t. This is provided as a convenience function, as this is the format that requests tohttps://wikidata.org/wiki/Special:EntityData/{ID}.json(whereIDis a Wikidata Entity ID) are returned in.