stripping out punctuation

This commit is contained in:
2020-07-03 16:26:13 -05:00
parent 640ea5a735
commit 2513999d29

View File

@@ -14,10 +14,13 @@ public class RandomWordFileReader {
public RandomWordFileReader(String filename){
try(BufferedReader reader = Files.newBufferedReader(Path.of(filename));){
//This should use flatMap to make a string array from the line, and then turn the elements of that array into a stream, which goes to forEach
reader.lines().flatMap(line -> Arrays.stream(line.split("\\s+"))).forEach(word -> words.add(word.toLowerCase()));
reader.lines().flatMap(line -> Arrays.stream(line.split("[\\s\\W_0]+"))).forEach(word -> words.add(word.toLowerCase()));
}catch (IOException ex){
System.err.println(ex);
}
/*for (String e : words) {
e = e.replaceAll("\\W+","");
}*/
}
public ArrayList<String> getWords(){