Class SetLabelsForNumbersBot

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

public class SetLabelsForNumbersBot extends Object implements EntityDocumentProcessor
This bot adds a default label to Wikidata items that are about numbers, by simply creating a string for any integer number. Decimal numbers that are not integers are not touched since they usually should have more meaningful labels than the numerical representation. Moreover, the bot checks the class (P31 value) of each item to make sure that only items about numbers are re-labelled.

The activity of the bot is logged in the file bot-log-setnumlabels-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
  • Create data objects for writing
  • 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 over 10,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.
      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.
    • addLabelForNumbers

      protected void addLabelForNumbers(ItemIdValue itemIdValue)
      Fetches the current online data for the given item, and adds numerical labels if necessary.
      Parameters:
      itemIdValue - the id of the document to inspect
    • lacksSomeLanguage

      protected boolean lacksSomeLanguage(ItemDocument itemDocument)
      Returns true if the given item document lacks a label for at least one of the languages covered.
      Parameters:
      itemDocument -
      Returns:
      true if some label is missing
    • logEntityModification

      protected void logEntityModification(EntityIdValue entityId, String numberLabel, ArrayList<String> languages)
      Logs information about entities changed so far.
      Parameters:
      entityId - the id of the modified item
      numberLabel - the label written
      languages - the list of languages for which the label was set