PropertyAdderBot#

class wikidata_bot_framework.PropertyAdderBot[source]#

A bot that adds properties to pages.

Supports merging existing properties with the internal representation.

act_on_item(item: ItemPage | PropertyPage | LexemePage) bool[source]#

Act on an item.

Parameters:

item – The item to act on.

Returns:

If any edits were made to the item.

can_add_main_property(extra_property: ExtraProperty) bool[source]#

Return if the property can be added or edited

feed_items(items: Iterable[ItemPage | PropertyPage | LexemePage], skip_errored_items: bool = False) None[source]#

Feed items to the bot.

Parameters:
  • items – The items to feed.

  • skip_errored_items – If the bot should skip items that errored.

get_edit_group_id() str | None[source]#

Get the edit group ID for the bot.

This is used to identify the bot in the edit summary.

Returns:

The edit group ID for the bot. Return None to omit it.

abstract get_edit_summary(page: ItemPage | PropertyPage | LexemePage) str[source]#

Get the edit summary for the bot.

Parameters:

page – The item page that was edited.

Returns:

The edit summary to use.

get_full_summary(message: str) str[source]#

Get a fully formatted summary that can be used to update the API and track it to the EditGroup.

Parameters:

message – The message to format with. To use the default summary, pass in the result of get_edit_summary().

Returns:

The fully formatted summary.

post_edit_process_hook(output: Mapping[str, List[ExtraProperty]], item: ItemPage | PropertyPage | LexemePage) None[source]#

Do additional processing after the item is edited.

This hook only fires if an API request was made.

Parameters:
  • output – The output that was processed.

  • item – The item that was edited.

post_output_process_hook(output: Mapping[str, List[ExtraProperty]], item: ItemPage | PropertyPage | LexemePage) bool[source]#

Do additional processing after all output has been processed.

Parameters:
  • output – The output that was processed.

  • item – The item that was edited.

Returns:

Return whether or not the item was changed. This will be used to determine if an API request should be made.

pre_edit_process_hook(output: Mapping[str, List[ExtraProperty]], item: ItemPage | PropertyPage | LexemePage) None[source]#

Do additional processing before the item is edited.

This hook only fires if an API request will be made.

Parameters:
  • output – The output that was processed.

  • item – The item that will be edited.

process(output: Mapping[str, List[ExtraProperty]], item: ItemPage | PropertyPage | LexemePage) bool[source]#

Processes the output from run_item.

Parameters:
  • output – The output to process

  • item – The item to process

Returns:

If any edits were made to the item.

processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.missing_property, ProcessReason.missing_value], *, claim: ExtraProperty) bool[source]#
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.different_rank], *, claim: ExtraProperty, context: DifferentRankContext) bool
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.replace_value], *, claim: ExtraProperty, context: ReplaceValueContext) bool
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.delete_values], *, claim: ExtraProperty, context: DeleteValuesContext) bool
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.missing_qualifier_property, ProcessReason.missing_qualifier_value], *, claim: ExtraProperty, qualifier: ExtraQualifier)
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.replace_qualifier_value], *, claim: ExtraProperty, qualifier: ExtraQualifier, context: ReplaceQualifierValueContext) bool
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.delete_qualifier_values], *, claim: ExtraProperty, qualifier: ExtraQualifier, context: DeleteQualifierValuesContext) bool
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.new_claim_from_qualifier], *, claim: ExtraProperty, qualifier: ExtraQualifier, context: NewClaimFromQualifierContext) bool
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.missing_reference], *, claim: ExtraProperty, reference: ExtraReference) bool
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.merged_reference], *, claim: ExtraProperty, reference: ExtraReference, context: MergedReferenceContext) bool
processed_hook(item: ItemPage | PropertyPage | LexemePage, reason: Literal[ProcessReason.post_output]) bool

Do processing whenever the item is modified. This method is called directly after the item is modified.

New in version 5.8.0.

Parameters:
  • item – The item that was modified.

  • reason – The reason the item was modified.

  • claim – The main claim that was added or is having qualifiers/references added, defaults to None

  • qualifier – The qualifier that was modified, defaults to None

  • reference – The reference that was modified, defaults to None

  • context – Additional context with the operation, defaults to None

Returns:

If the item was modified. This will cause a re-cycle of the process loop so only use this if something on the same tier or higher was modified.

Thing being added

Thing being modified

Main statement

Qualifier

Reference

Main statement

Yes

Yes

Yes

Qualifier

No

Yes

Yes

Reference

No

No

Yes

abstract run_item(item: ItemPage | PropertyPage | LexemePage) Mapping[str, List[ExtraProperty]][source]#

The main work that should be done externally.

This method will take an item and return a dictionary of list of ExtraProperties. The keys are the property IDs.

Parameters:

item – The item to work on.

Returns:

A dictionary of list of ExtraProperties. Recommended to use OutputHelper.

same_main_property(existing_claim: Claim, new_claim: Claim, page: ItemPage | PropertyPage | LexemePage) bool[source]#

Return if the main property is the same.

Parameters:
  • existing_claim – The existing claim to compare to.

  • new_claim – The new claim to compare to.

  • page – The item page that is being edited.

Returns:

If the main property is the same.

same_qualifier(existing_qualifier: Claim, new_qualifier: Claim, main_claim: Claim, page: ItemPage | PropertyPage | LexemePage) bool[source]#

Return if the qualifier is the same.

Parameters:
  • existing_qualifier – The existing qualifier to compare to.

  • new_qualifier – The new qualifier to compare to.

  • main_claim – The main claim that the qualifier is on.

  • page – The item page that is being edited.

Returns:

If the qualifier is the same.

whitelisted_claim(prop: ExtraProperty) bool[source]#

Return if the claim is whitelisted.

Parameters:

prop – The property to check.

Returns:

If the claim is whitelisted.

whitelisted_qualifier(prop: ExtraProperty, qualifier: ExtraQualifier) bool[source]#

Return if the qualifier is whitelisted.

Parameters:
  • prop – The property to check.

  • qualifier – The qualifier to check.

Returns:

If the qualifier is whitelisted.

whitelisted_reference(prop: ExtraProperty, reference: ExtraReference) bool[source]#

Return if the reference is whitelisted.

Parameters:
  • prop – The property to check.

  • reference – The reference to check.

Returns:

If the reference is whitelisted.