Wahedsaw
Wahedsaw

Reputation: 397

Specifying the frequencies of nouns in text using java

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

Answers (1)

awolfe91
awolfe91

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

Related Questions