带有单词,POS标签,来自CoNLL输入的关系的依赖树

时间:2016-10-09 13:53:55

标签: python nltk syntaxnet dependency-parsing

我尝试使用NLTK DependencyGraph从CoNLL输入获得依赖树。我理解的是,这个类提供tree() method构建tree structure的依赖关系,而relationhead之间没有dependents。树也没有POS标签。还有triple() method为头部,关系和家属提供POS标签。使用三重方法时,当像the red car is behind the blue car这样的句子中重复单词时,我很难得到依赖者,因为单词的索引不在三元组中。在这里,我们为同一个单词car提供了2个不同的节点。

那么如何从CoNLL输入一个依赖树,包括头字,它的标签,关系,子。它也可以是一个类似的数据结构,其中可以找到给定句子的信息(头部词,其标签,关系,孩子)。欢迎提出任何建议。以下是可用于启动的代码。

from nltk.parse import DependencyGraph


conll_data2 = """1   Cathy             Cathy             N     N     eigen|ev|neut                    2   su      _  _
2   zag               zie               V     V     trans|ovt|1of2of3|ev             0   ROOT    _  _
3   hen               hen               Pron  Pron  per|3|mv|datofacc                2   obj1    _  _
4   wild              wild              Adj   Adj   attr|stell|onverv                5   mod     _  _
5   zwaaien           zwaai             N     N     soort|mv|neut                    2   vc      _  _
6   .                 .                 Punc  Punc  punt                             5   punct   _  _

1   the _   DET DT  _   3   det _   _
2   blue    _   ADJ JJ  _   3   amod    _   _
3   car _   NOUN    NN  _   4   nsubj   _   _
4   is  _   VERB    VBZ _   0   ROOT    _   _
5   behind  _   ADP IN  _   4   prep    _   _
6   the _   DET DT  _   8   det _   _
7   red _   ADJ JJ  _   8   amod    _   _
8   car _   NOUN    NN  _   5   pobj    _   _

1   Ze                ze                Pron  Pron  per|3|evofmv|nom                 2   su      _  _
2   had               heb               V     V     trans|ovt|1of2of3|ev             0   ROOT    _  _
3   met               met               Prep  Prep  voor                             8   mod     _  _
4   haar              haar              Pron  Pron  bez|3|ev|neut|attr               5   det     _  _
5   moeder            moeder            N     N     soort|ev|neut                    3   obj1    _  _
6   kunnen            kan               V     V     hulp|ott|1of2of3|mv              2   vc      _  _
7   gaan              ga                V     V     hulp|inf                         6   vc      _  _
8   winkelen          winkel            V     V     intrans|inf                      11  cnj     _  _
9   ,                 ,                 Punc  Punc  komma                            8   punct   _  _
10  zwemmen           zwem              V     V     intrans|inf                      11  cnj     _  _
11  of                of                Conj  Conj  neven                            7   vc      _  _
12  terrassen         terras            N     N     soort|mv|neut                    11  cnj     _  _
13  .                 .                 Punc  Punc  punt                             12  punct   _  _
"""


graphs = [DependencyGraph(entry)
for entry in conll_data2.split('\n\n') if entry]

for graph in graphs:

 #find data structure here to get head word, its tag, relation, children. 

0 个答案:

没有答案