KZKY memo

自分用メモ.

Scala 20news Wordcount

Scala 20news Wordcountを忘れないようにメモ.

val src_path = "/home/kzk/datasets/news20/news20.dat"
val s = Source.fromFile(src_path);
var map = scala.collection.mutable.Map[String, Long]()

for (l <- s.getLines) {
    val sl = l.split(" ")
    for (i <- Range(1, sl.length)) {
        val k = sl(i).split(":")(0)
        if (map.contains(k)) {map(k)} += 1 else {map(k) = 0}
    }
}

println map.take(10)