Skip to content

Instantly share code, notes, and snippets.

@uzilan
Last active November 30, 2021 08:39
Show Gist options
  • Save uzilan/a0da4f1dd152f7d96804fe68425f150f to your computer and use it in GitHub Desktop.
Save uzilan/a0da4f1dd152f7d96804fe68425f150f to your computer and use it in GitHub Desktop.
package zer.ubba.bel;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import static java.lang.ClassLoader.getSystemResource;
import static java.util.Arrays.stream;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
public class JavaBible {
private final List<String> boringWords = List.of(("the,and,of,to,that,for,in,i,his,a,with,it,be,is,not,they,thou")
.split(","));
Map<String, Long> readTheBible() throws Exception {
final var path = Paths.get(getSystemResource("bible.txt").toURI());
return Files.lines(path)
.flatMap(line -> stream(line.split(" ")))
.filter(Pattern.compile("^\\w+").asMatchPredicate())
.map(String::toLowerCase)
.filter(word -> !boringWords.contains(word))
.collect(groupingBy(identity(), counting()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment