Created
September 15, 2009 04:08
-
-
Save dcbriccetti/187107 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Word(val word: String, val count: Long) { | |
override def toString = word + ": " + count | |
} | |
private def showWordCloud { | |
val counts = LinkedHashMap[String,Long]() | |
statusTableModel.filteredStatuses.map(status => { | |
List.fromArray(status.text.split("\\s")).foreach(word => { | |
counts.put(word, counts.getOrElse(word, 0L) + 1L) | |
}) | |
}) | |
var countList = List[Word]() | |
counts.foreach(item => countList ::= Word(item._1, item._2)) | |
countList = countList.sort(_.count > _.count) | |
log.info(countList) | |
} | |
// I'm very pleased with this rewrite from @jorgeortiz85: | |
case class Word(word: String, count: Long) { | |
override def toString = word + ": " + count | |
def +(n: Long): Word = Word(word, count + n) | |
} | |
private def showWordCloud { | |
val words = statusTableModel.filteredStatuses.flatMap(_.text.split("\\s")) | |
val emptyMap = collection.immutable.Map.empty[String, Word].withDefault(w => Word(w, 0)) | |
val counts = words.foldLeft(emptyMap)((map, word) => map(word) += 1) | |
val countList = counts.values.toList.sort(_.count > _.count) | |
log.info(countList) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment