【问题标题】:Stanford nlp java斯坦福nlp java
【发布时间】:2014-04-26 02:52:18
【问题描述】:

如何从树中提取这些标签? http://s9.postimg.org/uvbjudgi7/Immagine.png

我是否应该为每个标记提取句法类别,你能帮我吗?

我试过了:

Tree tree = sentence.get(TreeAnnotation.class);
tree.pennPrint();

for(int i = 0; i < tree.children().length; i++) {
   for(Tree r : tree.children()[i].localTrees()){
       System.out.println(r.nodeString());
    }
}

但我不知道如何提取标记的句法类别!

【问题讨论】:

    标签: java nlp stanford-nlp


    【解决方案1】:

    我认为你需要一个递归函数。

    public void output(Tree tree) {
        System.out.println(tree.nodeString());
        for(int i = 0; i < tree.numChildren(); i++) {
            output(tree.children()[i]);
        }
    }
    

    并且可以通过判断子节点是否为叶子来提取token的标签,例如:

    if(tree.numChildren() == 1 && tree.children()[0].isLeaf()) {
        System.out.println(tree.nodeString()+" "+tree.children()[0].nodeString());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 2010-12-23
      • 2015-04-30
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多