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

Class Verbs

pattern/text/en/inflect.py:628–723  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626#### VERB CONJUGATION ##############################################################################
627
628class Verbs(_Verbs):
629
630 def __init__(self):
631 _Verbs.__init__(self, os.path.join(MODULE, "en-verbs.txt"),
632 language = "en",
633 format = [0, 1, 2, 3, 7, 8, 17, 18, 19, 23, 25, 24, 16, 9, 10, 11, 15, 33, 26, 27, 28, 32],
634 default = {
635 1: 0, 2: 0, 3: 0, 7: 0, # present singular => infinitive ("I walk")
636 4: 7, 5: 7, 6: 7, # present plural
637 17: 25, 18: 25, 19: 25, 23: 25, # past singular
638 20: 23, 21: 23, 22: 23, # past plural
639 9: 16, 10: 16, 11: 16, 15: 16, # present singular negated
640 12: 15, 13: 15, 14: 15, # present plural negated
641 26: 33, 27: 33, 28: 33, # past singular negated
642 29: 32, 30: 32, 31: 32, 32: 33 # past plural negated
643 })
644
645 def find_lemma(self, verb):
646 """ Returns the base form of the given inflected verb, using a rule-based approach.
647 This is problematic if a verb ending in -e is given in the past tense or gerund.
648 """
649 v = verb.lower()
650 b = False
651 if v in ("'m", "'re", "'s", "n't"):
652 return "be"
653 if v in ("'d", "'ll"):
654 return "will"
655 if v in ("'ve"):
656 return "have"
657 if v.endswith("s"):
658 if v.endswith("ies") and len(v) > 3 and v[-4] not in VOWELS:
659 return v[:-3]+"y" # complies => comply
660 if v.endswith(("sses", "shes", "ches", "xes")):
661 return v[:-2] # kisses => kiss
662 return v[:-1]
663 if v.endswith("ied") and re_vowel.search(v[:-3]) is not None:
664 return v[:-3]+"y" # envied => envy
665 if v.endswith("ing") and re_vowel.search(v[:-3]) is not None:
666 v = v[:-3]; b=True; # chopping => chopp
667 if v.endswith("ed") and re_vowel.search(v[:-2]) is not None:
668 v = v[:-2]; b=True; # danced => danc
669 if b:
670 # Doubled consonant after short vowel: chopp => chop.
671 if len(v) > 3 and v[-1] == v[-2] and v[-3] in VOWELS and v[-4] not in VOWELS and not v.endswith("ss"):
672 return v[:-1]
673 if v.endswith(("ick", "ack")):
674 return v[:-1] # panick => panic
675 # Guess common cases where the base form ends in -e:
676 if v.endswith(("v", "z", "c", "i")):
677 return v+"e" # danc => dance
678 if v.endswith("g") and v.endswith(("dg", "lg", "ng", "rg")):
679 return v+"e" # indulg => indulge
680 if v.endswith(("b", "d", "g", "k", "l", "m", "r", "s", "t")) \
681 and len(v) > 2 and v[-2] in VOWELS and not v[-3] in VOWELS \
682 and not v.endswith("er"):
683 return v+"e" # generat => generate
684 if v.endswith("n") and v.endswith(("an", "in")) and not v.endswith(("ain", "oin", "oan")):
685 return v+"e" # imagin => imagine

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…