Groovy WordCount

class WordCountGroovy {
def wordCount [:]

void countWords({
  def file new File('src/main/groovy/collections/passage.txt')
  file.eachLine line ->
   List words line.tokenize()
   words.each word ->
    wordCount[wordwordCount.get(word,01
   }
  }
}

Map<String,IntegergetMostFrequent({
  def sorted [:]
  def sortedKeys wordCount.keySet().sort wordCount[it}
  sortedKeys[-1..-5].each word ->
   sorted[wordwordCount[word]
  }
  return sorted
}
}

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்