【问题标题】:stanford nlp pos tagging斯坦福 nlp pos 标记
【发布时间】:2015-04-11 17:28:39
【问题描述】:

我正在用这个标注器做我的 POS(词性标注)。但是当我将该部分结合到我的 Maven 项目中时,它不起作用。有没有一种方法可以让我直接使用 stanford 来做 pos 而无需使用单独的标记器?我希望输出与此相同。

 MaxentTagger tagger = new MaxentTagger("taggers/left3words-wsj-0-18.tagger");
        String sample = "Im so happy about my marks";
        String tagged = tagger.tagString(sample);
        System.out.println(tagged);

输出:Im/NNP so/RB 开心/JJ about/IN my/PRP$ 标记/NNS

【问题讨论】:

    标签: java maven nlp stanford-nlp


    【解决方案1】:

    当然,Stanford CoreNLP 可以直接进行标记。以下代码行标记您的示例,并为您提供所需的输出。

    Properties props = new Properties();
    
    props.setProperty("annotators","tokenize, ssplit, pos");
    
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    Annotation annotation = new Annotation("I'm so happy about my marks");
    pipeline.annotate(annotation);
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
        for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
            String word = token.get(CoreAnnotations.TextAnnotation.class);
            // this is the POS tag of the token
            String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
            System.out.println(word + "/" + pos);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多