Skip to content

Commit 1bccb8b

Browse files
committed
"El que" re-attach if subject.
1 parent 3f57dce commit 1bccb8b

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

udapi/block/ud/ca/elque.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,34 @@ def print_pattern(self, adp, el, que, verb):
7272
def fix_pattern(self, adp, el, que, verb):
7373
if adp:
7474
if adp.parent == que or adp.parent == verb:
75-
adp.parent = el
76-
adp.deprel = 'case'
77-
if len(adp.deps) == 1:
78-
adp.deps[0]['parent'] = el
79-
adp.deps[0]['deprel'] = 'case'
75+
attach(adp, el, 'case')
8076
if el.parent == que:
8177
###!!! Just a temporary change. In the end it will be attached elsewhere.
78+
attach(el, verb)
8279
el.parent = verb
8380
if len(el.deps) == 1:
8481
el.deps[0]['parent'] = verb
82+
if verb.parent != adp and verb.parent != el and verb.parent != que:
83+
if re.match(r'^[nc]subj$', verb.udeprel):
84+
attach(el, verb.parent, 'nsubj')
85+
attach(verb, el, 'acl:relcl')
86+
# If anything before 'el' depends on the verb ('cc', 'mark', 'punct' etc.),
87+
# re-attach it to 'el'.
88+
for c in verb.children:
89+
if c.ord < el.ord and re.match(r'^(cc|mark|case|punct)$', c.udeprel):
90+
attach(c, el)
91+
92+
def attach(node, parent, deprel=None):
93+
"""
94+
Attach a node to a new parent with a new deprel in the basic tree. In
95+
addition, if there are enhanced dependencies and there is just one incoming
96+
enhanced relation (this is the case in AnCora), this relation will be
97+
modified accordingly.
98+
"""
99+
node.parent = parent
100+
if deprel:
101+
node.deprel = deprel
102+
if len(node.deps) == 1:
103+
node.deps[0]['parent'] = parent
104+
if deprel:
105+
node.deps[0]['deprel'] = deprel

0 commit comments

Comments
 (0)