我需要从给定的文本文件中提取每个句子,并将该句子存储在一个字符串中。我使用的是stanford-parser的lexparser-gui,该工具突出显示了给定文件中的每一句话。有没有一种方法可以在java程序中使用stanford-parser.jar进行句子提取?如果是,谁能给出一个如何做到这一点的示例演示。
谢谢,Sambhav
发布于 2015-04-29 15:19:07
如果您只想从文本文件中提取句子,则不需要使用解析器。您可以只使用常规的句子分隔符,如下所示:
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);
}https://stackoverflow.com/questions/29933278
复制相似问题