Skip to content

Instantly share code, notes, and snippets.

@milindjagre
Created December 17, 2018 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milindjagre/bbcc8f5b640e89893209bf2507927fbf to your computer and use it in GitHub Desktop.
Save milindjagre/bbcc8f5b640e89893209bf2507927fbf to your computer and use it in GitHub Desktop.
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