Skip to content

Commit 48e1bc9

Browse files
author
Vincent Kriz
committed
New method eparents() instead of eparent(). Improved debugging messages.
1 parent de49479 commit 48e1bc9

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

udapi/block/zellig_harris/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def print_triple(node_a, relation_name, node_b, print_lemma=False):
3030
node_b = get_node_representation(node_b, print_lemma=print_lemma)
3131

3232
context = u"%s %s_%s" % (node_a, relation_name, node_b)
33-
print(context)
33+
return context

udapi/block/zellig_harris/configurations.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ def apply_query(self, query_id, node):
7171
logging.info(' - no configurations, but all conditions passed.')
7272

7373
for (node_a, relation_name, node_b) in triples:
74-
print_triple(node_a, relation_name, node_b,
75-
print_lemma=self.print_lemmas)
74+
triple = print_triple(node_a, relation_name, node_b, print_lemma=self.print_lemmas)
75+
76+
if self.verbose:
77+
logging.info(' - %s', triple)
78+
79+
print(triple)
7680

7781
def process_tree(self, tree):
7882
"""

udapi/block/zellig_harris/enhancedeps.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@
55
from udapi.core.block import Block
66

77

8-
def eparent(node):
8+
def eparents(node):
99
"""
10-
Return an effective parent for the given node.
11-
12-
The rule for the effective parent - when the current node A has a deprel 'conj' to its parent B,
13-
return B.parent, otherwise return A.parent.
10+
Return a list of effective parents for the given node.
1411
1512
:param node: An input node.
16-
:return: An effective parent.
17-
:rtype: udapi.core.node.Node
13+
:return: A list of effective parents.
14+
:rtype: list
1815
1916
"""
17+
# Rule (1): When node.deprel == conj, its effective parents are equal to its parent.
2018
if node.deprel == 'conj':
21-
return node.parent.parent
19+
return eparents(node.parent)
20+
21+
# Rule (2): Append the real parent and look for its coordinated nodes.
22+
final_eparents = [node.parent]
23+
for candidate_eparent in node.parent.children:
24+
if candidate_eparent.deprel == 'conj':
25+
final_eparents.append(candidate_eparent)
2226

23-
return node.parent
27+
return final_eparents
2428

2529

2630
def echildren(node):
@@ -32,35 +36,36 @@ def echildren(node):
3236
:rtype: list
3337
3438
"""
35-
node_parent = eparent(node)
39+
node_parents = eparents(node)
3640
echildren_list = [child for child in node.children]
3741

3842
# Rule (A)
3943
target_deprels = ['subj', 'subjpass', 'dobj', 'iobj', 'compl']
40-
for candidate_child in node_parent.children:
41-
# Check if a candidate node C has the target deprel.
42-
if candidate_child.deprel not in target_deprels:
43-
continue
44-
45-
# Check if such deprel is not in the current node children already.
46-
no_such_deprel = True
47-
for current_child in node.children:
48-
if current_child.deprel == candidate_child.deprel:
49-
no_such_deprel = False
50-
break
51-
52-
# If there is no such deprel, we can add a new secondary dependence.
53-
if no_such_deprel:
54-
echildren_list.append(candidate_child)
55-
56-
# Rule (B)
57-
if node.upostag == 'VERB' and (node_parent.upostag == 'AUX' or
58-
node_parent.lemma in ['chtít', 'moci', 'smět', 'mít', 'muset', 'umět']):
44+
for node_parent in node_parents:
5945
for candidate_child in node_parent.children:
60-
# Check if the candidate child is not in the current node children already.
61-
if candidate_child not in echildren_list:
46+
# Check if a candidate node C has the target deprel.
47+
if candidate_child.deprel not in target_deprels:
48+
continue
49+
50+
# Check if such deprel is not in the current node children already.
51+
no_such_deprel = True
52+
for current_child in node.children:
53+
if current_child.deprel == candidate_child.deprel:
54+
no_such_deprel = False
55+
break
56+
57+
# If there is no such deprel, we can add a new secondary dependence.
58+
if no_such_deprel:
6259
echildren_list.append(candidate_child)
6360

61+
# Rule (B)
62+
for node_parent in node_parents:
63+
if node.upostag == 'VERB' and (node_parent.upostag == 'AUX' or node_parent.lemma in ['chtít', 'moci', 'smět', 'mít', 'muset', 'umět']):
64+
for candidate_child in node_parent.children:
65+
# Check if the candidate child is not in the current node children already.
66+
if candidate_child not in echildren_list:
67+
echildren_list.append(candidate_child)
68+
6469
return echildren_list
6570

6671

0 commit comments

Comments
 (0)