Title: | Crossword, Scrabble and Anagram Solver |
---|---|
Description: | Provides a large English words list and tools to find words by patterns. In particular, anagram finder and scrabble word finder. |
Authors: | Iaroslav Domin [aut, cre] |
Maintainer: | Iaroslav Domin <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0 |
Built: | 2024-11-04 03:02:49 UTC |
Source: | https://github.com/idmn/wfindr |
Calculates character frequencies in a vector.
char_count(x)
char_count(x)
x |
character vector, or a list that can be unlisted to a character vector. |
data.frame with two columns: char
- character and count
- number of it's occurencies.
char_count("character") char_count(words.eng)
char_count("character") char_count(words.eng)
Uses regex constructed by model_to_regex
to search
words. By default the search is done among words.eng
.find_word
returns a vector of found words, find_word_l
returns a logical vector that can be used for subsetting.
find_word(model = "*", allow = letters, ban = character(0), type = "usual", words = wfindr::words.eng) find_word_l(model = "*", allow = letters, ban = character(0), type = "usual", words = wfindr::words.eng)
find_word(model = "*", allow = letters, ban = character(0), type = "usual", words = wfindr::words.eng) find_word_l(model = "*", allow = letters, ban = character(0), type = "usual", words = wfindr::words.eng)
model |
pattern that a word should match. Consists of letters and
unknown characters specifications. Dot |
allow |
characters allowed to fill gaps in a word. Can be listed in a
single string or in a vector. By default is set to |
ban |
characters not allowed to fill gaps in a word. |
type |
can be
|
words |
vector of words to search within. By default is set to
|
## Search 4-letter words starting with "c". find_word("c.{3}") ## Disallow "a" and "b". find_word("c.{3}", ban = "ab") ## Allow only "a" and "b" to fill the gap. find_word("c.{3}", allow = "ab") ## Allow "a", "b", and "c", but then ban "c" ## result is the same as in the previous example find_word("c.{3}", allow = "abc", ban = "c") ## Find no more than 4-letter words that have "th" bigram library(magrittr) find_word(".{0,4}") %>% find_word("*th*", words = .) ## count words that start with "th" sum(find_word_l("th*")) length(find_word("th*")) ## Find words that can be constructed of the "thing" word's letters. find_word(allow = "thing", type = "scrabble") ## Get at lest 4-letter words. find_word(".{4,}", allow = "thing", type = "scrabble") ## Find anagrams of the word "thing" find_word(allow = "thing", type = "anagram")
## Search 4-letter words starting with "c". find_word("c.{3}") ## Disallow "a" and "b". find_word("c.{3}", ban = "ab") ## Allow only "a" and "b" to fill the gap. find_word("c.{3}", allow = "ab") ## Allow "a", "b", and "c", but then ban "c" ## result is the same as in the previous example find_word("c.{3}", allow = "abc", ban = "c") ## Find no more than 4-letter words that have "th" bigram library(magrittr) find_word(".{0,4}") %>% find_word("*th*", words = .) ## count words that start with "th" sum(find_word_l("th*")) length(find_word("th*")) ## Find words that can be constructed of the "thing" word's letters. find_word(allow = "thing", type = "scrabble") ## Get at lest 4-letter words. find_word(".{4,}", allow = "thing", type = "scrabble") ## Find anagrams of the word "thing" find_word(allow = "thing", type = "anagram")
Build a regular expression to fit chosen parameters
model_to_regex(model = "*", allow = letters, ban = character(0), type = "usual")
model_to_regex(model = "*", allow = letters, ban = character(0), type = "usual")
model |
pattern that a word should match. Consists of letters and
unknown characters specifications. Dot |
allow |
characters allowed to fill gaps in a word. Can be listed in a
single string or in a vector. By default is set to |
ban |
characters not allowed to fill gaps in a word. |
type |
can be
|
If type = "scrabble"
or "anagram"
, output
regex will contain perl-like syntax. So, to use it in grep
or
gsub
for example, set perl
parameter to TRUE
.
## Regular expression to match all the 5-letter words starting with "c". model_to_regex("c.{4}") ## Disallow "a" and "b". model_to_regex("c.{4}", ban = "ab") ## Allow only "a" and "b" to fill the gap. model_to_regex("c.{4}", allow = "ab") ## Allow "a", "b", and "c", but then ban "c" (result is the same as the previous example) model_to_regex("c.{4}", allow = "abc", ban = "c") ## Regex to match all words that start with "p" and end with "zed". model_to_regex("p*zed") ## Regex to match all the words that can be constructed of the word "thing". model_to_regex(allow = "thing", type = "scrabble") ## Get at lest 4-letter words. model_to_regex(".{4,}", allow = "thing", type = "scrabble") ## Regex to match anagrams of the word "thing" model_to_regex(allow = "thing", type = "anagram")
## Regular expression to match all the 5-letter words starting with "c". model_to_regex("c.{4}") ## Disallow "a" and "b". model_to_regex("c.{4}", ban = "ab") ## Allow only "a" and "b" to fill the gap. model_to_regex("c.{4}", allow = "ab") ## Allow "a", "b", and "c", but then ban "c" (result is the same as the previous example) model_to_regex("c.{4}", allow = "abc", ban = "c") ## Regex to match all words that start with "p" and end with "zed". model_to_regex("p*zed") ## Regex to match all the words that can be constructed of the word "thing". model_to_regex(allow = "thing", type = "scrabble") ## Get at lest 4-letter words. model_to_regex(".{4,}", allow = "thing", type = "scrabble") ## Regex to match anagrams of the word "thing" model_to_regex(allow = "thing", type = "anagram")
scrabble
finds words that can be constructed from the
specified set of letters. anagram
finds words that are
permutations of the specified set of letters. Usually this set of letters
is a word itself.
scrabble(allow, model = "*", ban = character(0), words = wfindr::words.eng) anagram(allow, model = "*", ban = character(0), words = wfindr::words.eng)
scrabble(allow, model = "*", ban = character(0), words = wfindr::words.eng) anagram(allow, model = "*", ban = character(0), words = wfindr::words.eng)
allow |
characters allowed to use to construct words. |
model |
pattern that a word should match. Consists of letters and
unknown characters specifications. Dot |
ban |
characters not allowed to fill gaps in a word. |
words |
vector of words to search within. By default is set to
|
scrabble
and anagram
are functions built on top of the
find_word
function with parameter type
set to
"scrabble"
or "anagram"
respectively and allow
parameter moved to the first place to simplify usage (see the first
example).
## Find all words that can be constructed of the "thing" word's letters scrabble("thing") ## same as find_word(allow = "thing", type = "s") ## take at least 4-letter words scrabble("thing", ".{4,}") ## same as find_word(".{4,}", "thing", type = "s") ## Pick 8 random letters and find words that can be constructed of them. library(magrittr) sample(letters, 8, TRUE) %>% list(letters = ., words = scrabble(.)) ## Find anagrams of the word "thing" anagram("thing")
## Find all words that can be constructed of the "thing" word's letters scrabble("thing") ## same as find_word(allow = "thing", type = "s") ## take at least 4-letter words scrabble("thing", ".{4,}") ## same as find_word(".{4,}", "thing", type = "s") ## Pick 8 random letters and find words that can be constructed of them. library(magrittr) sample(letters, 8, TRUE) %>% list(letters = ., words = scrabble(.)) ## Find anagrams of the word "thing" anagram("thing")
263,533 english words list took from http://norvig.com/ngrams/
(See word.list
file).
An object of class character
of length 263533.