Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #2450
| From | Barrie Stokes <Barrie.Stokes@newcastle.edu.au> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Count Ouccrence of words in a long text |
| Date | 2011-05-18 11:16 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <ir09qp$226$1@smc.vnet.net> (permalink) |
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@smc.vnet.net>, Yako <yako@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!
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Count Ouccrence of words in a long text Barrie Stokes <Barrie.Stokes@newcastle.edu.au> - 2011-05-18 11:16 +0000
csiph-web