def __init__(self, syllable_counter, exception_triples, base_is_er_est, erable, not_erable): self.syllable_counter = syllable_counter self.exception_bases = set(map(lambda ss: ss[0], exception_triples)) self.exception_degree_base2ss = defaultdict(list) self.exception_s2degrees_bases = defaultdict(list) degrees = [ ComparativeDegree.BASE, ComparativeDegree.COMP, ComparativeDegree.SUPER ] for triple in exception_triples: base = triple[0] for degree, word in zip(degrees, triple): self.exception_degree_base2ss[(degree, base)].append(word) self.exception_s2degrees_bases[word].append((degree, base)) self.base_is_er_est = set(base_is_er_est) self.erable = set(erable) self.not_erable = set(not_erable) self.degree_polarity2adverb = { (ComparativeDegree.BASE, ComparativePolarity.POS): None, (ComparativeDegree.COMP, ComparativePolarity.POS): 'more', (ComparativeDegree.SUPER, ComparativePolarity.POS): 'most', (ComparativeDegree.BASE, ComparativePolarity.NEG): 'not', (ComparativeDegree.COMP, ComparativePolarity.NEG): 'less', (ComparativeDegree.SUPER, ComparativePolarity.NEG): 'least', } self.adverb2degree_polarity = v2k_from_k2v(self.degree_polarity2adverb) self.repeat_last_chr_re = re.compile('.*[^aeiou][aeiou][^aeiouyw]$')
def __init__(self, syllable_counter, exception_triples, base_is_er_est, erable, not_erable): self.syllable_counter = syllable_counter self.exception_bases = set(map(lambda ss: ss[0], exception_triples)) self.exception_degree_base2ss = defaultdict(list) self.exception_s2degrees_bases = defaultdict(list) degrees = [ComparativeDegree.BASE, ComparativeDegree.COMP, ComparativeDegree.SUPER] for triple in exception_triples: base = triple[0] for degree, word in zip(degrees, triple): self.exception_degree_base2ss[(degree, base)].append(word) self.exception_s2degrees_bases[word].append((degree, base)) self.base_is_er_est = set(base_is_er_est) self.erable = set(erable) self.not_erable = set(not_erable) self.degree_polarity2adverb = { (ComparativeDegree.BASE, ComparativePolarity.POS): None, (ComparativeDegree.COMP, ComparativePolarity.POS): 'more', (ComparativeDegree.SUPER, ComparativePolarity.POS): 'most', (ComparativeDegree.BASE, ComparativePolarity.NEG): 'not', (ComparativeDegree.COMP, ComparativePolarity.NEG): 'less', (ComparativeDegree.SUPER, ComparativePolarity.NEG): 'least', } self.adverb2degree_polarity = v2k_from_k2v(self.degree_polarity2adverb) self.repeat_last_chr_re = re.compile('.*[^aeiou][aeiou][^aeiouyw]$')
def __init__(self, inflection_mgr): self.inflection_mgr = inflection_mgr self.ppcase2pc = { PersonalPronounCase.SUBJECT: PersonalColumn.SUBJ, PersonalPronounCase.OBJECT: PersonalColumn.OBJ, PersonalPronounCase.REFLEXIVE: PersonalColumn.REFL, } self.pc2ppcase = v2k_from_k2v(self.ppcase2pc) self.tables = PersonalKnowledge()
def __init__(self, cat2sings, rules, nonsuffixable_sing2plur, capitalized_sing2plur): sings_set = set() for r in rules: if r.category_only: for sing in cat2sings[r.category_only]: assert sing.endswith(r.sing_suffix) assert sing not in sings_set sings_set.add(sing) sing2x = {} sing2x_pedantic_ok = {} plur2xx = defaultdict(list) plur2xx_pedantic_ok = defaultdict(list) for i, rule in enumerate(rules): for s in singular_suffixes_from_rule(rule, cat2sings): assert s not in sing2x_pedantic_ok sing2x_pedantic_ok[s] = i if not rule.is_pedantic: sing2x[s] = i for s in plural_suffixes_from_rule(rule, cat2sings): plur2xx_pedantic_ok[s].append(i) if not rule.is_pedantic: plur2xx[s].append(i) self.sing2x = SuffixFanoutMap(sing2x, None, min) self.sing2x_pedantic_ok = SuffixFanoutMap(sing2x_pedantic_ok, None, min) self.plur2xx = SuffixFanoutMap(plur2xx, [], min) self.plur2xx_pedantic_ok = SuffixFanoutMap(plur2xx_pedantic_ok, [], min) self.rules = rules self.nonsuffixable_sing2plur = nonsuffixable_sing2plur self.nonsuffixable_plur2sing = v2k_from_k2v(nonsuffixable_sing2plur) self.capitalized_sing2plur = capitalized_sing2plur self.capitalized_plur2sing = v2k_from_k2v(capitalized_sing2plur)
def __init__(self): self.section2s = { DaySection.MORNING: 'morning', DaySection.AFTERNOON: 'afternoon', DaySection.EVENING: 'evening', DaySection.NIGHT: 'night', } self.offset2section2ss = { -1: { DaySection.MORNING: 'yesterday morning'.split(), DaySection.AFTERNOON: 'yesterday afternoon'.split(), DaySection.EVENING: 'last evening'.split(), DaySection.NIGHT: 'last night'.split(), }, 0: { DaySection.MORNING: 'this morning'.split(), DaySection.AFTERNOON: 'this afternoon'.split(), DaySection.EVENING: 'this evening'.split(), DaySection.NIGHT: ['tonight'], }, 1: { DaySection.MORNING: 'tomorrow morning'.split(), DaySection.AFTERNOON: 'tomorrow afternoon'.split(), DaySection.EVENING: 'tomorrow evening'.split(), DaySection.NIGHT: 'tomorrow night'.split(), }, } self.s2offset_section = { (None, 'tonight'): (0, DaySection.NIGHT), } self.s2offset = { 'yesterday': -1, 'last': -1, 'this': 0, 'tomorrow': 1, 'next': 1, } self.s2section = v2k_from_k2v(self.section2s)
from panoptes.etc.dicts import v2k_from_k2v from panoptes.etc.enum import enum Conjunction = enum('Conjunction = ALL_OF ONE_OF') CONJUNCTION2STR = { Conjunction.ALL_OF: 'and', Conjunction.ONE_OF: 'or', } STR2CONJUNCTION = v2k_from_k2v(CONJUNCTION2STR)