-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.py
166 lines (136 loc) · 5.14 KB
/
rules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from tree import *
from functools import partial
def findkar(kar, const):
"""
recursively looks for
karaka kar in constituent const
"""
if getkar(const) == kar:
return const
for child in const[1:]:
f = findkar(kar, child)
if f != None:
return f
return None
def findpsp(const):
"""
looks for karak chihna
in dependents of head
only (non-recursive)
"""
for child in const[1:]:
if getkar(child) == 'lwg__psp':
return child[0].spel
return None
def mahakarak(replacement, const):
"""
Generalisation of replacement
functions
"""
const[0].spel = replacement
for child in const[1:]:
mahakarak('', child)
def k1(const):
replacement_possibilities = ["कौन", "किसने"]
if findpsp(const) == 'ने':
mahakarak(replacement_possibilities[1], const)
else:
mahakarak(replacement_possibilities[0], const)
return True
def k1s(const):
replacement_possibilities = ["कौन", "कैसा", "कैसे", "कैसी"]
if const != [] and const[0].spel != "":
if const[0].pos == 'JJ': # for adjectives
repl = "कैस" + const[0].spel[-1]
if repl in replacement_possibilities: # if the gender can be determined from the adjective,
mahakarak(repl, const) # use it to find which possibility to use
else:
mahakarak("कैसा", const) # else use masc कैसा by default
else: # for nouns
mahakarak(replacement_possibilities[0], const)
return True
def k2(const):
replacement_possibilities = ["किसको", "क्या"]
if findpsp(const) == 'को':
mahakarak(replacement_possibilities[0], const)
else:
mahakarak(replacement_possibilities[1], const)
return True
def k2p(const):
replacement_possibilities = ["कहाँ", "किधर"]
# note: "कहाँ" and "किधर" can be considered interchangable
mahakarak(replacement_possibilities[0], const)
return True
def k3(const):
replacement_possibilities = ["किससे", "किसके द्वारा"]
if findpsp(const) == 'के':
mahakarak(replacement_possibilities[1], const)
else:
mahakarak(replacement_possibilities[0], const)
return True
def rt(const):
replacement_possibilities = ["क्यों", "किसके लिए"]
mahakarak(replacement_possibilities[0], const)
return True
def rh(const):
replacement_possibilities = ["क्यों", "किसलिए"]
mahakarak(replacement_possibilities[0], const)
return True
def k5(const):
replacement_possibilities = ["किससे", "कहाँ से", "किधर से"]
if const[0].pos == 'NNP':
mahakarak(replacement_possibilities[1], const) # for place names
else:
mahakarak(replacement_possibilities[0], const) # otherwise
return True
def r6(const):
replacement_possibilities = ["किसका", "किसके", "किसकी"]
# here the ambiguity is resolved by gender
# and / or number and / or honorific
suff = findpsp(const)
if suff != None:
mahakarak('किस'+suff, const) # Affix the karak chihn if it is there
elif const != [] and const[0].spel != "":
gen = const[0].spel[-1] # else determine gender from last matra
mahakarak('किसक'+gen, const)
return True
def k7p(const):
replacement_possibilities = ["कहाँ", "किधर", "किसमें", "किसपर", "किसपे"]
suff = findpsp(const)
if suff != None:
mahakarak('किस'+suff, const) # Affix the karak chihn if it is there
else:
mahakarak(replacement_possibilities[0],const) # else use कहाँ
return True
def k7t(const):
replacement_possibilities = ["कब", "किस दिन", "कौनसे दिन"]
# the last two are interchangable
# the first is a broader case of the other two
mahakarak(replacement_possibilities[0], const)
return True
def main(_):
return None
# paper.extended()
def pof(const):
replacement_possibilities = ["क्या"]
mahakarak(replacement_possibilities[0], const)
return True
def nmod__adj(const):
replacement_possibilities = ["कैसा", "कैसे", "कैसी"]
# if the gender can be determined from the adjective,
# use it to find which possibility to use
# else use masc कैसा by default
if const != [] and const[0].spel != "":
if const[0].pos == 'JJ':
repl = "कैस" + const[0].spel[-1]
if repl in replacement_possibilities:
mahakarak(repl, const)
else:
mahakarak("कैसा", const)
elif const[0].pos == 'QC' and const[0].spel != 'एक':
mahakarak("कितने", const)
elif const[0].pos == 'DEM':
mahakarak("कौनसा", const)
else:
return None
return True