def init_person_hierarchy(ch, hierarchies): hier = TDLHierarchy('person') for p in ch.persons(): for st in p[1].split(';'): hier.add(p[0], st) if not hier.is_empty(): hierarchies[hier.name] = hier
def init_pernum_hierarchy(ch, hierarchies): hier = TDLHierarchy('pernum') for pn in ch.pernums(): for st in pn[1].split(';'): hier.add(pn[0], st) if not hier.is_empty(): hierarchies[hier.name] = hier
def init_gender_hierarchy(ch, hierarchies): hier = TDLHierarchy('gender') for g in ch.genders(): for st in g[1].split(';'): hier.add(g[0], st) if not hier.is_empty(): hierarchies[hier.name] = hier
def init_number_hierarchy(ch, hierarchies): hier = TDLHierarchy('number') for n in ch.numbers(): for st in n[1].split(';'): hier.add(n[0], st) if not hier.is_empty(): hierarchies[hier.name] = hier
def init_form_hierarchy(ch, hierarchies): """ Create the FORM hierarchies associated with the user's choices about verb forms Adds FORM finite and nonfinte values if there are auxiliaries or if user specified """ hier = TDLHierarchy('form') if ch.get('has-aux') == 'yes' or 'noaux-fin-nf' in ch: hier.add('nonfinite', 'form') hier.add('finite', 'form') for p in ('nf', 'fin'): for subform in ch.get(p + '-subform',[]): if p == 'nf': sup = 'nonfinite' elif p == 'fin': sup = 'finite' sub = subform.get('name') hier.add(sub, sup) if not hier.is_empty(): hierarchies[hier.name] = hier
def init_situation_hierarchy(ch, hierarchies): hier = TDLHierarchy('situation') for situation in ch.get('situation', []): name = situation.get('name') for supertype in situation.get('supertype', []): supername = supertype.get('name') hier.add(name, supername) if not hier.is_empty(): hierarchies[hier.name] = hier
def init_form_hierarchy(ch, hierarchies): """ Create the FORM hierarchies associated with the user's choices about verb forms """ hier = TDLHierarchy('form') if ('form-fin-nf' in ch): hier.add('nonfinite', 'form') hier.add('finite', 'form') for subform in ch.get('form-subtype', []): hier.add(subform.get('name'), subform.get('supertype')) if not hier.is_empty(): hierarchies[hier.name] = hier
def init_other_hierarchies(ch, mylang, hierarchies): for feature in ch.get('feature', []): feat = feature.get('name', '') type = feature.get('type', '') hier = TDLHierarchy(feat, type) if feature.get('new', '') == 'yes': for value in feature.get('value', []): val = value.get('name') for supertype in value.get('supertype', []): stype = supertype.get('name') hier.add(val, stype) else: if type == 'head': mylang.add('head :+ [ ' + feat.upper() + ' ' + feature.get('existing', '') + ' ].', section='addenda') else: mylang.add('png :+ [ ' + feat.upper() + ' ' + feature.get('existing', '') + ' ].', section='addenda') if not hier.is_empty(): hierarchies[hier.name] = hier
def init_aspect_hierarchy(ch, hierarchies): hier = TDLHierarchy('aspect') for aspect in ch.get('aspect', []): name = aspect.get('name') for supertype in aspect.get('supertype', []): supername = supertype.get('name') hier.add(name, supername) if not hier.is_empty(): hierarchies[hier.name] = hier elif ch.get('perimper'): for asp in ('perfective', 'imperfective'): name = asp supername = 'aspect' hier.add(name, supername) hierarchies[hier.name] = hier
def init_mood_hierarchy(ch, hierarchies): hier = TDLHierarchy('mood') for mood in ch.get('mood', []): name = mood.get('name') for supertype in mood.get('supertype', []): supername = supertype.get('name') hier.add(name, supername) if not hier.is_empty(): hierarchies[hier.name] = hier elif ch.get('subjind'): for md in ('subjunctive', 'indicative'): name = md supername = 'mood' hier.add(name, supername) hierarchies[hier.name] = hier
def init_case_hierarchy(ch, hierarchies): cm = ch.get('case-marking') cases = case_names(ch) hier = TDLHierarchy('case') # EKN 2018-03-02 If possessive strategy implemented, add an intermediate # level to case hierarchy that contrasts with a 'false' case type that is # assigned to possessors. Keeps possessors from being args of verbs, etc. poss = True if ch.get('poss-strat') or ch.get('poss-pron') else False # For most case patterns, just make a flat hierarchy. For fluid-s, # split-n and split-v, however, a more articulated hierarchy is required. if cm in ['nom-acc', 'erg-abs', 'tripartite', 'split-s', 'focus']: # LTX 2022-04-22: real-case should be only defined once if poss: hier.add('real-case', 'case', 'intermediate case type for all real cases') for c in cases: if poss: hier.add(c[2], 'real-case', c[1]) else: hier.add(c[2], 'case', c[1]) elif cm in ['fluid-s']: if poss: hier.add('real-case', 'case', 'intermediate case type for all real cases') abbr = canon_to_abbr('a_case+o_case', cases) for c in cases: if c[0] in ['a_case', 'o_case']: hier.add(c[2], abbr, c[1]) else: if poss: hier.add(c[2], 'real-case', c[1]) else: hier.add(c[2], 'case', c[1]) elif cm in ['split-n', 'split-v']: if poss: hier.add('real-case', 'case', 'intermediate case type for all real cases') nom_a = canon_to_abbr('nom', cases) acc_a = canon_to_abbr('acc', cases) erg_a = canon_to_abbr('erg', cases) abs_a = canon_to_abbr('abs', cases) if cm == 'split-v': for c in cases: hier.add(c[2], 'case', c[1]) else: # 'split-n': if poss: hier.add('a_case', 'real-case', 'transitive agent') hier.add('s_case', 'real-case', 'intransitive subject') hier.add('o_case', 'real-case', 'transitive patient') else: hier.add('a_case', 'case', 'transitive agent') hier.add('s_case', 'case', 'intransitive subject') hier.add('o_case', 'case', 'transitive patient') for c in cases: if c[2] == erg_a: hier.add(c[2], 'a_case', c[1]) elif c[2] == nom_a: hier.add(c[2], 'a_case', c[1]) hier.add(c[2], 's_case', c[1]) elif c[2] == abs_a: hier.add(c[2], 's_case', c[1]) hier.add(c[2], 'o_case', c[1]) elif c[2] == acc_a: hier.add(c[2], 'o_case', c[1]) else: hier.add(c[2], 'case', c[1]) if not hier.is_empty(): hierarchies[hier.name] = hier
def write_dir_inv_types(choices, mylang, hierarchies): mylang.add('verb :+ [ DIRECTION direction ].', section='addenda') hier = TDLHierarchy('direction') hier.add('dir', 'direction') hier.add('inv', 'direction') hier.save(mylang) if choices.has_SCARGS(): mylang.add('word-or-lexrule :+ [ SC-ARGS list ].', section='addenda') mylang.add('lex-rule :+ [ SC-ARGS #1, DTR.SC-ARGS #1 ].', section='addenda') cases = case.case_names(choices) features = choices.features() # Figure out which features are involved in the hierarchy names = [] # feature names for scale in choices.get('scale', []): for feat in scale.get('feat', []): names.append(feat.get('name', '')) # Now pass through the scale, creating the direct-inverse hierarchy # pairwise mylang.set_section('dirinv') mylang.add_literal(';;; Direct-inverse scale') supertype = 'dir-inv-scale' mylang.add(supertype + ' := canonical-synsem.') scale_len = len(choices.get('scale', '')) for i in range(1, scale_len): values = {} # for each feature, a set of values # get the features on the first scale entry in this range for feat in choices.get('scale')[i].get('feat', []): name = feat.get('name', '') if name not in values: values[name] = set() values[name].add(feat.get('value')) # create the left type in the pair type = 'dir-inv-' + str(i) mylang.add(type + ' := ' + supertype + '.') for n in values: vset = values[n] if n == 'case': new_vset = set() for v in vset: new_vset.add(canon_to_abbr(v, cases)) vset = new_vset geom = '' for f in features: if f[0] == n: geom = f[2] value = hierarchies[n].get_type_covering(vset) if value != n: # don't bother if it doesn't constrain anything mylang.add(type + ' := [ ' + geom + ' ' + value + ' ].') # rest of the scale values = {} for scale in choices.get('scale')[i:]: for feat in scale.get('feat', []): name = feat.get('name', '') if name not in values: values[name] = set() values[name].add(feat.get('value', '')) # create the right type in the pair type = 'dir-inv-non-' + str(i) mylang.add(type + ' := ' + supertype + '.') for n in values: vset = values[n] if n == 'case': new_vset = set() for v in vset: new_vset.add(canon_to_abbr(v, cases)) vset = new_vset geom = '' for f in features: if f[0] == n: geom = f[2] value = hierarchies[n].get_type_covering(vset) if value != n: # don't bother if it doesn't constrain anything mylang.add(type + ' := [ ' + geom + ' ' + value + ' ].') supertype = type # generate subtypes to patch the direct-inverse/unexpressed type conflict mylang.add_literal( ';;; Direct-inverse/unexpressed subtypes for compatibility with argument optionality' ) # add subtypes for each left-branching leaf on the scale for i in range(1, scale_len): type = 'dir-inv-' + str(i) subtype = type + '-unexpressed' mylang.add(subtype + ' := ' + type + ' & unexpressed.') # now add the last, right-branching leaf type = 'dir-inv-non-' + str(scale_len - 1) subtype = type + '-unexpressed' mylang.add(subtype + ' := ' + type + ' & unexpressed.')
def init_tense_hierarchy(ch, hierarchies): hier = TDLHierarchy('tense') tdefn = ch.get('tense-definition') if tdefn: if tdefn == 'choose': ppflist = [] for ten in ('nonfuture', 'nonpast', 'past', 'present', 'future'): if ten in ch: if ten not in ppflist: hier.add(ten, 'tense') for subtype in ch.get(ten + '-subtype', []): st = subtype.get('name', '') hier.add(st, ten) if ten == 'nonfuture': for moreten in ('past', 'present'): if moreten in ch: hier.add(moreten, ten) ppflist.append(moreten) if ten == 'nonpast': for moreten in ('present', 'future'): if moreten in ch: hier.add(moreten, ten) ppflist.append(moreten) elif tdefn == 'build': for tense in ch.get('tense', []): name = tense.get('name') for supertype in tense.get('supertype', []): supername = supertype.get('name') hier.add(name, supername) if not hier.is_empty(): hierarchies[hier.name] = hier
def init_case_hierarchy(ch, hierarchies): cm = ch.get('case-marking') cases = case_names(ch) hier = TDLHierarchy('case') # For most case patterns, just make a flat hierarchy. For fluid-s, # split-n and split-v, however, a more articulated hierarchy is required. if cm in ['nom-acc', 'erg-abs', 'tripartite', 'split-s', 'focus']: for c in cases: hier.add(c[2], 'case', c[1]) elif cm in ['fluid-s']: abbr = canon_to_abbr('a_case+o_case', cases) for c in cases: if c[0] in ['a_case', 'o_case']: hier.add(c[2], abbr, c[1]) else: hier.add(c[2], 'case', c[1]) elif cm in ['split-n', 'split-v']: nom_a = canon_to_abbr('nom', cases) acc_a = canon_to_abbr('acc', cases) erg_a = canon_to_abbr('erg', cases) abs_a = canon_to_abbr('abs', cases) if cm == 'split-v': for c in cases: hier.add(c[2], 'case', c[1]) else: # 'split-n': hier.add('a_case', 'case', 'transitive agent') hier.add('s_case', 'case', 'intransitive subject') hier.add('o_case', 'case', 'transitive patient') for c in cases: if c[2] == erg_a: hier.add(c[2], 'a_case', c[1]) elif c[2] == nom_a: hier.add(c[2], 'a_case', c[1]) hier.add(c[2], 's_case', c[1]) elif c[2] == abs_a: hier.add(c[2], 's_case', c[1]) hier.add(c[2], 'o_case', c[1]) elif c[2] == acc_a: hier.add(c[2], 'o_case', c[1]) else: hier.add(c[2], 'case', c[1]) if not hier.is_empty(): hierarchies[hier.name] = hier