Consider the following:
StringData1={"Dog","Dog","Dog","Dog","Duck","Duck","Duck","Rabbit","House"};
StringData2={"A dog is in the house.","A dog is outside.",
"Why is everybody talking about a dog?", "Dog", "The duck died in the house.",
"The duck is actually a rabbit.", "Duck", "And the rabbit in fact is a dog",
"I have a dog in my house."};
Using the following function, it is quite easy to plot a histogram for StringData1
. However the options remain fixed.
StringHistogram[list_] :=
Module[{counter, strings, numbers},
counter = {First@#, Length@#} & /@ (GatherBy@list);
strings = First /@ counter;
numbers = Last /@ counter;
BarChart[numbers, ChartLabels -> strings]
]
In case of StringData2
I was wondering whether it would be possible to chop up each sentence into single words (e.g.{Sentence1,...} -> {{Word1, Word2,...},...}
) and then to run StringHistogram
on Flatten@StringData2New
, whereas StringData2New
is of the form {{Word1, Word2,...},...}
.