Skip to content

Instantly share code, notes, and snippets.

@uzilan
Created November 30, 2021 08:42
Show Gist options
  • Save uzilan/60ac0ad8994d84975a83e070e2870048 to your computer and use it in GitHub Desktop.
Save uzilan/60ac0ad8994d84975a83e070e2870048 to your computer and use it in GitHub Desktop.
package zer.ubba.bel
import java.io.File
import java.lang.ClassLoader.getSystemResource
import java.util.Locale
private val boringWords = ("the,and,of,to,that,for,in,i,his,a,with,it,be,is,not,they,thou")
.split(",")
fun readTheBible(): Map<String, Int> {
val file = File(getSystemResource("bible.txt").file)
return file
.readLines()
.flatMap { it.split(" ") }
.filter { """^\w+""".toRegex().matches(it) }
.map { it.lowercase(Locale.getDefault()) }
.filter { !boringWords.contains(it) }
.groupingBy { it }.eachCount()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment