插入和删除转换规则到类型依赖

insert and delete transformation rules to typed dependency

我使用 stanford coreNLP 提取了被动语态句子的所有类型依赖关系。现在我想让它成为主动语态。为此,我必须删除并插入一些新规则。例如,如果我们拿这样的句子 “猫被狗追了。”那么类型化的依赖表示是: det(cat-2,The-1) nsubjpass(chased-4, cat-2) 辅助通行证(追逐 4,被追逐 3) det(dog-7, the-6) 特工(追逐 4,狗 7) punct(chased-4, .-8)

将上述内容转换为主动语态的转换规则需要三个删除和两个插入: 1、匹配删除: (a) nsubjpass(??X0, ??X1) (b) auxpass(??X0, ??X2) (c) 代理(??X0, ??X3)

  1. 插入: (a) nsubj(??X0, ??X3) (b) dobj(??X0, ??X1)

在这里 ??X0(追逐),??X1(猫), ??X2(被) 和 ??X3(狗)

现在我的问题是如何将这些规则实施到我的 java 代码中。

所以你要改句子:

"The cat was chased by the dog."

进入:

"The dog chased the cat."

?

如果我正在处理这个问题,我的第一直觉是使用规则生成新的句子字符串,然后用该文本重建一个新的 Annotation 对象。

所以我不会搞乱编辑图表或其他注释,我只会创建我想要的新字符串,然后重建依赖关系图。

所以你可以想象有这样的规则:

Pattern: X was VERB by Y --> Y <VERB> X
Example: "The cat was chased by the dog." --> "The dog chased the cat."

并遵循这个算法:

  1. 检测依赖图中的模式或使用正则表达式(在本例中 "was VERB by")

  2. 创建 X 和 Y。这样您就可以按照图表添加额外的词,例如行列式。因此,在这种情况下,您将按照行列式边将 "cat" 扩展为 "The cat" 并将 "dog" 扩展为 "the dog".

  3. 输出新修改的字符串:X Y,全部小写。在这种情况下输出 "the cat chased the dog"

  4. 然后将新句子的第一个单词大写,并在末尾添加标点符号。导致 "The cat chased the dog."

  5. 然后我将这个新字符串输入注释并重新运行管道以获得新的依赖关系图。

    Annotation newSentenceAnnotation = new Annotation("The dog chased the cat.");
    pipeline.annotate(newSentenceAnnotation);
    

以下是使用语义图的一些链接:

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

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

如果您查看我们最近发布的这个演示,有一个名为 DependencyMatchFinder.java 的 class,它演示了从注释访问语义图:

https://github.com/stanfordnlp/nlp-meetup-demo/blob/master/DependencyMatchFinder.java