如何使用斯坦福解析器将文本拆分成句子? [英] How can I split a text into sentences using the Stanford parser?
本文介绍了如何使用斯坦福解析器将文本拆分成句子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用斯坦福解析器将文本或段落分割成句子?
How can I split a text or paragraph into sentences using Stanford parser?
是否有任何方法可以提取句子,例如 getSentencesFromString()
,因为它是为 Ruby ?
Is there any method that can extract sentences, such as getSentencesFromString()
as it's provided for Ruby?
推荐答案
你可以检查DocumentPreprocessor类。下面是一个简短的片段。我认为可能有其他方法可以做你想做的事。
You can check the DocumentPreprocessor class. Below is a short snippet. I think there may be other ways to do what you want.
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);
}
这篇关于如何使用斯坦福解析器将文本拆分成句子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文