Java和Stanford解析器
我使用StanfordCoreNLP jar文件库将英语段落拆分为句子,但我可以将拆分的句子作为CoreMap对象检索,但我想将CoreMap类型的拆分句子转换为String类型,是否仍有实现此任务的方法。代码中的粗体文本显示了使用CoreMap的区域,我希望检索到的句子将其转换为字符串
代码片段:
props.setProperty("annotators","tokenize,ssplit");
//put that in a pipeline
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
//a data structure for the annotation
Annotation document = new Annotation(text);
// run the pipeline on that data structure
pipeline.annotate(document);
// access the annotations which has worked on a sentence
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
PrintStream printStream = new PrintStream(new FileOutputStream("/home/sakshi/Desktop/Admin_System/translate.en"));
PrintStream console = System.out; // To store the reference to default output stream to use it to restore the default std output stream
System.setOut(printStream);// To change the default output stream
**for (CoreMap sentence : sentences) {
System.out.println(sentence);**
}
System.setOut(console);
response.setContentType("text/plain");
response.getWriter().write(text);
共 (0) 个答案