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.
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:
-
IgnoreCase False whether to ignore letter casing - WordFrequency[text,word,"CaseVariants"] gives an association that includes frequencies of all variants of upper and lower case.
Examples
open all close allBasic Examples (2)
Scope (7)
Basic Uses (4)
Find the frequency of "had" in a given string:
WordFrequency["James while John had had had had had had had had had had had a better effect on the teacher", "had"]For a list of words, an association of frequencies will be returned:
WordFrequency["James while John had had had had had had had had had had had a better effect on the teacher", { "had", "the", "on"}]When using alternatives, the total frequency for the matching pattern will be returned:
WordFrequency["James while John had had had had had had had had had had had a better effect on the teacher", "the" | "on"]If multiple alternatives are specified, a frequency will be given for each:
WordFrequency["James while John had had had had had had had had had had had a better effect on the teacher", {"the" | "on", "had had" | "on the"}, IgnoreCase -> True]Case Variants (3)
A word can have many lower- and uppercase variants:
WordFrequency["That that is, is that THAT is. Not is not. Is that it? It is", "that", "CaseVariants"]For multiword inputs, case variants will be returned for each word present:
WordFrequency["That that is, is that THAT is. Not is not. Is that it? It is", {"that", "it"}, "CaseVariants"]Alternatively, an explicit list of case-sensitive words can be provided:
WordFrequency["That that is, is that THAT is. Not is not. Is that it? It is", {"that", "That", "THAT", "it", "It"}]Multiple words with "CaseVariants" will be returned as lists:
WordFrequency["That that is, is that THAT is. Not is not. Is that it? It is", {"that" | "not", "is is" | "that that"}, "CaseVariants"]Options (1)
IgnoreCase (1)
By default, frequencies account for only those words that match the case of the specified word:
WordFrequency["Buffalo from Buffalo, which buffalo from Buffalo bully, themselves bully buffalo from Buffalo.", "Buffalo"]With IgnoreCase->True, all variations in case will be counted together:
WordFrequency["Buffalo from Buffalo, which buffalo from Buffalo bully, themselves bully buffalo from Buffalo.", "Buffalo", IgnoreCase -> True]Possible Issues (2)
With IgnoreCase->True, the resulting association will omit keys for case-variant duplicates:
WordFrequency["Sentences should Be split by Words, and words may be split by letters", {"words", "be", "Be", "BE"}, IgnoreCase -> True]Words that do not appear within the given text will have a frequency of zero:
WordFrequency[ExampleData[{"Text", "DeclarationOfIndependence"}], "beltalowda"]Neat Examples (2)
The frequency of articles in a sample of Alice in Wonderland:
WordFrequency[ExampleData[{"Text", "AliceInWonderland"}], {"a", "an", "the"}, "CaseVariants"]WordFrequency[ExampleData[{"Text", "AliceInWonderland"}], {"a", "an", "the"}, IgnoreCase -> True]Create a word cloud using the frequencies for the names of the characters in this book:
WordCloud[WordFrequency[ExampleData[{"Text", "AliceInWonderland"}], {"Alice", "Queen", "Rabbit", "Duchess", "King", "Mouse", "Hatter", "Cat", "Dodo", "Caterpillar"}, IgnoreCase -> True]]The frequency of the word "mission" in the Wikipedia article "Moon":
WordFrequency[WikipediaData["Moon"], "mission", IgnoreCase -> True]Related Guides
Related Workflows
- Analyze the Text on a Webpage
History
Text
Wolfram Research (2016), WordFrequency, Wolfram Language function, https://reference.wolfram.com/language/ref/WordFrequency.html.
CMS
Wolfram Language. 2016. "WordFrequency." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/WordFrequency.html.
APA
Wolfram Language. (2016). WordFrequency. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WordFrequency.html
BibTeX
@misc{reference.wolfram_2026_wordfrequency, author="Wolfram Research", title="{WordFrequency}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/WordFrequency.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_wordfrequency, organization={Wolfram Research}, title={WordFrequency}, year={2016}, url={https://reference.wolfram.com/language/ref/WordFrequency.html}, note=[Accessed: 12-June-2026]}