Wolfram Language & System 10.4 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

WordCounts

WordCounts["string"]
gives an association whose keys are the distinct words identified in string, and whose values give the number of times those words appear in string.

WordCounts["string",n]
gives counts of the distinct n-grams consisting of runs of n words in string.

Details and OptionsDetails and Options

  • WordCounts[string,] identifies words in string in the same way as TextWords.
  • In WordCounts[string,n], words that are considered part of an n-gram must appear consecutively in string, not separated by nonword characters other than whitespace.
  • WordCounts has the option IgnoreCase. With the setting IgnoreCase->True, letters are in effect all converted to lower case before being counted.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

Count distinct words in a string:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Count distinct 2-grams:

In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=
Introduced in 2015
(10.1)