Class WiktionaryIndex

java.lang.Object
org.getalp.wiktionary.WiktionaryIndex
All Implemented Interfaces:
WiktionaryPageSource

public class WiktionaryIndex extends Object implements WiktionaryPageSource
WiktionaryIndex is a Persistent HashMap designed to hold an index on a Wiktionary dump file.
Author:
serasset
  • Constructor Details

    • WiktionaryIndex

      public WiktionaryIndex(Path dump) throws WiktionaryIndexerException
      Creates a WiktionaryIndex for the wiktionary dump whose path is passed as a parameter. The live MediaWiki API fallback is disabled.
      Parameters:
      dump - the path to file containing the wiktionary dump.
      Throws:
      WiktionaryIndexerException - thrown if any error occur during index initialization
    • WiktionaryIndex

      public WiktionaryIndex(Path dump, String lang, boolean fillMissingPages) throws WiktionaryIndexerException
      Creates a WiktionaryIndex for the wiktionary dump whose path is passed as a parameter.

      MediaWiki's XML export is known to occasionally omit pages that do exist on the live wiki. If fillMissingPages is set, a title missing from the dump index is looked up on the live MediaWiki API instead of being reported as non existent; the outcome (found or confirmed missing) is cached in a file next to the dump so a title is never queried more than once, across runs.

      Parameters:
      dump - the path to file containing the wiktionary dump.
      lang - the language edition of the dump (used to reach the corresponding wiktionary API when fillMissingPages is set); may be null if fillMissingPages is false.
      fillMissingPages - whether to fall back to the live MediaWiki API for titles missing from the dump.
      Throws:
      WiktionaryIndexerException - thrown if any error occur during index initialization
  • Method Details

    • indexFile

      public static Path indexFile(Path dump)
      returns Path of the index file corresponding to passed dump.
      Parameters:
      dump - Path refering to the dump file.
      Returns:
      the Path refering to the index file.
    • apiCacheFile

      public static Path apiCacheFile(Path dump)
      returns Path of the persisted live-API fallback cache file corresponding to passed dump.
      Parameters:
      dump - Path refering to the dump file.
      Returns:
      the Path refering to the cache file.
    • close

      public void close()
      Free resource taken by the index.
    • get

      public String get(String key)
    • getTextOfPageWithRedirects

      public String getTextOfPageWithRedirects(String key)
      Specified by:
      getTextOfPageWithRedirects in interface WiktionaryPageSource
    • getTextOfPage

      public String getTextOfPage(String key)
      Specified by:
      getTextOfPage in interface WiktionaryPageSource
    • getFullXmlForPage

      public String getFullXmlForPage(String key)
      Specified by:
      getFullXmlForPage in interface WiktionaryPageSource