Package org.wikidata.wdtk.examples
Class ExampleHelpers
java.lang.Object
org.wikidata.wdtk.examples.ExampleHelpers
Class for sharing code that is used in many examples. It contains several
static final members that can be modified to change the behaviour of example
programs, such as whether to use
OFFLINE_MODE
or not.- Author:
- Markus Kroetzsch
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enum to say which dumps should be downloaded and processed. -
Field Summary
Modifier and TypeFieldDescriptionstatic final ExampleHelpers.DumpProcessingMode
Defines which dumps will be downloaded and processed in all examples.static final String
The directory where to place files created by the example applications.static final boolean
If set to true, all example programs will run in offline mode.static final int
Timeout to abort processing after a short while or 0 to disable timeout. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Defines how messages should be logged.static String
Returns the name of the dump file that was last processed.static FileOutputStream
openExampleFileOuputStream
(String filename) Opens a new FileOutputStream for a file of the given name in the example output directory (EXAMPLE_OUTPUT_DIRECTORY
).static void
processEntitiesFromWikidataDump
(EntityDocumentProcessor entityDocumentProcessor) Processes all entities in a Wikidata dump using the given entity processor.
-
Field Details
-
OFFLINE_MODE
public static final boolean OFFLINE_MODEIf set to true, all example programs will run in offline mode. Only data dumps that have been downloaded in previous runs will be used.- See Also:
-
DUMP_FILE_MODE
Defines which dumps will be downloaded and processed in all examples. -
EXAMPLE_OUTPUT_DIRECTORY
The directory where to place files created by the example applications.- See Also:
-
TIMEOUT_SEC
public static final int TIMEOUT_SECTimeout to abort processing after a short while or 0 to disable timeout. If set, then the processing will cleanly exit after about this many seconds, as if the dump file would have ended there. This is useful for testing (and in particular better than just aborting the program) since it allows for final processing and proper closing to happen without having to wait for a whole dump file to process.- See Also:
-
-
Constructor Details
-
ExampleHelpers
public ExampleHelpers()
-
-
Method Details
-
configureLogging
public static void configureLogging()Defines how messages should be logged. This method can be modified to restrict the logging messages that are shown on the console or to change their formatting. See the documentation of Log4J for details on how to do this. -
processEntitiesFromWikidataDump
Processes all entities in a Wikidata dump using the given entity processor. By default, the most recent JSON dump will be used. In offline mode, only the most recent previously downloaded file is considered.- Parameters:
entityDocumentProcessor
- the object to use for processing entities in this dump
-
openExampleFileOuputStream
Opens a new FileOutputStream for a file of the given name in the example output directory (EXAMPLE_OUTPUT_DIRECTORY
). Any file of this name that exists already will be replaced. The caller is responsible for eventually closing the stream.- Parameters:
filename
- the name of the file to write to- Returns:
- FileOutputStream for the file
- Throws:
IOException
- if the file or example output directory could not be created
-
getLastDumpFileName
Returns the name of the dump file that was last processed. This can be used to name files generated from this dump. The result might be the empty string if no file has been processed yet.
-