在斯坦福大学CoreNLP中强制使用POS标签 [英] Forcing POS tags in Stanford CoreNLP
问题描述
是否可以使用Stanford CoreNLP处理已经带有POS标记的文本?
Is there a way to process an already POS-tagged text using Stanford CoreNLP?
例如,我的句子采用这种格式
For example, I have the sentence in this format
They_PRP are_VBP hunting_VBG dogs_NNS ._.
并且我想通过强制给定POS注释来对引理,ner,parse等进行注释.
and I'd like to annotate with lemma, ner, parse, etc. by forcing the given POS annotation.
更新.我尝试了此代码,但无法正常工作.
Update. I tried this code, but it's not working.
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);
推荐答案
如果您在管道中包含pos
注释器,则肯定会替换POS注释.
The POS annotations will certainly be replaced if you include the pos
annotator in the pipeline.
相反,删除pos
注释器并添加选项-enforceRequirements false
.即使不存在lemma
等依赖的注释器(pos
注释器),这也将允许管道运行.在管道实例化之前添加以下行:
Instead, remove the pos
annotator and add the option -enforceRequirements false
. This will allow the pipeline to run even though an annotator which lemma
, etc. depend on (the pos
annotator) is not present. Add the following line before pipeline instantiation:
props.setProperty("enforceRequirements", "false");
当然,如果您未设置适当的注释而进入该区域,则行为是不确定的,因此请确保与相关注释者所做的注释匹配(
Of course, behavior is undefined if you venture into this area without setting the proper annotations, so make sure you match the annotations made by the relevant annotator (POSTaggerAnnotator
in this case).
这篇关于在斯坦福大学CoreNLP中强制使用POS标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!