Class FixIntegerQuantityPrecisionsBot

java.lang.Object
org.wikidata.wdtk.examples.bots.FixIntegerQuantityPrecisionsBot
All Implemented Interfaces:
EntityDocumentProcessor

public class FixIntegerQuantityPrecisionsBot extends Object implements EntityDocumentProcessor
This bot adds changes quantity values of properties that are required to use integers (such as population numbers) to be exact if they are now set to +/-1. The latter is the default when editing through the API but not useful there.

The activity of the bot is logged in the file bot-log-fixintprec-TIMESTAMP.txt. Note that this log contains all edits that would have been made, even if editing was disabled. Errors are logged to the console only.

By default, this program has the actual editing disabled (see source code), so as to avoid accidental modifications. The output will still mention changes that would be done. If you want to do real edits, please respect the bot etiquette and community guidelines.

The function of the bot is very basic, but it illustrates some important techniques:

  • Scan a recent dump for items worth changing
  • Check the online version of each item before really changing it, and use the online revision id to prevent edit conflicts
  • Update statements while preserving most of their content
  • Use basic bot configuration features (login, disable editing for test, limited numbers of test edits)
The bot is tried and tested, and has been used on Wikidata to perform its task on several 1,000 items (see User:Makrobot).
Author:
Markus Kroetzsch
  • Constructor Details

  • Method Details

    • main

      public static void main(String[] args) throws LoginFailedException, IOException
      Main method to run the bot.
      Parameters:
      args -
      Throws:
      LoginFailedException
      IOException
    • printDocumentation

      public static void printDocumentation()
      Prints some basic documentation about this program.
    • processItemDocument

      public void processItemDocument(ItemDocument itemDocument)
      Description copied from interface: EntityDocumentProcessor
      Processes the given ItemDocument.
      Specified by:
      processItemDocument in interface EntityDocumentProcessor
      Parameters:
      itemDocument - the ItemDocument
    • finish

      public void finish()
      Finishes processing and makes sure that the log file is written.
    • fixIntegerPrecisions

      protected void fixIntegerPrecisions(ItemIdValue itemIdValue, String propertyId)
      Fetches the current online data for the given item, and fixes the precision of integer quantities if necessary.
      Parameters:
      itemIdValue - the id of the document to inspect
      propertyId - id of the property to consider
    • logEntityModification

      protected void logEntityModification(EntityIdValue entityId, List<Statement> updateStatements, String propertyId)
      Logs information about entities changed so far.
      Parameters:
      entityId - the id of the modified item
      updateStatements -
      propertyId -
    • isPlusMinusOneValue

      protected boolean isPlusMinusOneValue(QuantityValue quantityValue)
      Checks if the given value is a number with precision +/-1.
      Parameters:
      quantityValue -
      Returns:
    • hasPlusMinusOneValues

      protected boolean hasPlusMinusOneValues(StatementGroup statementGroup)
      Checks if the given statement group contains at least one value of precision +/-1.
      Parameters:
      statementGroup -
      Returns: