private static String unescapeKeywords(String term) { return splitIdentifiers .splitAsStream(term + " ") // add space such that the ending "::" is not lost .map(BaseRascalREPL::unescapeKeyword) .collect(Collectors.joining("::")) .trim(); }
public static void main(String[] args) throws IOException { Pattern wordSeparator = Pattern.compile("[\\P{L}]+"); try (Stream<String> lines = Files.lines(Paths.get("frankenstein.txt"))) { System.out.println( lines.flatMap(l -> wordSeparator.splitAsStream(l)).filter(x -> x.length() > 10).count()); } }
private static Collection<String> escapeKeywords(Collection<String> suggestions) { return suggestions .stream() .map( s -> splitIdentifiers .splitAsStream(s + " ") // add space such that the ending "::" is not lost .map(BaseRascalREPL::escapeKeyword) .collect(Collectors.joining("::")) .trim()) .collect(Collectors.toList()); }
private Set<Word> addTweetToCloud(Tweet tweet) { // System.out.println("Add tweet to cloud"); String text = tweet .getTextWithout(UrlTweetEntry.class) .getTextWithout(UserMentionTweetEntry.class) .get(); Set<Word> tweetWords = pattern .splitAsStream(text) .map(l -> trimTail(l)) // no bad word tails .filter(l -> l.length() > 2) // longer than 2 characters .filter(l -> !urlPattern.matcher(l).matches()) // no url .filter(l -> !StopList.contains(l)) // not in stoplist .map(l -> new Word(l, -2)) // convert to Word .collect(Collectors.toSet()); // collect List<Word> words = new ArrayList<>(wordle.wordsProperty().get()); tweetWords.removeAll(words); words.addAll(tweetWords); Platform.runLater(() -> wordle.wordsProperty().set(words)); return tweetWords; }
public Stream<String> parse(String text) { return SPLIT_PATTERN.splitAsStream(text).map(String::toLowerCase); }