Class SimpleDictionary

java.lang.Object
smile.nlp.dictionary.SimpleDictionary
All Implemented Interfaces:
Iterable<String>, Dictionary

public class SimpleDictionary extends Object implements Dictionary
A simple implementation of dictionary interface.
  • Constructor Details

    • SimpleDictionary

      public SimpleDictionary(String resource)
      Constructor that loads a dictionary from a file path or classpath resource. If the given path points to an existing file, it is loaded directly. Otherwise, it is treated as a classpath resource path.
      Parameters:
      resource - the file path or classpath resource path of the dictionary. The file should be plain text with one word per line.
    • SimpleDictionary

      public SimpleDictionary(Path path)
      Constructor that loads a dictionary from a Path.
      Parameters:
      path - the path to the dictionary file. The file should be plain text with one word per line.
  • Method Details

    • contains

      public boolean contains(String word)
      Description copied from interface: Dictionary
      Returns true if this dictionary contains the specified word.
      Specified by:
      contains in interface Dictionary
      Parameters:
      word - the query word.
      Returns:
      true if this dictionary contains the specified word.
    • size

      public int size()
      Description copied from interface: Dictionary
      Returns the number of words in this dictionary.
      Specified by:
      size in interface Dictionary
      Returns:
      the number of words in this dictionary.
    • iterator

      public Iterator<String> iterator()
      Description copied from interface: Dictionary
      Returns an iterator over the words in this dictionary.
      Specified by:
      iterator in interface Dictionary
      Specified by:
      iterator in interface Iterable<String>
      Returns:
      the iterator.