4
$\begingroup$

I have created an autocomplete function based on WordList.

auto = Autocomplete[WordList["KnownWords"]]

And if I use this on the letters "ga", it will provide me with a long list of possible words. Is it possible to create a probability list from these to choose the most commonly used one?

I am aware this is more of a theoretical question and am happy with any answers that point me in the right direction.

$\endgroup$

1 Answer 1

3
$\begingroup$

QUICK TAKE

You can make use of WordFrequencyData and define

auto=Autocomplete[WordList["KnownWords"]];
hint[word_]:=First[Keys[ReverseSort[DeleteMissing[WordFrequencyData[auto[word],IgnoreCase->True]]]]]

It will give you most popular hint, for examplle:

hint["gath"]

"gathered"

DETAILS

So starting from hints for say "gath"

auto = Autocomplete[WordList["KnownWords"]];
hints = auto["gath"]

{"gather", "gatherer", "gathered", "gathering"}

you can find and sort reversely their frequencies in typical English:

freq=ReverseSort[DeleteMissing[WordFrequencyData[auto["gath"],IgnoreCase->True]]]

<|gathered->0.000013772,gathering->8.98098*10^-6,gather->7.46439*10^-6,gatherer->3.42559*10^-7|>

Then get already order hints as

Keys[freq]

{gathered,gathering,gather,gatherer}

or just the most frequent one

First[Keys[freq]]

"gathered"

NOTE

WordFrequencyData can slow down for too many words as it accesses Wolfram servers to download data and needs internet. One trick to speed this up - is to pre-download and save WordFrequencyData for your set of words. It might take a long time for many 1000s of words, but is doable if you split it in cycles by, say, 100 words.

$\endgroup$
2
  • $\begingroup$ Just to follow-up on how to speed it up, how can I pre-download certain words? $\endgroup$
    – Tim B
    Feb 1, 2020 at 20:27
  • 1
    $\begingroup$ @TimB prefetch = WordFrequencyData[{"cat", "dog"}] etc. then use prefetch variable to work with or save with Put Get etc. Read some docs on WordFrequencyData. $\endgroup$ Feb 1, 2020 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.