如何使用斯坦福解析器将文本拆分为句子?

如何使用Stanford解析器将文本或段落拆分为句子?

有没有可以提取句子的方法(例如getSentencesFromString()为Ruby提供的方法)?

回答:

您可以检查DocumentPreprocessor类。以下是一个简短的摘要。我认为可能还有其他方式可以做您想要的事情。

String paragraph = "My 1st sentence. “Does it work for questions?” My third sentence.";

Reader reader = new StringReader(paragraph);

DocumentPreprocessor dp = new DocumentPreprocessor(reader);

List<String> sentenceList = new ArrayList<String>();

for (List<HasWord> sentence : dp) {

// SentenceUtils not Sentence

String sentenceString = SentenceUtils.listToString(sentence);

sentenceList.add(sentenceString);

}

for (String sentence : sentenceList) {

System.out.println(sentence);

}

以上是 如何使用斯坦福解析器将文本拆分为句子? 的全部内容, 来源链接: utcz.com/qa/398366.html

回到顶部