qwikidata.entity module

Module for Wikidata Entities.

class ClaimsMixin[source]

Bases: object

Mixin for entities with top level claims (aka statements).

See: https://www.wikidata.org/wiki/Help:Statements

get_claim_group(property_id)[source]

Get the claim group corresponding to a given property id.

Parameters

property_id (NewType()(PropertyId, str)) – the string representing the property ID of the claim group to return

Return type

WikidataClaimGroup

get_claim_groups()[source]

Get all claim groups about this entity.

Return type

Dict[NewType()(PropertyId, str), WikidataClaimGroup]

get_truthy_claim_group(property_id)[source]

Get truthy claims from the claim group corresponding to a given property id.

Truthy is defined in the Wikidata RDF dump format docs,

“Truthy statements represent statements that have the best non-deprecated rank for a given property. Namely, if there is a preferred statement for a property P, then only preferred statements for P will be considered truthy. Otherwise, all normal-rank statements for P are considered truthy.”

RDF dump format docs on truthy statements

Parameters

property_id (NewType()(PropertyId, str)) – the string representing the property ID of the claim group to return

Return type

WikidataClaimGroup

get_truthy_claim_groups()[source]

Get all truthy claim groups about this entity.

Truthy is defined in the Wikidata RDF dump format docs,

“Truthy statements represent statements that have the best non-deprecated rank for a given property. Namely, if there is a preferred statement for a property P, then only preferred statements for P will be considered truthy. Otherwise, all normal-rank statements for P are considered truthy.”

RDF dump format docs on truthy statements

Return type

Dict[NewType()(PropertyId, str), WikidataClaimGroup]

class EntityMixin[source]

Bases: object

Mixin for all entities.

class LabelDescriptionAliasMixin[source]

Bases: object

Mixin for entities with labels, descriptions, and aliases.

get_aliases(lang='en')[source]

Get alternative names for this entity in a specific language.

See: https://www.wikidata.org/wiki/Help:Aliases

Parameters

lang (NewType()(LanguageCode, str)) – Find aliases in this language.

Return type

List[str]

get_description(lang='en')[source]

Get a brief description of this entity in a specific language.

See: https://www.wikidata.org/wiki/Help:Description

Parameters

lang (NewType()(LanguageCode, str)) – Find the description in this language.

Return type

str

get_label(lang='en')[source]

Get label (primary name for this entity) in a specific language.

See: https://www.wikidata.org/wiki/Help:Label

Parameters

lang (NewType()(LanguageCode, str)) – Find the label in this language.

Return type

str

class WikidataForm(form_dict)[source]

Bases: ClaimsMixin

A form associated with a Wikidata Lexeme.

See: https://www.mediawiki.org/wiki/Extension:WikibaseLexeme/Data_Model#Form

This class can be initialized from a lexeme dictionary as,

>>> form_dict = l3354_dict['forms'][0]
>>> wikidata_form = WikidataForm(form_dict)
Parameters

form_dict (FormDict) – A dictionary representing a Wikidata Lexeme form.

Variables
  • form_id (str) – Unique id for this form (e.g. ‘L3354-F1’)

  • grammatical_features (list) – List of item ids representing grammatical categories (e.g. present tense, first person, …)

get_representation(lang='en')[source]

Get representation of this form in a given language.

See: https://www.mediawiki.org/wiki/Extension:WikibaseLexeme/Data_Model#Representation

Parameters

lang (NewType()(LanguageCode, str)) – Find the representation in this language.

Return type

str

class WikidataItem(item_dict)[source]

Bases: LabelDescriptionAliasMixin, ClaimsMixin, EntityMixin

Class for Wikidata Items.

Parameters

item_dict (ItemDict) – A dictionary representation of a Wikidata Item. See the wikibase JSON data model docs for a description of the dictionary format.

See also

Wikidata docs on items,

Ways to generate item dictionaries within qwikidata.

get_enwiki_title()[source]

Get english language wikipedia page title.

Return type

str

Get Wikimedia sitelinks for this item.

Parameters

prefix (str) – filters to sitelinks that begin with prefix. can filter by language (e.g. “en”) or by language and site (e.g. “enwiki”).

Returns

A dictionary with site names as keys and sitelink dictionaries as values.

Return type

dict

class WikidataLexeme(lexeme_dict)[source]

Bases: ClaimsMixin, EntityMixin

Class for Wikidata Lexeme.

Parameters

lexeme_dict (LexemeDict) – A dictionary representation of a Wikidata Lexeme. See the wikibase Lexeme JSON data model docs for a description of the dictionary format.

get_forms()[source]

Get the set of forms assocaited with this Lexeme.

Return type

List[WikidataForm]

get_lemma(lang='en')[source]

Get lemma (primary name for this lexeme) in a specific language.

See: https://www.mediawiki.org/wiki/Extension:WikibaseLexeme/Data_Model#Lemma

Parameters

lang (NewType()(LanguageCode, str)) – Find the lemma in this language.

Return type

str

get_senses()[source]

Get the set of senses assocaited with this Lexeme.

Return type

List[WikidataSense]

class WikidataProperty(property_dict)[source]

Bases: LabelDescriptionAliasMixin, ClaimsMixin, EntityMixin

Class for Wikidata Properties.

Parameters

property_dict (PropertyDict) – A dictionary representation of a Wikidata Property. See the wikibase JSON data model docs for a description of the dictionary format.

See also

Wikidata docs on properties,

Ways to generate property dictionaries within kwikimedia.

class WikidataSense(sense_dict)[source]

Bases: ClaimsMixin

A sense associated with a Wikidata Lexeme.

See: https://www.mediawiki.org/wiki/Extension:WikibaseLexeme/Data_Model#Sense

This class can be initialized from a lexeme dictionary as,

>>> sense_dict = l3354_dict['senses'][0]
>>> wikidata_sense = WikidataSense(sense_dict)
Parameters

sense_dict (SenseDict) – A dictionary representing a Wikidata Lexeme sense.

Variables

sense_id (str) – Unique id for this sense (e.g. ‘L3354-S1’)

get_gloss(lang='en')[source]

Get gloss of this sense in a given language.

See: https://www.mediawiki.org/wiki/Extension:WikibaseLexeme/Data_Model#Gloss

Parameters

lang (NewType()(LanguageCode, str)) – Find the gloss in this language.

Return type

str