5
5
from udapi .core .block import Block
6
6
7
7
8
- def eparent (node ):
8
+ def eparents (node ):
9
9
"""
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.
14
11
15
12
: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
18
15
19
16
"""
17
+ # Rule (1): When node.deprel == conj, its effective parents are equal to its parent.
20
18
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 )
22
26
23
- return node . parent
27
+ return final_eparents
24
28
25
29
26
30
def echildren (node ):
@@ -32,35 +36,36 @@ def echildren(node):
32
36
:rtype: list
33
37
34
38
"""
35
- node_parent = eparent (node )
39
+ node_parents = eparents (node )
36
40
echildren_list = [child for child in node .children ]
37
41
38
42
# Rule (A)
39
43
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 :
59
45
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 :
62
59
echildren_list .append (candidate_child )
63
60
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
+
64
69
return echildren_list
65
70
66
71
0 commit comments