【问题标题】:Why do I get UnsupportedOperationException with Stanford CoreNLP为什么斯坦福 CoreNLP 会出现 UnsupportedOperationException
【发布时间】:2017-09-04 08:16:28
【问题描述】:

我想从Stanford CoreNLP 中的Tree 中找到每个短语(成分)的中心词,但是当我尝试将tree.Parent() 用于任何constituents 时,我得到UnsupportedOperationException。我做错了什么?

这是我的代码:

List<Tree> allConstituents = new ArrayList<>();
    private Tree parseTree;

  List<CoreMap> sentences = LoadAndParse(language, filetype, modelPath, text);

            for (CoreMap sentence : sentences) {
                Tree parse = sentence.get(TreeAnnotation.class);
                allConstituents = parseTree.subTreeList();

            for (int i = 0; i < allConstituents.size(); i++) {
                    Tree constituentTree = allConstituents.get(i);
                    HeadFinder headFinder = new SemanticHeadFinder();
                    String head = constituentTree.headTerminal(headFinder, constituentTree.parent());

                }
              }

这是我的一个例子:

Your tasks are challenging:

我得到 13 作为 parseTree.subTreeList() 的大小,但对于所有这些,我在 constituentTree.parent() 方法上得到 UnsupportedOperationException。谁能帮我获取树中“所有”成分的语义头的正确方法是什么?

【问题讨论】:

  • 问题似乎是没有为该类型实现父方法。有没有关于斯坦福 CoreNLP 的文档?

标签: java stanford-nlp parse-tree


【解决方案1】:

我不确定这是否真的是一个适用于所有人的答案,但在我的情况下它很有帮助:

使用包含整个句子的主要Tree作为所有成分的第二输入;那就是:

                String head = constituentTree.headTerminal(headFinder, parseTree);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多