使用Core Annotation与GrammaticalStructure / headWordNode

时间:2015-09-27 10:20:37

标签: java nlp stanford-nlp

我使用Stanford CoreNLP来解析句子。我试图用情感和其他语言注释创建词汇化语法。

我正在使用:

获得解析+情绪+ dep
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, 
                  lemma, ner, parse, depparse, sentiment");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

Annotation annotation = pipeline.process(mySentence);

由于我想在语法中使用依赖项,我一直在使用GrammaticalStructureFactory及其newGrammaticalStructure()方法来获取语法结构实例。我注意到了TreeGraphNode'有一个' headWordNode'因此,我同步遍历两棵树,例如

public void BuildSomething(Tree tree, TreeGraphNode gsNode) {
    List<Tree> gsNodes = gsNode.getChildrenAsList();
    List<Tree> constNodes = tree.getChildrenAsList();

    for (int i = 0; i < constNodes.size(); i++) {
        Tree childTree = constNodes.get(i);
        TreeGraphNode childGsNode = (TreeGraphNode) gsNodes.get(i);

        // build for this "sub-tree"            
        BuildSomething(childTree, childGsNode);
    }

    String headWord = gsNode.headWordNode().label().value();
    // do something with the head-word...

    // do other stuff...
}

我用树注释和语法结构root来调用这个函数:

for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
    Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
     GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);

     BuildSomething(tree, gs.root);
}

使用类似上面代码的东西,我注意到我得到的GrammaticalStructure不一定与Tree的结构相匹配(应该吗?)而且,我有时会得到一个&#34;奇怪的&#34;头部选择(选择为头部的确定器似乎不正确): A parse with determiner as the head

我对GrammaticalStructure / headWordNode的使用是否不正确?

P.S。我看过一些代码使用了HeadFinder&#39;和&#39; node.headTerminal(hf,parent)&#39; (here)但我认为另一种方法会更快......所以我不确定我是否可以使用上述方法或必须使用这种方法

0 个答案:

没有答案