Skip to content

Instantly share code, notes, and snippets.

@ghidalgo3
Created September 18, 2014 15:28
Show Gist options
  • Save ghidalgo3/f97895f3ce36dd4a0c27 to your computer and use it in GitHub Desktop.
Save ghidalgo3/f97895f3ce36dd4a0c27 to your computer and use it in GitHub Desktop.
//read a file and build a concordance list of the tokens in the file
//there's gotta be a nicer way to do this
def two(fileName:String): Unit = {
val scanner = new Scanner(new File(fileName))
val concordanceList = new mutable.HashMap[String, Int]()
while(scanner hasNext) {
scanner.nextLine()
.split(" ")
.foreach {
word => if(concordanceList contains word) {
concordanceList.update(word, concordanceList(word) + 1)
} else {
concordanceList += (word -> 1)
}
}
}
println(concordanceList)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment