private String[] testOpenNLP(String text) throws Exception { try (InputStream modelIn = this.getClass().getResourceAsStream(RESOURCES_EN_SENT_BIN)) { SentenceModel model = new SentenceModel(modelIn); SentenceDetectorME sentenceDetector = new SentenceDetectorME(model); return sentenceDetector.sentDetect(text); } }
while ((para = paraStream.read()) != null) { String[] sents = sdetector.sentDetect(para); for (String sentence : sents) { System.out.println(sentence);
// Initialize the sentence detector final SentenceDetectorME sdetector = EasyParserUtils .getOpenNLPSentDetector(Constants.SENTENCE_DETECTOR_DATA); // Initialize the parser final Parser parser = EasyParserUtils .getOpenNLPParser(Constants.PARSER_DATA_LOC); // Get sentences of the text final String sentences[] = sdetector.sentDetect(essay); // Go through the sentences and parse each for (final String sentence : sentences) { // Parse the sentence, produce only 1 parse final Parse[] parses = ParserTool.parseLine(sentence, parser, 10); if (parses.length == 0) { // Most probably this is code } else { // An English sentence } }
@Override public List<String> extractSentences(String text) { String[] sentences = sentenceDetector.sentDetect(text); return newArrayList(sentences); }
String[] sents = sentDetect.sentDetect(sampleSentences1); Assert.assertEquals(sents.length,2); Assert.assertEquals(sents[0],"This is a test."); sents = sentDetect.sentDetect(sampleSentences2); Assert.assertEquals(sents.length,2); probs = sentDetect.getSentenceProbabilities(); sents = sentDetect.sentDetect(sampleSentences3); Assert.assertEquals(sents.length,2); probs = sentDetect.getSentenceProbabilities(); sents = sentDetect.sentDetect(sampleSentences4); Assert.assertEquals(sents.length,3); probs = sentDetect.getSentenceProbabilities(); sents = sentDetect.sentDetect(sampleSentences5); Assert.assertEquals(1, sentDetect.getSentenceProbabilities().length); Assert.assertEquals(sents[0],"This is a one sentence test space at the end."); sents = sentDetect.sentDetect(sampleSentences6); Assert.assertEquals(sents[0],"This is a one sentences test with tab at the end."); sents = sentDetect.sentDetect(sampleSentences7); Assert.assertEquals(sents[0],"This is a test."); Assert.assertEquals(sents[1],"With spaces between the two sentences."); sents = sentDetect.sentDetect(sampleSentences9); Assert.assertEquals(0, sents.length);
public static Set<String> parseSentencesNLP(String input, ITokenizer tokenizer, int minimumWordsInASentence) throws Exception { SentenceDetectorME sentenceDetector = new SentenceDetectorME( SENTENCE_MODEL); String[] rawSentences = sentenceDetector.sentDetect(input); HashSet<String> sentences = new HashSet<String>(); for (int i = 0; i < rawSentences.length; i++) { String rawSentence = rawSentences[i]; String[] words = tokenizer.tokenize(rawSentence); if (words.length >= minimumWordsInASentence) { sentences.add(rawSentence); } } return sentences; }
public static Set<String> parseSentencesNLP(String input, ITokenizer tokenizer, int minimumWordsInASentence) throws Exception { SentenceDetectorME sentenceDetector = new SentenceDetectorME( SENTENCE_MODEL); String[] rawSentences = sentenceDetector.sentDetect(input); HashSet<String> sentences = new HashSet<String>(); for (int i = 0; i < rawSentences.length; i++) { String rawSentence = rawSentences[i]; String[] words = tokenizer.tokenize(rawSentence); if (words.length >= minimumWordsInASentence) { sentences.add(rawSentence); } } return sentences; }
final String sentences[] = sdetector.sentDetect(essay);
while ((para = paraStream.read()) != null) { String[] sents = sdetector.sentDetect(para); for (String sentence : sents) { System.out.println(sentence);
while ((para = paraStream.read()) != null) { String[] sents = sdetector.sentDetect(para); for (String sentence : sents) { System.out.println(sentence);