Created
November 30, 2021 08:42
-
-
Save uzilan/60ac0ad8994d84975a83e070e2870048 to your computer and use it in GitHub Desktop.
This file contains 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
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