Package org.wikidata.wdtk.examples.bots
Class FixIntegerQuantityPrecisionsBot
java.lang.Object
org.wikidata.wdtk.examples.bots.FixIntegerQuantityPrecisionsBot
- All Implemented Interfaces:
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)
- Author:
- Markus Kroetzsch
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
finish()
Finishes processing and makes sure that the log file is written.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.protected boolean
hasPlusMinusOneValues
(StatementGroup statementGroup) Checks if the given statement group contains at least one value of precision +/-1.protected boolean
isPlusMinusOneValue
(QuantityValue quantityValue) Checks if the given value is a number with precision +/-1.protected void
logEntityModification
(EntityIdValue entityId, List<Statement> updateStatements, String propertyId) Logs information about entities changed so far.static void
Main method to run the bot.static void
Prints some basic documentation about this program.void
processItemDocument
(ItemDocument itemDocument) Processes the given ItemDocument.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.wikidata.wdtk.datamodel.interfaces.EntityDocumentProcessor
processEntityRedirectDocument, processLexemeDocument, processMediaInfoDocument, processPropertyDocument
-
Constructor Details
-
FixIntegerQuantityPrecisionsBot
Constructor.- Throws:
LoginFailedException
IOException
-
-
Method Details
-
main
Main method to run the bot.- Parameters:
args
-- Throws:
LoginFailedException
IOException
-
printDocumentation
public static void printDocumentation()Prints some basic documentation about this program. -
processItemDocument
Description copied from interface:EntityDocumentProcessor
Processes the given ItemDocument.- Specified by:
processItemDocument
in interfaceEntityDocumentProcessor
- Parameters:
itemDocument
- the ItemDocument
-
finish
public void finish()Finishes processing and makes sure that the log file is written. -
fixIntegerPrecisions
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 inspectpropertyId
- 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 itemupdateStatements
-propertyId
-
-
isPlusMinusOneValue
Checks if the given value is a number with precision +/-1.- Parameters:
quantityValue
-- Returns:
-
hasPlusMinusOneValues
Checks if the given statement group contains at least one value of precision +/-1.- Parameters:
statementGroup
-- Returns:
-