MCPcopy Create free account
hub / github.com/clips/pattern / Verbs

Class Verbs

pattern/text/es/inflect.py:248–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246]
247
248class Verbs(_Verbs):
249
250 def __init__(self):
251 _Verbs.__init__(self, os.path.join(MODULE, "es-verbs.txt"),
252 language = "es",
253 default = {},
254 format = [
255 0, 1, 2, 3, 4, 5, 6, 8, # indicativo presente
256 34, 35, 36, 37, 38, 39, 24, # indicativo pretérito
257 17, 18, 19, 20, 21, 22, # indicativo imperfecto
258 40, 41, 42, 43, 44, 45, # indicativo futuro
259 46, 47, 48, 49, 50, 51, # indicativo condicional
260 52, 54, # imperativo afirmativo
261 55, 56, 57, 58, 59, 60, # subjuntivo presente
262 67, 68, 69, 70, 71, 72 # subjuntivo imperfecto
263 ])
264
265 def find_lemma(self, verb):
266 """ Returns the base form of the given inflected verb, using a rule-based approach.
267 """
268 # Spanish has 12,000+ verbs, ending in -ar (85%), -er (8%), -ir (7%).
269 # Over 65% of -ar verbs (6500+) have a regular inflection.
270 v = verb.lower()
271 # Probably ends in -ir if preceding vowel in stem is -i.
272 er_ir = lambda b: (len(b) > 2 and b[-2] == "i") and b+"ir" or b+"er"
273 # Probably infinitive if ends in -ar, -er or -ir.
274 if v.endswith(("ar", "er", "ir")):
275 return v
276 # Ruleset for irregular inflections adds 10% accuracy.
277 for a, b in verb_irregular_inflections:
278 if v.endswith(a):
279 return v[:-len(a)] + b
280 # reconozco => reconocer
281 v = v.replace(u"zco", "ce")
282 # reconozcamos => reconocer
283 v = v.replace(u"zca", "ce")
284 # reconozcáis => reconocer
285 v = v.replace(u"zcá", "ce")
286 # saldrár => saler
287 if "ldr" in v:
288 return v[:v.index("ldr")+1] + "er"
289 # compondrán => componer
290 if "ndr" in v:
291 return v[:v.index("ndr")+1] + "er"
292 # Many verbs end in -ar and have a regular inflection:
293 for x in ((
294 u"ando", u"ado", u"ad", # participle
295 u"aré", u"arás", u"ará", u"aremos", u"aréis", u"arán", # future
296 u"aría", u"arías", u"aríamos", u"aríais", u"arían", # conditional
297 u"aba", u"abas", u"ábamos", u"abais", u"aban", # past imperfective
298 u"é", u"aste", u"ó", u"asteis", u"aron", # past perfective
299 u"ara", u"aras", u"áramos", u"arais", u"aran")): # past subjunctive
300 if v.endswith(x):
301 return v[:-len(x)] + "ar"
302 # Many verbs end in -er and have a regular inflection:
303 for x in ((
304 u"iendo", u"ido", u"ed", # participle
305 u"eré", u"erás", u"erá", u"eremos", u"eréis", u"erán", # future

Callers 1

inflect.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…