【问题标题】:Manual tagging of Words using Stanford CorNLP使用 Stanford CorNLP 手动标记单词
【发布时间】:2015-02-25 16:19:43
【问题描述】:

我有一个资源,我确切地知道单词的类型。我必须对它们进行词形还原,但为了获得正确的结果,我必须手动标记它们。我找不到任何用于手动标记单词的代码。我正在使用以下代码,但它返回错误的结果。即我期望“绘画”的“绘画”的“绘画”。

*//...........lemmatization starts........................

Properties props = new Properties(); 
props.put("annotators", "tokenize, ssplit, pos, lemma"); 
StanfordCoreNLP pipeline = new StanfordCoreNLP(props, false);
String text = "painting"; 
Annotation document = pipeline.process(text);  

List<edu.stanford.nlp.util.CoreMap> sentences = document.get(SentencesAnnotation.class);

for(edu.stanford.nlp.util.CoreMap sentence: sentences) 

{    
    for(CoreLabel token: sentence.get(TokensAnnotation.class))
    {       
        String word = token.get(TextAnnotation.class);      
        String lemma = token.get(LemmaAnnotation.class); 
        System.out.println("lemmatized version :" + lemma);
    }
}

//...........lemmatization ends.........................*

我必须对单词而不是句子运行 lemmatizer,其中 pos 标记将自动完成。所以我会首先手动标记单词,然后找到它们的引理。一些示例代码的帮助或对某些网站的引用会很有帮助。

【问题讨论】:

    标签: java-7 stanford-nlp lemmatization


    【解决方案1】:

    如果您事先知道 POS 标签,您可以通过以下方式获取词条:

    Properties props = new Properties(); 
    props.put("annotators", "tokenize, ssplit"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props, false);
    String text = "painting";
    
    Morphology morphology = new Morphology();
    
    Annotation document = pipeline.process(text);  
    
    List<edu.stanford.nlp.util.CoreMap> sentences = document.get(SentencesAnnotation.class);
    
    for(edu.stanford.nlp.util.CoreMap sentence: sentences) {
    
      for(CoreLabel token: sentence.get(TokensAnnotation.class)) {       
        String word = token.get(TextAnnotation.class);
        String tag = ... //get the tag for the current word from somewhere, e.g. an array
        String lemma = morphology.lemma(word, tag);
        System.out.println("lemmatized version :" + lemma);
      }
    }
    

    如果您只想获取单个单词的引理,您甚至不必运行 CoreNLP 来进行分词和分句,因此您只需调用引理函数,如下所示:

    String tag = "VBG";      
    String word = "painting";
    Morphology morphology = new Morphology();
    String lemma = morphology.lemma(word, tag);
    

    【讨论】:

    • 正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多