"Merged" 附属国和选区树

"Merged" dependency and constituency tree

我正在进行一项研究,其中我使用 CoreNlp 来解析句子,使用各种可用的注释器(主要是选区和情绪)。

我现在正在尝试创建一个 "merged" 树,其中包括选区和依赖信息,我将从中提取语法(可以考虑 PCFG)。

我正在尝试找到类似于图片中左侧树的位置:

(图片来自Relational-Realizational Parsing (Tsarfaty and Sima’an, 2008)

是否有一些 "easy" 方法可以使用提供的解析器输出(在代码中)来达到类似的效果?

或者,您是否知道基于斯坦福 NLP 库的任何实现?

GrammaticalStructure在这里有帮助吗?为每个节点制作一个 GS 并在每个选区节点读取它的 typedDependencies() 在这里有意义吗?

这里是一些代码的草图,用于处理选区和依赖项解析。

Properties props = new Properties();
props.setProperty("annotators","tokenize, ssplit, pos, lemma, parse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
String sampleDoc = "This is the first sentence.  This is the second one.";
Annotation annotation = new Annotation(sampleDoc);
pipeline.annotate(annotation);
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
  Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
  SemanticGraph deps = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
}

对于您的项目,您将需要研究这两个 classes:

http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/trees/Tree.html

http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/semgraph/SemanticGraph.html

树 class 代表选区解析,语义图 class 代表依赖解析。

为创建合并的选区和依赖关系树所需的代码创建了一个"snippet"(相当长的一个),该代码沿着上面建议的路线 - 遍历两棵树。

Merge Constituency and Dependency

高层进程:

  1. 使用parser/pipeline

  2. 获取选区树
  3. 获取树的语法结构并从中输入依赖关系(注意 - 保留标点符号)

  4. 将类型化的依赖转换为依赖树

  5. 根据匹配的节点覆盖跨度合并依赖树和选区树。

代码(类):

  • DependencySpan - 表示一个跨度和覆盖它的节点(用于匹配跨度)

  • DependencyTreeNode - 依赖树中的一个节点,它保存对核心标签的引用(反过来,有一个用于获取跨度的相关词索引)

  • MergedNode - 合并选区+依赖节点。

  • MergeConstituencyAndDependency - 合并树的实际代码 - 按照上述算法工作。包括主要(测试入口点)。

我不是 100% 确定的一件事是为什么需要 "sentiment" 注释器 - 如果没有它创建语法结构会引发错误。

免责声明 - 我不精通斯坦福 NLP 库及其所有选项。该代码大致基于我在网上找到的其他示例,可能有更好的方法来完成此任务。