Datasets:
ArXiv:
License:
File size: 958 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
package rd222dv_assign1;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.Stream;
public class WarAndPeace {
public static void main(String[] args) throws IOException {
String text = readText("WarAndPeace.txt");
String[] words = text.split(" ");
System.out.println("Initial word count: " + words.length);
long uniqueWords = Arrays.stream(words).filter(t -> !t.matches("[a-zA-Z]*")).distinct().count();
// the output is probably not unique enough, but I am running out of time, so I will ask for more filters during the lab sessions
System.out.println("Unique words: " +uniqueWords);
}
private static String readText(String string) throws IOException {
byte[] encoded = Files
.readAllBytes(Paths.get("D:\\lnu\\java_courses\\1DV507\\src\\rd222dv_assign1\\WarAndPeace.txt"));
return new String(encoded);
}
}
|