예제 #1
0
def add_lexrules(choices):
    '''
    '''
    for pc in morphotactics.all_position_classes(choices):
        pc_key = pc.full_key
        idx = pc['lrt'].next_iter_num() if 'lrt' in pc else 1
        for lrt in pc.get('lrt', []):
            overt = [
                f for f in lrt.get('feat', []) if f['name'] == 'overt-arg'
            ]
            dropped = [
                f for f in lrt.get('feat', []) if f['name'] == 'dropped-arg'
            ]
            need_lex_rule = need_no_drop_rule('obj-mark', choices) or \
                need_no_drop_rule('subj-mark', choices)
            # overt-arg morphs should be the index of the next available
            if overt:
                feat = overt[0]
                # convert overt-arg features to OPT
                if feat['value'] == 'not-permitted':
                    feat['name'] = 'OPT'
                    feat['value'] = 'plus'
                # only create a lexical rule if necessary
                if need_lex_rule:
                    key = pc.full_key + '_lrt' + str(idx)
                    name = get_name(pc) + '-no-drop'
                    choices[key + '_name'] = name
                    choices[key + '_feat1_name'] = 'OPT'
                    choices[key + '_feat1_value'] = 'minus'
                    choices[key + '_feat1_head'] = feat['head']
                    choices[key + '_lri1_inflecting'] = 'no'
                    choices[key + '_lri1_orth'] = ''
            # dropped-arg morphs should be the index of the next available + 1
            if dropped:
                feat = dropped[0]
                # convert dropped-arg features to OPT
                if feat['value'] == 'not-permitted':
                    feat['name'] = 'OPT'
                    feat['value'] = 'minus'
                # only create a lexical rule if necessary
                if need_lex_rule:
                    key = pc.full_key + '_lrt' + str(idx + 1)
                    name = get_name(pc) + '-drop'
                    choices[key + '_name'] = name
                    choices[key + '_feat1_name'] = 'OPT'
                    choices[key + '_feat1_value'] = 'plus'
                    choices[key + '_feat1_head'] = feat['head']
                    choices[key + '_lri1_inflecting'] = 'no'
                    choices[key + '_lri1_orth'] = ''
예제 #2
0
def get_lt_name(key, choices):
    if key in LEXICAL_SUPERTYPES:
        # lexical supertype-- pull out of lexical_supertypes, remove '-lex'
        return LEXICAL_SUPERTYPES[key].rsplit('-lex', 1)[0]
    else:
        # defined lextype, name may or may not be defined
        name = get_name(choices[key])
        lex_st = LEXICAL_SUPERTYPES[key.strip('1234567890')]
        return '-'.join([name, lex_st.rsplit('-lex', 1)[0]])
예제 #3
0
def validate(ch, vr):
    if not ch.get(COMPS):
        pass
    matches = {}
    wo = ch.get(constants.WORD_ORDER)
    for v in ch.get('verb'):
        if get_name(v) == 'clausal':
            vr.err(v.full_key + '_name',
                   "The word 'clausal' is reserved; please use another name.")
    for ccs in ch.get(COMPS):
        if wo in ['free', 'v2']:
            vr.warn(ccs.full_key + '_' + SAME, WO_WARNING)
        matches[ccs.full_key] = None
        for vb in ch.get('verb'):
            val = vb['valence']
            if val.endswith(ccs.full_key):
                matches[ccs.full_key] = vb.full_key
                for f in vb['feat']:
                    if f['name'] == 'case' and f['head'] == 'obj' and not is_nominalized_complement(ccs):
                        vr.err(f.full_key + '_name', 'You cannot specify case on the object of '
                               'a clausal verb unless the complementation strategy involves nominalization.')
        for m in matches:
            if not matches[m]:
                vr.err(ccs.full_key + '_' + SAME,
                       'You did not enter any verbs in the Lexicon to go with this complementation strategy.')
        if not (ccs[EXTRA] or ccs[SAME]):
            vr.err(ccs.full_key + '_' + SAME, SAME_OR_EXTRA)
        if ccs[EXTRA]:
            if wo in ['free', 'v2', 'svo', 'vso']:
                vr.err(ccs.full_key + '_' + EXTRA, EXTRA_VO)
        for f in ccs['feat']:
            if f['name'] in ['evidential', 'negation', 'OPT', 'tense']:
                vr.err(f.full_key + '_name',
                       'Supported features: aspect, mood, form, nominalization, custom syntactic.')
            feat = find_in_other_features(f['name'], ch)
            if feat:
                if feat['type'] and feat['type'] == 'index':
                    vr.err(f.full_key + '_name',
                           'Custom semantic features are not supported here.')
        if ccs['cformvalue'] and not ccs[COMP] == 'oblig':
            vr.err(ccs.full_key + '_' + COMP,
                   'FORM on complementizers is only supported with obligatory complementizers.')
        if ccs['complementizer'] and not (ccs[COMP] == 'oblig' or ccs[COMP] == 'opt'):
            vr.err(ccs.full_key + '_' + COMP,
                   'Please choose whether the complementizer is obligatory or optional.')
예제 #4
0
def add_lexrules(ch):
    # only need to add rules for mixed_case
    if not ch.has_mixed_case():
        return
    for pc in ch['noun-pc']:
        # TJT 2014-09-08: changing to set comprehension for speed
        #feature_names = {feat['name'] for lrt in pc['lrt'] for feat in lrt['feat']}
        feature_names = set()
        for lrt in pc['lrt']:
            for feat in lrt['feat']:
                feature_names.add(feat['name'])
        if 'case' in feature_names:
            for c in case_names(ch):
                if ch.has_adp_case(c[0]):
                    idx = ch[pc.full_key + '_lrt'].next_iter_num()
                    lrt_key = pc.full_key + '_lrt' + str(idx)
                    ch[lrt_key + '_name'] = get_name(pc) + '-synth-' + c[0]
                    ch[lrt_key + '_feat1_name'] = 'case'
                    ch[lrt_key + '_feat1_value'] = c[0]
                    ch[lrt_key + '_lri1_inflecting'] = 'no'
                    ch[lrt_key + '_lri1_orth'] = ''
예제 #5
0
def add_lexrules(ch):
    # only need to add rules for mixed_case
    if not ch.has_mixed_case():
        return
    for pc in ch['noun-pc']:
        # TJT 2014-09-08: changing to set comprehension for speed
        feature_names = set()
        for lrt in pc['lrt']:
            for feat in lrt['feat']:
                feature_names.add(feat['name'])
        if 'case' in feature_names:
            # create a set of cases that can be optionally marked adpositionally
            # create a new type in the case hierarchy that is a supertype of all these types
            # make one non inflecting synth rule that sets case to be this new supertype
            adp_cases = set()
            cases = case_names(ch)
            for c in cases:
                if ch.has_adp_case(c[0]):
                    adp_cases.add(canon_to_abbr(c[0], cases))

            # if there were adpositional cases, add the appropriate non-inflecting rule
            if len(adp_cases) > 0:
                # find the supertype that covers all the adposition cases
                if len(adp_cases) == 1:
                    adp_case_name = list(adp_cases)[0]
                else:
                    for case_supertype in ch['hierarchies']['case'].coverage:
                        if ch['hierarchies']['case'].coverage[
                                case_supertype] == adp_cases:
                            adp_case_name = case_supertype

                idx = ch[pc.full_key + '_lrt'].next_iter_num()
                lrt_key = pc.full_key + '_lrt' + str(idx)
                ch[lrt_key + '_name'] = get_name(pc) + '-synth-adp'
                ch[lrt_key + '_feat1_name'] = 'case'
                ch[lrt_key + '_feat1_value'] = adp_case_name
                ch[lrt_key + '_lri1_inflecting'] = 'no'
                ch[lrt_key + '_lri1_orth'] = ''
예제 #6
0
def add_lexrules(choices):
    features = choices.features()
    scale_size = len(choices['scale'])
    equal = choices.get('scale-equal')

    for lexprefix in ALL_LEX_TYPES:
        for lex in choices[lexprefix]:
            p = lex.full_key
            n = get_name(lex)
            if p in ALL_LEX_TYPES:  # What does this do and when would it execute?
                continue
            l = lexprefix
            if l == 'det':
                l = 'determiner'

            # If the lexical type is a direct-inverse verb, later rules
            # should use its mandatory rules as input rather than the
            # lexical type.  Create those rules here and put their supertype
            # in the root_dict.
            if lexprefix == 'verb' and lex.get('valence').endswith('dirinv'):
                #direc_geom = [f[2] for f in features if f[0] == 'direction'][0]
                idx = 1
                if 'verb-pc' in choices:
                    idx = choices['verb-pc'].next_iter_num()
                pc_key = 'verb-pc' + str(idx)
                choices[pc_key + '_name'] = n + '-dir-inv'
                choices[pc_key + '_inputs'] = lex.full_key
                # We also need to reassign PCs that specify lex as an input.
                reassign_inputs(choices, lex.full_key, pc_key)
                # The order doesn't really matter for lrules, so just put something
                choices[pc_key + '_order'] = 'suffix'
                # make the lexical type require the pc
                c_idx = 1
                if 'require' in lex:
                    c_idx = lex['require'].next_iter_num()
                c_key = lex.full_key + '_require' + str(c_idx)
                choices[c_key + '_others'] = pc_key

                # regarding the calculating of the keys, consider scale_size is 2:
                #   i = 0 or 1, so direc_lrt_key = (0*2)+0+1 = 1, or (1*2)+1+1 = 4
                #   j = 1 or 2, so lrt_key = (0*2)+0+1+1 = 2, (0*2)+0+2+1 = 3, or
                #                            (1*2)+1+1+1 = 5, (1*2)+1+2+1 = 6
                for i, direc in enumerate(['dir', 'inv']):
                    direc_lrt_key = pc_key + '_lrt' + str((i * scale_size) +
                                                          i + 1)
                    choices[direc_lrt_key + '_name'] = '-'.join([n, direc])
                    choices[direc_lrt_key + '_feat1_name'] = 'direction'
                    choices[direc_lrt_key + '_feat1_value'] = direc
                    for j in range(1, scale_size + 1):
                        if j == scale_size and not (equal == 'direct'
                                                    and direc == 'dir'):
                            break
                        lrt_key = pc_key + '_lrt' + str((i * scale_size) + i +
                                                        j + 1)
                        subj_type, comps_type = get_subj_comps_types(
                            j, scale_size, direc, equal)
                        choices[lrt_key + '_name'] = '-'.join(
                            [n, direc, str(j)])
                        choices[lrt_key + '_supertypes'] = direc_lrt_key
                        choices[lrt_key + '_feat1_name'] = 'dirinv-type'
                        choices[lrt_key + '_feat1_head'] = 'subj'
                        choices[lrt_key + '_feat1_value'] = subj_type
                        choices[lrt_key + '_feat2_name'] = 'dirinv-type'
                        choices[lrt_key + '_feat2_head'] = 'obj'
                        choices[lrt_key + '_feat2_value'] = comps_type
                        # add an empty lexical rule instance
                        choices[lrt_key + '_lri1_inflecting'] = 'no'
                        choices[lrt_key + '_lri1_orth'] = ''
예제 #7
0
def det_id(item):
  """Return the identifier for a determiner lexical item."""
  return get_name(item) + '-determiner-lex'
예제 #8
0
def cop_id(item):
  """Return the identifier for an copula lexical item."""
  return get_name(item) + '-cop-lex'
예제 #9
0
def adj_id(item):
  """Return the identifier for an adjective lexical item."""
  return get_name(item) + '-adj-lex'
예제 #10
0
def noun_id(item):
  """Return the identifier for a noun lexical item."""
  return get_name(item) + '-noun-lex'
예제 #11
0
def verb_id(item):
  """Return the identifier for a verb lexical item."""
  return get_name(item) + '-verb-lex'
예제 #12
0
def find_clausalverb_typename(ch, cs):
    for v in ch.get(constants.VERB):
        if v.get(constants.VALENCE).endswith(cs.full_key):
            name = get_name(
                v) + '-verb-lex' if not get_name(v).endswith('-verb-lex') else get_name(v)
            return name