gerhardvanwyk / tfrequency

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Text Frequency

The following are assumptions and definitions that limit the scope of the task:

  • Word: To simplify, a word is represented by a sequence of one or more characters between „a‟ and „z‟ or between „A‟ and „Z‟). For example “agdfBh”.
  • Letter Case: When counting frequencies, we are interested in the case insensitive frequency (i.e. in the text “The sun shines over the lake”, the library should count 2 occurrences for any of the words “the” or “The” or “tHE” etc).
  • Input Text: The input text contains words separated by various separator characters. Note that the characters from „a‟ and „z‟ and „A‟ and „Z‟ can only appear within words.
  • Available Memory: There is enough memory to store the

Implementation (Java version)

  • Create a class which implements the following interface:
public interface WordFrequency { 
       String getWord(); 
       int getFrequency(); 
}
  • Create a class which implements the following interface:
- public interface WordFrequencyAnalyzer { 
   int calculateHighestFrequency(String text); 
   int calculateFrequencyForWord (String text, String word); 
   List<WordFrequency> calculateMostFrequentNWords (String text, int n); 
}

Implement the three methods defined in this interface

  • CalculateHighestFrequency should return the highest frequency in the text (several words might have this frequency)
  • CalculateFrequencyForWord should return the frequency of the specified word
  • CalculateMostFrequentNWords should return a list of the most frequent „n‟ words in the input text, all the words returned in lower case. If several words have the same frequency, this method should return them in ascendant alphabetical order (for input text “The sun shines over the lake” and n = 3, it should return the list {(“the”, 2), (“lake”, 1), (“over”, 1) }

Implementation (Jakarta EE version)

CalculateHighestFrequency

curl -i -X GET http://localhost:8080/hf?text=The%20brown%20fox%2C%20jump%2C%20over%20the%20moon%20that%20jump%2C%20jump%20and%20jumps%20on%20brown%20dusky%20eves%2E

CalculateFrequencyForWord

curl -i -X GET http://localhost:8080/ffw?word=the%26text=The%20brown%20fox%2C%20jump%2C%20over%20the%20moon%20that%20jump%2C%20jump%20and%20jumps%20on%20brown%20dusky%20eves%2E

CalculateMostFrequentNWords

curl -i -X GET http://localhost:8080/mfnw?n=3%26text=The%20brown%20fox%2C%20jump%2C%20over%20the%20moon%20that%20jump%2C%20jump%20and%20jumps%20on%20brown%20dusky%20eves%2E

About


Languages

Language:Java 100.0%