qwikidata.datavalue module

Module for Wikidata Datavalues.

class GlobeCoordinate(datavalue_dict)[source]

Bases: object

Class for globecoordinate datavalues.

In this class, the value attribute is a mapping with the following keys,

  • latitude (float or str): the latitude part of the coordinate in degrees

  • longitude (float or str): the longitude part of the coordinate in degrees

  • precision (float or str): the coordinate’s precision, in (fractions of) degrees

  • globe (str): the URI of a reference globe. This would typically refer to a data item on wikidata.org. This is usually just an indication of the celestial body (e.g. Q2 = earth), but could be more specific, like WGS 84 or ED50.

  • altitude (float or str): Deprecated and no longer used. Will be dropped in the future.

Variables
  • value (dict) – mapping that represents a location on a globe

  • datatype (str) – globecoordinate

class MonolingualText(datavalue_dict)[source]

Bases: object

Class for monolingualtext datavalues.

In this class, the value attribute is a mapping with the following keys,

Variables
  • value (dict) – mapping that represents text in a specific language

  • datatype (str) – monolingualtext

class Quantity(datavalue_dict)[source]

Bases: object

Class for quantity datavalues.

In this class, the value attribute is a mapping with the following keys,

  • amount (str): The nominal value of the quantity, as an arbitrary precision decimal string. The string always starts with a character indicating the sign of the value, either “+” or “-“.

  • upperBound (str): Optionally, the upper bound of the quantity’s uncertainty interval, using the same notation as the amount field. If not given or null, the uncertainty (or precision) of the quantity is not known. If the upperBound field is given, the lowerBound field must also be given.

  • lowerBound (str): Optionally, the lower bound of the quantity’s uncertainty interval, using the same notation as the amount field. If not given or null, the uncertainty (or precision) of the quantity is not known. If the lowerBound field is given, the upperBound field must also be given.

  • unit (str): the URI of a unit (or “1” to indicate a unit-less quantity). This would typically refer to a data item on wikidata.org, e.g. http://www.wikidata.org/entity/Q712226 for “square kilometer”.

Variables
  • value (dict) – mapping that represents a numeric quantity

  • datatype (str) – quantity

class String(datavalue_dict)[source]

Bases: object

Class for string datavalues.

Variables
  • value (str) – a string literal

  • datatype (str) – string

class Time(datavalue_dict)[source]

Bases: object

Class for time datavalues.

In this class, the value attribute is a mapping with the following keys,

  • time (str): the format and interpretation of this string depends on the calendar model. Currently, only Julian and Gregorian dates are supported. The format used for Gregorian and Julian dates use a notation resembling ISO 8601. E.g. “+1994-01-01T00:00:00Z”. The year is represented by at least four digits, zeros are added on the left side as needed. Years BCE are represented as negative numbers, using the historical numbering, in which year 0 is undefined, and the year 1 BCE is represented as -0001, the year 44 BCE is represented as -0044, etc., like XSD 1.0 (ISO 8601:1988) does. Month and day may be 00 if they are unknown or insignificant. The day of the month may have values between 0 and 31 for any month, to accommodate “leap dates” like February 30. Hour, minute, and second are currently unused and should always be 00.

  • timezone (int): Signed integer. Currently unused, and should always be 0.

  • calendarmodel (str): URI of a calendar model, such as gregorian or julian. Typically given as the URI of a data item on the repository

  • precision (int): To what unit is the given date/time significant? Given as an integer indicating one of the following units:

    • 0: 1 Gigayear

    • 1: 100 Megayears

    • 2: 10 Megayears

    • 3: Megayear

    • 4: 100 Kiloyears

    • 5: 10 Kiloyears

    • 6: Kiloyear

    • 7: 100 years

    • 8: 10 years

    • 9: years

    • 10: months

    • 11: days

    • 12: hours (unused)

    • 13: minutes (unused)

    • 14: seconds (unused)

    Note that the precision should be read as an indicator of the significant parts of the date string, it does not directly specify an interval. That is, 1988-07-13T00:00:00 with precision 8 (decade) will be interpreted as 198?-??-?? and rendered as “1980s”. 1981-01-21T00:00:00 with precision 8 would have the exact same interpretation. Thus the two dates are equivalent, since year, month, and days are treated as insignificant.

  • before (int): Beginning of an uncertainty range, given in the unit defined by the precision field. This cannot be used to represent a duration. (Currently unused, may be dropped in the future)

  • after (int): End of an uncertainty range, given in the unit defined by the precision field. This cannot be used to represent a duration. (Currently unused, may be dropped in the future)

Variables
  • value (dict) – mapping that represents a time

  • datatype (str) – time

get_parsed_datetime_dict()[source]

Return a dictionary representation of the datavalue.

Given a Wikidata time string, extract the year, month, and day.

Time strings look like this, for examples: ‘+1838-01-01T00:00:00Z’.

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

TODO: Handle truncated dates (like 20 for 20th century) TODO: Allow for partial match if we only know some information like the year

Returns

a dictionary representing the timestring’s year, month, and date

Return type

dict

class WikibaseEntityId(datavalue_dict)[source]

Bases: object

Class for wikibase-entityid datavalues.

In this class, the value attribute is a mapping with the following keys,

  • entity-type (str): one of [“item”, “property”]

  • id (str): string form of entity id (e.g. “Q42”)

  • numeric-id (int): integer form of entity id (e.g. 42)

Variables
  • value (dict) – mapping that references a Wikidata entity

  • datatype (str) – wikibase-entityid

class WikibaseUnmappedEntityId(datavalue_dict)[source]

Bases: object

Class for wikibase-unmapped-entityid datavalues.

In this class, the value attribute is a string representing an unmapped wikibase entity id.

Variables
  • value (str) – string that references an unmapped entity id

  • datatype (str) – wikibase-unmapped-entityid

get_datavalue_from_snak_dict(snak_dict)[source]

Return a Wikidata Datavalue from a snak dictionary.

Return type

Union[GlobeCoordinate, MonolingualText, Quantity, String, Time, WikibaseEntityId, WikibaseUnmappedEntityId, None]