Class StopwordLists

java.lang.Object
opennlp.tools.stopword.StopwordLists

public final class StopwordLists extends Object
Static factory for StopwordFilter instances backed by bundled language-specific stopword resources or caller-supplied input streams.

Bundled lists ship for the eleven languages enumerated in OPENNLP-660: Bulgarian (bg), Danish (da), German (de), English (en), Spanish (es), Finnish (fi), French (fr), Italian (it), Dutch (nl), Portuguese (pt), Russian (ru). Each list is keyed by its ISO 639-1 two-letter code.

  • Field Details

    • RESOURCE_PATH_PREFIX

      private static final String RESOURCE_PATH_PREFIX
      See Also:
    • SUPPORTED_LANGUAGES

      private static final Set<String> SUPPORTED_LANGUAGES
    • BUNDLED_CACHE

      private static final Map<String,StopwordFilter> BUNDLED_CACHE
      Caches the immutable, thread-safe filters loaded from the bundled resources, keyed by normalized ISO 639-1 code, so that repeated forLanguage(String) calls do not re-read and re-parse the same classpath resource.
  • Constructor Details

    • StopwordLists

      private StopwordLists()
  • Method Details

    • forLanguage

      public static StopwordFilter forLanguage(String iso639Code)
      Returns a case-insensitive StopwordFilter for the given ISO 639 language code. Three-letter codes are normalized to their two-letter equivalent when a bundled list exists for the latter.
      Parameters:
      iso639Code - The ISO 639-1 or ISO 639-2/3 language code. Must not be null.
      Returns:
      A StopwordFilter backed by the bundled resource. The returned instance is immutable, thread-safe and cached, so repeated calls for the same language return the same shared filter.
      Throws:
      IllegalArgumentException - if iso639Code is null, is not a valid ISO 639 code, or has no bundled list for this language.
      UncheckedIOException - if reading the bundled resource fails.
    • loadBundled

      private static StopwordFilter loadBundled(String normalized)
    • supportedLanguages

      public static Set<String> supportedLanguages()
      Returns:
      An unmodifiable view of the bundled ISO 639-1 codes for which stopword lists are shipped.
    • load

      public static StopwordFilter load(InputStream in, Charset cs, boolean caseSensitive) throws IOException
      Loads a stopword filter from a caller-supplied input stream.
      Parameters:
      in - The input stream. Must not be null.
      cs - The Charset to decode with. Must not be null.
      caseSensitive - Whether the resulting filter matches case-sensitively.
      Returns:
      A StopwordFilter populated from in.
      Throws:
      IllegalArgumentException - if in or cs is null.
      IOException - Thrown if an IO error occurs while reading.