Werds (werds v1.0.3)

A module to generate valid word variants from a base word.

Summary

Functions

Check that the number of letters in the candidate word are less than or equal to the number of letters in the word we used as a source

This takes a string mask like "...x.." and creates a string that can be turned into a regex for searching

Give us a list of words from the dictionary, using the letters from source, that conform to the match pattern. The match looks like a "normal" regex, but when we have a . it matches the unused letters from the source word

Functions

check_word(word_char_counts, source_char_counts)

@spec check_word(Map, Map) :: true | false

Check that the number of letters in the candidate word are less than or equal to the number of letters in the word we used as a source

make_mask(source_word, match_string)

@spec make_mask(String.t(), String.t()) :: String.t()

This takes a string mask like "...x.." and creates a string that can be turned into a regex for searching:

Say the word is "banana" and we want to see words that will match a pattern like "..ana", as in each . would match the unused characters from our source word. You would need /[ban][ban]ana/ - this method generates it.

words(source_word, match_pattern)

Give us a list of words from the dictionary, using the letters from source, that conform to the match pattern. The match looks like a "normal" regex, but when we have a . it matches the unused letters from the source word

The default search is caseless and will find acronyms and proper names, pass an empty options list to turn this behaviour off

Options [:proper_names] and [:acronyms] will do the obvious thing

The option [:standard] turns off caseless and will only find "proper" words

words(source_word, match_pattern, options)

@spec words(String.t(), String.t(), [term()]) :: [String.t()] | {:error, String.t()}