1
2
3
4
5
6
7
8
9
10
11
12
13
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
+
-
+
+
-
+
|
"""
# Grammalecte - Compiled regular expressions
Grammalecte - Compiled regular expressions
"""
import re
#### Lemme
Lemma = re.compile("^>(\w[\w-]*)")
Lemma = re.compile(r"^>(\w[\w-]*)")
#### Analyses
Gender = re.compile(":[mfe]")
Number = re.compile(":[spi]")
#### Nom et adjectif
NA = re.compile(":[NA]")
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
+
+
|
NPf = re.compile(":(?:M[12P]|T):f")
NPe = re.compile(":(?:M[12P]|T):e")
#### FONCTIONS
def getLemmaOfMorph (s):
"return lemma in morphology <s>"
return Lemma.search(s).group(1)
def checkAgreement (l1, l2):
"returns True if agreement in gender and number is possible between morphologies <l1> and <l2>"
# check number agreement
if not mbInv(l1) and not mbInv(l2):
if mbSg(l1) and not mbSg(l2):
return False
if mbPl(l1) and not mbPl(l2):
return False
# check gender agreement
|
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
return ":e"
return sGender
def getNumber (lMorph):
"returns number of word (':s', ':p', ':i' or empty string)."
sNumber = ""
for sMorph in lMorph:
m = Number.search(sWord)
m = Number.search(sMorph)
if m:
if not sNumber:
sNumber = m.group(0)
elif sNumber != m.group(0):
return ":i"
return sNumber
# NOTE : isWhat (lMorph) returns True if lMorph contains nothing else than What
# mbWhat (lMorph) returns True if lMorph contains What at least once
## isXXX = it’s certain
def isNom (lMorph):
"returns True if all morphologies are “nom”"
return all(":N" in s for s in lMorph)
def isNomNotAdj (lMorph):
"returns True if all morphologies are “nom”, but not “adjectif”"
return all(NnotA.search(s) for s in lMorph)
def isAdj (lMorph):
"returns True if all morphologies are “adjectif”"
return all(":A" in s for s in lMorph)
def isNomAdj (lMorph):
"returns True if all morphologies are “nom” or “adjectif”"
return all(NA.search(s) for s in lMorph)
def isNomVconj (lMorph):
"returns True if all morphologies are “nom” or “verbe conjugué”"
return all(NVconj.search(s) for s in lMorph)
def isInv (lMorph):
"returns True if all morphologies are “invariable”"
return all(":i" in s for s in lMorph)
def isSg (lMorph):
"returns True if all morphologies are “singulier”"
return all(":s" in s for s in lMorph)
def isPl (lMorph):
"returns True if all morphologies are “pluriel”"
return all(":p" in s for s in lMorph)
def isEpi (lMorph):
"returns True if all morphologies are “épicène”"
return all(":e" in s for s in lMorph)
def isMas (lMorph):
"returns True if all morphologies are “masculin”"
return all(":m" in s for s in lMorph)
def isFem (lMorph):
"returns True if all morphologies are “féminin”"
return all(":f" in s for s in lMorph)
## mbXXX = MAYBE XXX
def mbNom (lMorph):
"returns True if one morphology is “nom”"
return any(":N" in s for s in lMorph)
def mbAdj (lMorph):
"returns True if one morphology is “adjectif”"
return any(":A" in s for s in lMorph)
def mbAdjNb (lMorph):
"returns True if one morphology is “adjectif” or “nombre”"
return any(AD.search(s) for s in lMorph)
def mbNomAdj (lMorph):
"returns True if one morphology is “nom” or “adjectif”"
return any(NA.search(s) for s in lMorph)
def mbNomNotAdj (lMorph):
"returns True if one morphology is “nom”, but not “adjectif”"
b = False
for s in lMorph:
if ":A" in s:
return False
if ":N" in s:
b = True
return b
def mbPpasNomNotAdj (lMorph):
"returns True if one morphology is “nom” or “participe passé”, but not “adjectif”"
return any(PNnotA.search(s) for s in lMorph)
def mbVconj (lMorph):
"returns True if one morphology is “nom” or “verbe conjugué”"
return any(Vconj.search(s) for s in lMorph)
def mbVconj123 (lMorph):
"returns True if one morphology is “nom” or “verbe conjugué” (but not “avoir” or “être”)"
return any(Vconj123.search(s) for s in lMorph)
def mbMG (lMorph):
"returns True if one morphology is “mot grammatical”"
return any(":G" in s for s in lMorph)
def mbInv (lMorph):
"returns True if one morphology is “invariable”"
return any(":i" in s for s in lMorph)
def mbSg (lMorph):
"returns True if one morphology is “singulier”"
return any(":s" in s for s in lMorph)
def mbPl (lMorph):
"returns True if one morphology is “pluriel”"
return any(":p" in s for s in lMorph)
def mbEpi (lMorph):
"returns True if one morphology is “épicène”"
return any(":e" in s for s in lMorph)
def mbMas (lMorph):
"returns True if one morphology is “masculin”"
return any(":m" in s for s in lMorph)
def mbFem (lMorph):
"returns True if one morphology is “féminin”"
return any(":f" in s for s in lMorph)
def mbNpr (lMorph):
"returns True if one morphology is “nom propre” or “titre de civilité”"
return any(NP.search(s) for s in lMorph)
def mbNprMasNotFem (lMorph):
"returns True if one morphology is “nom propre masculin” but not “féminin”"
if any(NPf.search(s) for s in lMorph):
return False
return any(NPm.search(s) for s in lMorph)
|