FastRunContainer#

class wikibaseintegrator.wbi_fastrun.FastRunContainer(base_filter, base_data_type=None, use_qualifiers=True, use_references=False, use_rank=False, cache=True, case_insensitive=False, sparql_endpoint_url=None, wikibase_url=None)[source]#

Bases: object

A FastRunContainer loads the statements of the entities matching the base filter from the SPARQL endpoint and caches them, so that a bot can check whether a write is required without loading every entity through the API.

Parameters:
  • base_filter (list[BaseDataType | list[BaseDataType]]) – The default filter to initialize the dataset. A list made of BaseDataType or list of BaseDataType.

  • base_data_type (type[BaseDataType] | None, default: None) – The default data type to create objects.

  • use_qualifiers (bool, default: True) – Use qualifiers during fastrun. Enabled by default.

  • use_references (bool, default: False) – Use references during fastrun. Disabled by default.

  • use_rank (bool, default: False) – Use rank during fastrun. Disabled by default.

  • cache (bool, default: True) – Put data returned by the SPARQL endpoint in cache. Enabled by default.

  • case_insensitive (bool, default: False) – Compare the string values without taking the case into account. The comparison of qualifiers, references and ranks stays case sensitive. Disabled by default.

  • sparql_endpoint_url (str | None, default: None) – SPARQL endpoint URL.

  • wikibase_url (str | None, default: None) – Wikibase URL used for the concept URI.

check_language_data(qid, lang_data, lang, lang_data_type, action_if_exists=ActionIfExists.APPEND_OR_REPLACE)[source]#

Method to check if certain language data exists as a label, description or aliases

Parameters:
  • qid (str) – entity ID

  • lang_data (list) – list of string values to check

  • lang (str) – language code

  • lang_data_type (str) – What kind of data is it? ‘label’, ‘description’ or ‘aliases’?

  • action_if_exists (ActionIfExists, default: ActionIfExists.APPEND_OR_REPLACE) – If aliases already exist, APPEND_OR_REPLACE or REPLACE_ALL

Return type:

bool

Returns:

boolean True if a write is required

clear()[source]#

Convenience function to empty the caches of this fastrun container.

Return type:

None

get_entities(claims, cache=None, query_limit=None)[source]#

Return a list of entities who correspond to the specified claims.

Parameters:
  • claims (list[Claim] | Claims | Claim) – A list of claims to query the SPARQL endpoint.

  • cache (bool | None, default: None) – Put data returned by the SPARQL endpoint in cache. Enabled by default.

  • query_limit (int | None, default: None) – Limit the amount of results from the SPARQL server

Return type:

list[str]

Returns:

A list of entity ID.

get_language_data(qid, lang, lang_data_type)[source]#

get language data for specified qid

Parameters:
  • qid (str) – entity ID

  • lang (str) – language code

  • lang_data_type (str) – ‘label’, ‘description’ or ‘aliases’

Return type:

list[str]

Returns:

list of strings. If nothing is found: [‘’] for a label or a description, [] for the aliases

init_language_data(lang, lang_data_type)[source]#

Initialize language data store

Parameters:
  • lang (str) – language code

  • lang_data_type (str) – ‘label’, ‘description’ or ‘aliases’

Return type:

None

Returns:

None

load_statements(claims, cache=None, wb_url=None, limit=None)[source]#

Load the statements related to the given claims into the internal cache of the current object.

When the cache is enabled, every statement of the property is loaded once and reused afterwards. When the cache is disabled and the claim carries a value, only the statements holding the same value (and the same qualifiers if use_qualifiers is enabled) are loaded; such a partial load is never reused as a cache.

A complete load only reads the simple values: joining the value node of every statement, for the unit of a quantity or the precision of a time, makes the query of a large dataset exceed the time limit of the SPARQL endpoint. The unit and the precision are loaded later, only for the statements holding the value of a claim (see _filter_value_details()). A partial load, restricted to one value, reads them directly.

Parameters:
  • claims (list[Claim] | Claims | Claim) – A Claim, Claims or list of Claim

  • cache (bool | None, default: None) – Put data returned by the SPARQL endpoint in cache. Enabled by default.

  • wb_url (str | None, default: None) – The first part of the concept URI of entities.

  • limit (int | None, default: None) – The limit to request at one time.

Return type:

None

Returns:

write_required(claims, entity_filter=None, property_filter=None, action_if_exists=ActionIfExists.REPLACE_ALL, use_qualifiers=None, use_references=None, use_rank=None, cache=None, query_limit=None)[source]#

Check if a write to the Wikibase instance is required: a write is not required only when at least one entity already holds, for every claim, a statement with the same value (and the same qualifiers, references and rank, depending on the flags).

Parameters:
  • claims (list[Claim] | Claims | Claim) – The claims proposed to be written.

  • entity_filter (list[str] | str | None, default: None) – Allows you to filter the entities checked. This can be a single entity or a list of entities. Pass the ID of the entity being edited to check whether this entity specifically already holds the data.

  • property_filter (list[str] | str | None, default: None) – Allows you to limit the difference comparison to a list of properties. Claims whose property is not in the filter are ignored.

  • action_if_exists (ActionIfExists, default: ActionIfExists.REPLACE_ALL) – The action that will be used for the write. With FORCE_APPEND, the statements are always appended and a write is always required. The other actions check that the claims already exist.

  • use_qualifiers (bool | None, default: None) – Use qualifiers during fastrun. Enabled by default.

  • use_references (bool | None, default: None) – Use references during fastrun. Disabled by default.

  • use_rank (bool | None, default: None) – Use rank during fastrun. Disabled by default.

  • cache (bool | None, default: None) – Put data returned by the SPARQL endpoint in cache. Enabled by default.

  • query_limit (int | None, default: None) – Limit the amount of results from the SPARQL server

Return type:

bool

Returns:

a boolean True if a write is required. False otherwise.

data: dict[str, dict[str, list[dict[str, str]]]]#