Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This method returns the number of sentences used by eminem in his lyrical career.
public static int getNumberOfSentences(SentenceModel sentenceModel,
String input) throws IOException {
SentenceDetectorME detector = new SentenceDetectorME(sentenceModel);
String sentences[] = detector.sentDetect(input);
return sentences.length;
}
String[] inputFilePathArray = new String[4];
inputFilePathArray[0] = "C:\\input1.txt";
inputFilePathArray[1] = "C:\\input2.txt";
inputFilePathArray[2] = "C:\\input3.txt";
inputFilePathArray[3] = "C:\\input4.txt";
InputStream inputStream = new FileInputStream("C:\\en-sent.bin");
SentenceModel sentenceModel = new SentenceModel(inputStream);
int sentenceCounts = 0;
for (String inputFilePath : inputFilePathArray) {
BufferedReader br = new BufferedReader(
new FileReader(inputFilePath));
String line = null, mapKey = null;
String[] lineSplitter = null;
int i = 0;
while ((line = br.readLine()) != null) {
sentenceCounts += getNumberOfSentences(sentenceModel, line);
}
br.close();
}
System.out.println("***NUMBER OF SENTENCES USED***");
System.out.print(sentenceCounts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.