Reputation: 397
I have a file contains the words attached with POS tags such as
Tom/NNP went/VBP to/IN the/DT stadium/NN ....etc
I need to know the frequency of all nouns contains in this file. So, the output might be
stadium 12
football 20
player 13
where these numbers are the times of numbers these nouns occur in the text. How can I do this in java?
Upvotes: 0
Views: 213
Reputation: 1647
Have a map from Strings (nouns) to integers (the count). Loop through each word in the file. Examine the part of the word after the '/', and if it is a noun, put it in the map with a "1" value if it isn't already in there, or add 1 to the existing value. Then iterate through the map, printing out the key/value pairs.
Upvotes: 1