WordFrequency

WordFrequency[text,word]

gives the frequency of word in text.

WordFrequency[text,{word1,word2,}]

gives an association of the frequencies of each of the wordi.

Details and Options

  • WordFrequency[text,word] gives the number of occurrences of word divided by the total number of words in text.
  • In WordFrequency[text,word], word can be a multiword string containing spaces. For an n-gram string, the result is divided by the total number of n-grams in text.
  • WordFrequency[text,word1|word2|] gives the total frequency of all the wordi.
  • WordFrequency[{text1,text2,},word] gives a list of frequencies in each of the texti.
  • Possible options include:
  • IgnoreCaseFalsewhether to ignore letter casing
  • WordFrequency[text,word,"CaseVariants"] gives an association that includes frequencies of all variants of upper and lower case.

Examples

open allclose all

Basic Examples  (2)

Find the frequency of the word "the" in a string:

Find the frequencies for a list of words:

Scope  (7)

Find the frequency of "had" in a given string:

For a list of words, an association of frequencies will be returned:

When using alternatives, the total frequency for the matching pattern will be returned:

If multiple alternatives are specified, a frequency will be given for each:

CaseVariants  (3)

A word can have many lower- and uppercase variants:

For multiword inputs, case variants will be returned for each word present:

Alternatively, an explicit list of case-sensitive words can be provided:

Multiple words with "CaseVariants" will be returned as lists:

Options  (1)

IgnoreCase  (1)

By default, frequencies account for only those words that match the case of the specified word:

With IgnoreCase->True, all variations in case will be counted together:

Possible Issues  (1)

With IgnoreCase->True, the resulting association will omit keys for case-variant duplicates:

Neat Examples  (2)

The frequency of articles in a sample of Alice in Wonderland:

Create a word cloud using the frequencies for the names of the characters in this book:

The frequency of the word "mission" in the Wikipedia article "Moon":

Introduced in 2016
 (10.4)