Parsing CoreNLP:提供pos标签

Parsing CoreNLP:提供pos标签,parsing,tokenize,pos-tagger,stanford-nlp,Parsing,Tokenize,Pos Tagger,Stanford Nlp,我有已经标记化、句子分割和位置标记的文本 我想使用CoreNLP对引理(lemma)、命名实体(ner)、连续性和依赖性解析(parse)以及coreference(dcoref)进行注释 是否有命令行选项和选项文件规范的组合使这从命令行成为可能 根据,我可以通过将以下内容添加到我的属性文件中,要求解析器将空白视为分隔标记,将换行视为分隔句子: tokenize.whitespace = true ssplit.eolonly = true 这很好,所以剩下的就是向CoreNLP指定我也想提供

我有已经标记化、句子分割和位置标记的文本

我想使用CoreNLP对引理(
lemma
)、命名实体(
ner
)、连续性和依赖性解析(
parse
)以及coreference(
dcoref
)进行注释

是否有命令行选项和选项文件规范的组合使这从命令行成为可能

根据,我可以通过将以下内容添加到我的属性文件中,要求解析器将空白视为分隔标记,将换行视为分隔句子:

tokenize.whitespace = true
ssplit.eolonly = true
这很好,所以剩下的就是向CoreNLP指定我也想提供POS标签

单独使用Stanford解析器时,需要让它使用现有的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代币,并且以“\u1”分隔,则此功能应该有效。您可以使用forcedpos.tagSeparator属性对其进行更改

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

对于属性文件,在类路径中包含上述类,然后在“标记化”之后的注释器列表中包含“forcedpos”,您应该能够传入自己的pos标记

我可能会把它清理得更干净一些,并在将来的版本中为人们提供它

我还没来得及实际测试这段代码,如果您尝试一下并发现错误,请让我知道,我会修复它