Re: Count Ouccrence of words in a long text
- To: mathgroup at smc.vnet.net
- Subject: [mg118985] Re: Count Ouccrence of words in a long text
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Wed, 18 May 2011 07:18:48 -0400 (EDT)
- References: <iqtn8n$ilc$1@smc.vnet.net>
Hi, > 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? I think there might be languages that are better suited for this kind of tasks, especially if the text becomes _really_ long. Anyway, it is fairly easy in Mathematica and resonable fast, too: text = Import["ExampleData/USConstitution.txt"]; words = StringCases[text, WordCharacter ..]; Tally[words] hth, albert