Package org.wikidata.wdtk.examples.bots
Class SetLabelsForNumbersBot
java.lang.Object
org.wikidata.wdtk.examples.bots.SetLabelsForNumbersBot
- All Implemented Interfaces:
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)
- Author:
- Markus Kroetzsch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddLabelForNumbers(ItemIdValue itemIdValue) Fetches the current online data for the given item, and adds numerical labels if necessary.voidfinish()Finishes processing and makes sure that the log file is written.protected booleanlacksSomeLanguage(ItemDocument itemDocument) Returns true if the given item document lacks a label for at least one of the languages covered.protected voidlogEntityModification(EntityIdValue entityId, String numberLabel, ArrayList<String> languages) Logs information about entities changed so far.static voidMain method to run the bot.static voidPrints some basic documentation about this program.voidprocessItemDocument(ItemDocument itemDocument) Processes the given ItemDocument.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.wikidata.wdtk.datamodel.interfaces.EntityDocumentProcessor
processEntityRedirectDocument, processLexemeDocument, processMediaInfoDocument, processPropertyDocument
-
Constructor Details
-
SetLabelsForNumbersBot
Constructor.- Throws:
LoginFailedExceptionIOException
-
-
Method Details
-
main
Main method to run the bot.- Throws:
LoginFailedExceptionIOException
-
printDocumentation
public static void printDocumentation()Prints some basic documentation about this program. -
processItemDocument
Description copied from interface:EntityDocumentProcessorProcesses the given ItemDocument.- Specified by:
processItemDocumentin interfaceEntityDocumentProcessor- Parameters:
itemDocument- the ItemDocument
-
finish
public void finish()Finishes processing and makes sure that the log file is written. -
addLabelForNumbers
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
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 itemnumberLabel- the label writtenlanguages- the list of languages for which the label was set
-