This is my code, and it splits data into sentences. Each sentence is labeled with an emotion. I need to count the number of sentences for each label (emotion) and split the dataset according to labels.
public class DataProcessor {
public static void main(String[] args) throws FileNotFoundException {
try (Scanner read = new Scanner (new File("E:\\blabla.txt"))) {
read.useDelimiter("::");
String tweet;
while(read.hasNext())
{
tweet = read.next();
System.out.println(tweet + " "+ "\n"); //just for debugging
}
}
}
}
output looks like this
joy: Had a test today. But I still was good
The
mapcontains all emotions with sentences. To get the number of sentences, lets call them tweets because sometimes they contain more than one, you can usemap.get("joy").size().If the tweet also can contain
:I would changetweet.split(":");totweet.split(":", 2);so that only the first delimiter is used to split.To check the result
mapyou can use this code: