Skip to content

Commit d63c6f8

Browse files
committed
Extended the ElQue block. Now it can also harmonize the annotation.
1 parent bdc7547 commit d63c6f8

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

udapi/block/ud/ca/elque.py

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99

1010
class ElQue(Block):
1111

12+
def __init__(self, fix=False, **kwargs):
13+
"""
14+
Default: Print the annotation patterns but do not fix anything.
15+
fix=1: Do not print the patterns but fix them.
16+
"""
17+
super().__init__(**kwargs)
18+
self.fix = fix
19+
1220
def process_node(self, node):
1321
# We take 'que' as the central node of the construction.
1422
if node.lemma == 'que' and node.upos == 'PRON' and node.parent.ord > node.ord:
@@ -19,35 +27,53 @@ def process_node(self, node):
1927
# Check the lemma of the determiner. The form may vary for gender and number.
2028
if que.prev_node and que.prev_node.lemma == 'el':
2129
el = que.prev_node
22-
stanford = []
2330
adp = None
2431
if el.prev_node and el.prev_node.upos == 'ADP':
2532
adp = el.prev_node
2633
if adp.udeprel == 'fixed':
2734
adp = adp.parent
28-
parentstr = 'OTHER'
29-
if adp.parent == el:
30-
parentstr = 'el'
31-
elif adp.parent == que:
32-
parentstr = 'que'
33-
elif adp.parent == verb:
34-
parentstr = 'VERB'
35-
stanford.append(adp.deprel + '(' + parentstr + ', ADP)')
36-
if el.parent == adp:
37-
parentstr = 'ADP'
38-
elif el.parent == que:
39-
parentstr = 'que'
40-
elif el.parent == verb:
41-
parentstr = 'VERB'
42-
else:
43-
parentstr = 'OTHER'
44-
stanford.append(el.deprel + '(' + parentstr + ', el)')
45-
stanford.append(que.deprel + '(VERB, que)')
46-
if verb.parent == adp:
47-
parentstr = 'ADP'
48-
elif verb.parent == el:
49-
parentstr = 'el'
35+
if self.fix:
36+
self.fix_pattern(adp, el, que, verb)
5037
else:
51-
parentstr = 'OTHER'
52-
stanford.append(verb.deprel + '(' + parentstr + ', VERB)')
53-
print('; '.join(stanford))
38+
self.print_pattern(adp, el, que, verb)
39+
40+
def print_pattern(self, adp, el, que, verb):
41+
stanford = []
42+
if adp:
43+
if adp.parent == el:
44+
parentstr = 'el'
45+
elif adp.parent == que:
46+
parentstr = 'que'
47+
elif adp.parent == verb:
48+
parentstr = 'VERB'
49+
else:
50+
parentstr = 'OTHER'
51+
stanford.append(adp.deprel + '(' + parentstr + ', ADP)')
52+
if el.parent == adp:
53+
parentstr = 'ADP'
54+
elif el.parent == que:
55+
parentstr = 'que'
56+
elif el.parent == verb:
57+
parentstr = 'VERB'
58+
else:
59+
parentstr = 'OTHER'
60+
stanford.append(el.deprel + '(' + parentstr + ', el)')
61+
# We found the verb as the parent of 'que', so we do not need to check the parent of 'que' now.
62+
stanford.append(que.deprel + '(VERB, que)')
63+
if verb.parent == adp:
64+
parentstr = 'ADP'
65+
elif verb.parent == el:
66+
parentstr = 'el'
67+
else:
68+
parentstr = 'OTHER'
69+
stanford.append(verb.deprel + '(' + parentstr + ', VERB)')
70+
print('; '.join(stanford))
71+
72+
def fix_pattern(self, adp, el, que, verb):
73+
if adp:
74+
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'

0 commit comments

Comments
 (0)