我需要从给定的文本文件中提取每个句子并将该句子存储在字符串中。我使用的是 stanford-parser 的 lexparser-gui,该工具突出显示给定文件的每个句子。有没有办法,我可以使用 stanford-parser.jar 在 java 程序中进行句子提取?如果是的话,任何人都可以提供一个有关如何执行此操作的示例演示。
谢谢, 桑巴夫
最佳答案
如果您只想从文本文件中提取句子,则无需使用解析器。您可以使用常规句子拆分器,如下所示:
Properties props = new Properties();
props.setProperty("annotators","tokenize, ssplit");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation annotation = new Annotation("This is sentence one. This is sentence two.");
pipeline.annotate(annotation);
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
System.out.println(sentence);
}
关于java - 如何使用 stanford-parser 从文本文件中提取每个句子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29933278/