Re: Count Ouccrence of words in a long text
- To: mathgroup at smc.vnet.net
- Subject: [mg118973] Re: Count Ouccrence of words in a long text
- From: Barrie Stokes <Barrie.Stokes at newcastle.edu.au>
- Date: Wed, 18 May 2011 07:16:38 -0400 (EDT)
Hi Yako You will get a variety of responses to this question (we all love one-liners), but this is my 2 cents worth. One minute in the Help and I came up with: text = "Hello, First of all I am pretty new to Mathematica, so excuse me if this has a simple answer. What I need is to be able to count the occurrence of each word of a text and count the times each word appears on it. I know how to do this on other languages but I am trying to achieve it with Mathematica. Can someone hint me the way to go? Thanks!"; StringSplit[ text] // Tally // Grid or StringSplit[ text] // Tally // Sort // Grid to get the words in alphabetical order, or Map[ Reverse, StringSplit[ text] // Tally ] // Sort // Grid to get the words in order of increasing frequency, or Reverse[ Map[ Reverse, StringSplit[ text] // Tally ] // Sort ] // Grid to get the words in order of decreasing frequency. I.e., using your email text as the example text, StringSplit (by default) splits at spaces, and well, Tally is a *great* command for all sorts of applications. The sky*s the limit. Cheers Barrie >>> On 17/05/2011 at 9:47 pm, in message <201105171147.HAA19109 at smc.vnet.net>, Yako <yako at 11y11.com> wrote: > Hello, > > First of all I am pretty new to Mathematica, so excuse me if this has > a simple answer. > > What I need is to be able to count the occurrence of each word of a > text and count the times each word appears on it. I know how to do > this on other languages but I am trying to achieve it with > Mathematica. > > Can someone hint me the way to go? > > Thanks!