在斯坦福CoreNLP强制POS标签

时间:2015-04-08 15:28:21

标签: stanford-nlp part-of-speech

有没有办法使用Stanford CoreNLP处理已经过POS标记的文本?

例如,我有这种格式的句子

They_PRP are_VBP hunting_VBG dogs_NNS ._.

我想通过强制给定的POS注释来引用引理,ner,parse等。

更新。我尝试了这段代码,但它无效。

Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma"); 

StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
String sentText = "They_PRP are_VBP hunting_VBG dogs_NNS ._.";
List<CoreLabel> sentence = new ArrayList<>();

String[] parts = sentText.split("\\s");
for (String p : parts) {
    String[] split = p.split("_");
    CoreLabel clToken = new CoreLabel();
    clToken.setValue(split[0]);
    clToken.setWord(split[0]);
    clToken.setOriginalText(split[0]);
    clToken.set(CoreAnnotations.PartOfSpeechAnnotation.class, split[1]);
    sentence.add(clToken);
}
Annotation s = new Annotation(sentText);
s.set(CoreAnnotations.TokensAnnotation.class, sentence);

Annotation document = new Annotation(s);
pipeline.annotate(document);

1 个答案:

答案 0 :(得分:0)

如果在管道中包含pos注释器,肯定会替换POS注释。

而是删除pos注释器并添加选项-enforceRequirements false。即使lemma等依赖于(pos注释器)的注释器不存在,这也将允许管道运行。在管道实例化之前添加以下行:

props.setProperty("enforceRequirements", "false");

当然,如果您在没有设置正确注释的情况下冒险进入此区域,行为是不确定的,因此请确保您匹配相关注释器(在这种情况下为POSTaggerAnnotator)所做的注释。