Class TrieWordList

    • Constructor Detail

      • TrieWordList

        public TrieWordList​(@NonNull
                            @NonNull Iterable<String> words)
        Instantiates a new TrieWordList
        Parameters:
        words - the words
      • TrieWordList

        public TrieWordList​(@NonNull
                            @NonNull WordList... wordLists)
        Instantiates a new TrieWordList
        Parameters:
        wordLists - the wordLists
    • Method Detail

      • read

        public static TrieWordList read​(@NonNull
                                        @NonNull Resource resource)
                                 throws IOException

        Reads the word list from the given resource where each term is on its own line and "#" represents comments.

        Note that convention states that if the first line of a word list is a comment stating "case-insensitive" then loading of that word list will result in all words being lower-cased.

        Parameters:
        resource - the resource
        Returns:
        the trie word list
        Throws:
        IOException - the io exception
      • contains

        public boolean contains​(String string)
        Description copied from interface: WordList
        Is the String contained in the WordList
        Specified by:
        contains in interface WordList
        Parameters:
        string - the string to lookup
        Returns:
        True if the string is in the WordList, False otherwise
      • isPrefixMatch

        public boolean isPrefixMatch​(HString hString)
        Description copied from interface: PrefixSearchable
        Check if a prefix matches the given HString
        Specified by:
        isPrefixMatch in interface PrefixSearchable
        Parameters:
        hString - the HString to check for a prefix match
        Returns:
        True if a prefix matches, False otherwise
      • isPrefixMatch

        public boolean isPrefixMatch​(String hString)
        Description copied from interface: PrefixSearchable
        Check if a prefix matches the given String
        Specified by:
        isPrefixMatch in interface PrefixSearchable
        Parameters:
        hString - the String to check for a prefix match
        Returns:
        True if a prefix matches, False otherwise
      • prefixes

        public Set<String> prefixes​(String string)
        Description copied from interface: PrefixSearchable
        Gets the prefixes that match the given string
        Specified by:
        prefixes in interface PrefixSearchable
        Parameters:
        string - the string
        Returns:
        the set of matching prefixes
      • size

        public int size()
        Description copied from interface: WordList
        Number of words in the list
        Specified by:
        size in interface WordList
        Returns:
        the number of words in the list
      • suggest

        public Map<String,​Integer> suggest​(String string)
        Suggests potential matches based on the given elements.
        Parameters:
        string - the string to generate suggestions for
        Returns:
        the map of suggestions with their costs
      • suggest

        public Map<String,​Integer> suggest​(String string,
                                                 int maxCost)
        Suggests potential matches based on the given elements.
        Parameters:
        string - the string to generate suggestions for
        maxCost - the maximum cost of the suggestions
        Returns:
        the map of suggestions with their costs
      • suggest

        public Map<String,​Integer> suggest​(String string,
                                                 int maxCost,
                                                 int substitutionCost)
        Suggests potential matches based on the given elements.
        Parameters:
        string - the string to generate suggestions for
        maxCost - the maximum cost of the suggestions
        substitutionCost - the cost for string substitutions
        Returns:
        the map of suggestions with their costs