Class ExampleHelpers

java.lang.Object
org.wikidata.wdtk.examples.ExampleHelpers

public class ExampleHelpers extends Object
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
  • Field Details

    • OFFLINE_MODE

      public static final boolean OFFLINE_MODE
      If 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

      public static final ExampleHelpers.DumpProcessingMode DUMP_FILE_MODE
      Defines which dumps will be downloaded and processed in all examples.
    • EXAMPLE_OUTPUT_DIRECTORY

      public static final String EXAMPLE_OUTPUT_DIRECTORY
      The directory where to place files created by the example applications.
      See Also:
    • TIMEOUT_SEC

      public static final int TIMEOUT_SEC
      Timeout 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

      public static void processEntitiesFromWikidataDump(EntityDocumentProcessor entityDocumentProcessor)
      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

      public static FileOutputStream openExampleFileOuputStream(String filename) throws IOException
      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

      public static String 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.