CoreNLP : 提供 pos 标签

CoreNLP : provide pos tags

我的文本已经标记化、句子拆分和词性标记。

我想使用 CoreNLP 另外 注释引理 (lemma)、命名实体 (ner)、连续性和依赖性解析 (parse), 和共同引用 (dcoref).

是否有命令行选项和选项文件规范的组合可以从命令行实现这一点?

根据 ,我可以通过将此添加到我的属性文件来要求解析器将空格视为定界标记,将换行符视为定界句子:

tokenize.whitespace = true
ssplit.eolonly = true

这很好用,所以剩下的就是向 CoreNLP 指定我也想提供 POS 标签。

单独使用 Stanford Parser 时,seems to be possible 让它使用现有的 POS 标签,但将该语法复制到 CoreNLP 的调用似乎不起作用。例如,这不起作用:

java -cp *:./* -Xmx2g edu.stanford.nlp.pipeline.StanfordCoreNLP -props my-properties-file -outputFormat xml -outputDirectory my-output-dir -sentences newline -tokenized -tagSeparator / -tokenizerFactory edu.stanford.nlp.process.WhitespaceTokenizer -tokenizerMethod newCoreLabelTokenizerFactory -file my-annotated-text.txt

虽然 涵盖了编程调用,但我从命令行调用 CoreNLP 作为更大系统的一部分,所以我真的想问一下是否可以通过命令行选项实现这一点。

我认为命令行选项不可能做到这一点。

如果您愿意,可以制作自定义注释器并将其包含在您的管道中,您可以采用这种方式。

下面是一些示例代码:

package edu.stanford.nlp.pipeline;

import edu.stanford.nlp.util.logging.Redwood;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.util.concurrent.MulticoreWrapper;
import edu.stanford.nlp.util.concurrent.ThreadsafeProcessor;

import java.util.*;

public class ProvidedPOSTaggerAnnotator {

  public String tagSeparator;

  public ProvidedPOSTaggerAnnotator(String annotatorName, Properties props) {
    tagSeparator = props.getProperty(annotatorName + ".tagSeparator", "_");
  }

  public void annotate(Annotation annotation) {

    for (CoreLabel token : annotation.get(CoreAnnotations.TokensAnnotation.class)) {
      int tagSeparatorSplitLength = token.word().split(tagSeparator).length;
      String posTag = token.word().split(tagSeparator)[tagSeparatorSplitLength-1];
      String[] wordParts = Arrays.copyOfRange(token.word().split(tagSeparator), 0, tagSeparatorSplitLength-1);
      String tokenString = String.join(tagSeparator, wordParts);
      // set the word with the POS tag removed
      token.set(CoreAnnotations.TextAnnotation.class, tokenString);
      // set the POS
      token.set(CoreAnnotations.PartOfSpeechAnnotation.class, posTag);
    }
  }
}

如果您为您的令牌提供由“_”分隔的 POS 令牌,这应该有效。您可以使用 forcedpos.tagSeparator 属性.

更改它

如果设置 customAnnotator.forcedpos = edu.stanford.nlp.pipeline.ProvidedPOSTaggerAnnotator

到属性文件,在你的CLASSPATH中包含上面的class,然后在你的注释列表中"tokenize"之后包含"forcedpos",你应该可以传递您自己的 pos 标签。

我可能会进一步清理它,并将其实际包含在未来的版本中供人们使用!

我还没有时间实际测试这段代码,如果您尝试并发现错误请告诉我,我会修复它!