【问题标题】:How can I obtain NP and VP subtrees in Stanford parser using a Spanish model如何使用西班牙模型在斯坦福解析器中获取 NP 和 VP 子树
【发布时间】:2017-04-05 07:36:07
【问题描述】:

实际上,我使用 Java 从西班牙语文本中提取三元组。我需要提取NP-VP-NP 形式的那些三元组。我也在使用 Stanford Parser CoreNLP v 3.7.0 和西班牙模型 v 3.7.0。接下来我的问题是,有没有办法从西班牙语模型中的句子中提取 NP 子树和 VP 子树?我意识到西班牙语解析器树形式与英语形式不同。

例如:

(ROOT (sentence (sn (spec (da0000 El)) (grup.nom (nc0s000 reino))) (grup.verb (vmm0000 canta) (sadv (spec (rg muy)) (grup.adv (rg bien))) (fp .)))

【问题讨论】:

    标签: java stanford-nlp


    【解决方案1】:

    你应该使用主发行版来确保你拥有一切并下载西班牙模型

    (可在此处获取:http://stanfordnlp.github.io/CoreNLP/download.html

    package edu.stanford.nlp.examples;
    
    import edu.stanford.nlp.ling.*;
    import edu.stanford.nlp.pipeline.*;
    import edu.stanford.nlp.trees.*;
    import edu.stanford.nlp.trees.tregex.*;
    import edu.stanford.nlp.util.*;
    
    import java.util.*;
    
    
    public class TregexExample {
    
      public static void main(String[] args) {
        // set up pipeline
        Properties props = StringUtils.argsToProperties("-props", "StanfordCoreNLP-spanish.properties");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        // Spanish example
        Annotation spanishDoc = new Annotation("...insert Spanish text...");
        pipeline.annotate(spanishDoc);
        // get first sentence
        CoreMap firstSentence = spanishDoc.get(CoreAnnotations.SentencesAnnotation.class).get(0);
        Tree firstSentenceTree = firstSentence.get(TreeCoreAnnotations.TreeAnnotation.class);
        // use Tregex to match
        String nounPhrasePattern = "/grup\\.nom/";
        TregexPattern nounPhraseTregexPattern = TregexPattern.compile(nounPhrasePattern);
        TregexMatcher nounPhraseTregexMatcher = nounPhraseTregexPattern.matcher(firstSentenceTree);
        while (nounPhraseTregexMatcher.find()) {
          nounPhraseTregexMatcher.getMatch().pennPrint();
        }
      }
    }
    

    【讨论】:

    • 谢谢。我应该对更改 nounPhrasePattern 的动词组做同样的事情吗?
    • 是的,只需将其更改为“/grup\\.verb/”。
    • 完美。非常感谢。
    猜你喜欢
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多