find_word: Find words that fit the chosen parameters.

Description Usage Arguments See Also Examples

Description

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.

Usage

1
2
3
4
5
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)

Arguments

model

pattern that a word should match. Consists of letters and unknown characters specifications. Dot . stands for unknown character. It may be followed by {...} repetition quantifier (i.e. .{n}, .{n,}, .{n,m}). Asterisk * stands for unknown number of unknown characters. See examples.
By default model is set to "*".

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 letters.

ban

characters not allowed to fill gaps in a word.

type

can be "usual", "scrabble", or "anagram". Abbreviated input is allowed: e.g. "u", "s", or "a".
type defines how often allowed characters can be used to fill the gaps. Say, character appears n times in allow and m times in ban. If d = n - m is less or equal to zero, whatever the type is, this character won't be used to fill the gaps. For the case when d > 0:

  • If type is "usual" then the character is allowed to fill the gaps unlimited number of times.

  • If type is "scrabble" then the character is allowed to fill the gaps no more than d times.

  • If type is "anagram" then the character should be used exactly d times.

words

vector of words to search within. By default is set to words.eng.

See Also

scrabble, anagram

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## 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")

wfindr documentation built on May 2, 2019, 12:20 p.m.