Last active
January 17, 2018 08:21
-
-
Save prskr/8ea0f916e0a1510c323270b248a6a419 to your computer and use it in GitHub Desktop.
Utility to transform Stream of tweets to a Stream of single words
This file contains hidden or 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 de.fhro.inf.prg3.a13.utils; | |
| import de.fhro.inf.prg3.a13.model.Tweet; | |
| import java.util.regex.Pattern; | |
| import java.util.stream.Stream; | |
| /** | |
| * @author Peter Kurfer | |
| */ | |
| public abstract class SplitUtils { | |
| /** | |
| * Pattern to filter for words that are only alpha numerical | |
| */ | |
| private static final Pattern ALPHA_NUMERICAL = Pattern.compile("[a-z0-9@]+"); | |
| /** | |
| * Pattern to split for words | |
| */ | |
| private static final Pattern WORD_SPLIT = Pattern.compile("\\W"); | |
| private SplitUtils() { | |
| } | |
| public static Stream<String> splitTweetText(final Stream<Tweet> tweetStream) { | |
| return tweetStream | |
| .map(Tweet::getText) | |
| .flatMap(WORD_SPLIT::splitAsStream) | |
| .map(String::toLowerCase) | |
| .filter(word -> ALPHA_NUMERICAL.matcher(word).matches()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment