首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java和Stanford

Java和Stanford
EN

Stack Overflow用户
提问于 2018-03-21 11:36:43
回答 2查看 86关注 0票数 0

我使用StanfordCoreNLP jar文件库将英文段落拆分成句子,但我可以作为CoreMap对象检索拆分的句子,但我想将CoreMap类型的拆分语句转换为String,是否存在实现此任务的方法。代码中的粗体文本显示了使用CoreMap的区域,我希望检索到的句子将其转换为字符串。

代码片段:

代码语言:javascript
复制
    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);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-21 11:47:10

whatever.toString(),因为toString适用于每个java对象,因为每个对象都是从java.lang.Object继承的。

票数 -1
EN

Stack Overflow用户

发布于 2018-03-21 11:43:18

不确定CoreMap的确切类型,但可能Map#values()是您需要的列表。要将其转换为单个字符串,可以使用Java8 Streams API:

代码语言:javascript
复制
list.stream ().map (i -> i.toString ()).collect (Collectors.joining (","));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49405325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档