Example #1
0
def customize_cops(mylang, ch, lexicon, hierarchies, trigger):

  if ch.get('cop',False):
    # Add PRD
    mylang.add('head :+ [ PRD bool ].', section='addenda')

    # Add copulas
    lexicon.add_literal(';;; Copulas')

    # Core definition
    mylang.add('''%s := basic-verb-lex-super & trans-first-arg-raising-lex-item-2 &
          [ SYNSEM.LOCAL [ CAT.VAL [ SUBJ < [ LOCAL [ CONT.HOOK.INDEX #xarg,
                                                      CAT [ VAL [ SPR < >,
                                                                  COMPS < > ],
                                                            HEAD noun ] ] ] >,
                                     COMPS < [ LOCAL.CAT [ HEAD.PRD +,
                                                           VAL [ SUBJ < >,
                                                                 COMPS < > ] ] ] >,
                                     SPR < >,
                                     SPEC < > ],
                           CONT.HOOK.XARG #xarg ] ].''' % LEXICAL_SUPERTYPES['cop'])

    # only works for adj right now, change in future
    comment = '''Copula type taking adjectival complements.\nNeed to define more for additional complement types.'''
    mylang.add('''adj-comp-copula-verb-lex := %s &
                  [ SYNSEM.LOCAL.CAT.VAL.COMPS.FIRST.LOCAL.CAT.HEAD adj ].''' % LEXICAL_SUPERTYPES['cop'],
               comment=comment)

    for cop in ch.get('cop', []):
      ctype = cop_id(cop)

      ## Calculate supertypes
      stypes = cop.get('supertypes').split(', ')
      stype_def = ''
      if '' in stypes: # Found root
        stype_def = 'adj-comp-copula-verb-lex & ' # Change for new complement types
      else:
        stype_names = [cop_id(ch[st]) for st in filter(None,stypes)]
        stype_def = " & ".join(stype_names) or ""
        if stype_def: stype_def += " & "

      features.customize_feature_values(mylang, ch, hierarchies, cop, ctype, 'cop')

      # Add the lexical types
      mylang.add(ctype + ' := ' + stype_def + '.')

      for stem in cop.get('stem'):
        orthstr = orth_encode(stem.get('orth'))
        name = stem.get('name')
        typedef = TDLencode(name) + ' := ' + ctype + ' & \
                        [ STEM < "' + orthstr + '" > ].'
        lexicon.add(typedef)
Example #2
0
def customize_users_auxtype(auxtypename, aux, ch, mylang, hierarchies):
  """
  A utility that declares the userstype as subtype of supertype and
  calls the functions that specify feature values on the type.
  Called by customize_auxiliaries.
  userstype = userstypename in customize_auxiliaries
  supertype = userstypename in customize_auxiliaries
  """
  auxcomp = ch.get('aux-comp')
  userstypename = get_users_type_name(aux)
  features.customize_feature_values(mylang, ch, hierarchies, aux, userstypename, 'aux')
  features.customize_feature_values(mylang, ch, hierarchies, aux, userstypename, 'auxcomplement')
  mylang.add(userstypename + ':= ' + auxtypename + '.')
Example #3
0
def customize_determiners(mylang, ch, lexicon, hierarchies):

  # Lexical type for determiners, if the language has any:
  if ch.get('has-dets') == 'yes':
    comment = \
      ';;; Determiners\n' + \
      ';;; SPEC is non-empty, and already specified by basic-determiner-lex.'
    mylang.add_literal(comment)
    
    # LLD 2016-04-04 changed basic-zero-arg to norm-zero-arg
    typedef = \
      'determiner-lex := basic-determiner-lex & norm-zero-arg & \
          [ SYNSEM.LOCAL.CAT.VAL [ SPR < >, \
                                   COMPS < >, \
                                   SUBJ < > ]].'
    mylang.add(typedef)

    mylang.add('determiner-lex := non-mod-lex-item.')

  # Determiners
  if 'det' in ch:
    lexicon.add_literal(';;; Determiners')

  for det in ch.get('det',[]):
    stype = 'determiner-lex'
    dtype = det_id(det)

    mylang.add(dtype + ' := ' + stype + '.')

    has_inforstr_feat = False
    for feat in det.get('feat', []):
      if feat['name'] == "information-structure meaning":
        has_inforstr_feat = True
        mylang.add(dtype + ' := infostr-marking-determiner-lex.')
        break
    if not has_inforstr_feat:
      mylang.add(dtype + ' := no-icons-lex-item.')

    features.customize_feature_values(mylang, ch, hierarchies, det, dtype, 'det')

    for stem in det.get('stem',[]):
      orthstr = orth_encode(stem.get('orth'))
      pred = stem.get('pred')
      name = stem.get('name')
      typedef = \
        TDLencode(name) + ' := ' + dtype + ' & \
                    [ STEM < "' + orthstr + '" >, \
                      SYNSEM.LKEYS.KEYREL.PRED "' + pred + '" ].'
      lexicon.add(typedef)
Example #4
0
def customize_users_auxtype(auxtypename, aux, ch, mylang, hierarchies):
    """
    A utility that declares the userstype as subtype of supertype and
    calls the functions that specify feature values on the type.
    Called by customize_auxiliaries.
    userstype = userstypename in customize_auxiliaries
    supertype = userstypename in customize_auxiliaries
    """
    auxcomp = ch.get('aux-comp')
    userstypename = get_users_type_name(aux)
    features.customize_feature_values(mylang, ch, hierarchies, aux,
                                      userstypename, 'aux')
    features.customize_feature_values(mylang, ch, hierarchies, aux,
                                      userstypename, 'auxcomplement')
    mylang.add(userstypename + ':= ' + auxtypename + '.')
    if ch.get('word-order') == 'v2' and ch.get(
            'subord-word-order') == 'vfinal':
        mylang.add(
            userstypename + ':=' + auxtypename +
            '& [ SYNSEM.LOCAL.CAT.VAL.COMPS.FIRST.LOCAL.CAT.MC na-or-- ].')
Example #5
0
def customize_arg_op(mylang, ch, rules, hierarchies):
    """ Create the lexical types, lexical, rules and phrase structure
        rules to allow argument dropping"""

    if 'scale' in ch and (ch.get('subj-drop') or ch.get('obj-drop')):
        mylang.add('dir-inv-scale := unexpressed-reg.')

    mylang.set_section('verblex')
    # Adding potential fix for integrating argument optionality and direct-inverse

    # Figure out the constraints on subject dropping and write the
    # appropriate types to mylang.tdl or rules.tdl

    if ch.get('subj-drop') == 'subj-drop-all' and not (ch.get('subj-con')
                                                       == 'subj-con-some'):
        rules.add('decl-head-opt-subj := decl-head-opt-subj-phrase.')
    if ch.get('subj-drop') == 'subj-drop-lex' and not (ch.get('subj-con')
                                                       == 'subj-con-some'):
        rules.add('decl-head-opt-subj := decl-head-opt-subj-phrase.')
        mylang.add('no-subj-drop-verb-lex := verb-lex &\
                         [SYNSEM.LOCAL.CAT.VAL.SUBJ.FIRST.OPT -].')
        mylang.add('subj-drop-verb-lex := verb-lex.')

    # Figure out the constraints on object dropping and write the
    # appropriate types to mylang.tdl or rules.tdl
    if ch.get('obj-drop') == 'obj-drop-all':
        rules.add('basic-head-opt-comp := basic-head-opt-comp-phrase.')

    if ch.get('obj-drop') == 'obj-drop-lex':
        rules.add('basic-head-opt-comp := basic-head-opt-comp-phrase.')
        mylang.add('no-obj-drop-verb-lex := transitive-verb-lex &\
                        [SYNSEM.LOCAL.CAT.VAL.COMPS.FIRST.OPT -].')
        mylang.add('obj-drop-verb-lex := transitive-verb-lex.')

    if ch.get('subj-drop') == 'subj-drop-lex' and ch.get(
            'obj-drop') == 'obj-drop-lex':
        mylang.add(
            'subj-drop-only-verb-lex := subj-drop-verb-lex & no-obj-drop-verb-lex.'
        )
        mylang.add(
            'obj-drop-only-verb-lex := obj-drop-verb-lex & no-subj-drop-verb-lex.'
        )
        mylang.add(
            'subj-obj-drop-verb-lex := subj-drop-verb-lex & obj-drop-verb-lex.'
        )
        mylang.add(
            'no-drop-verb-lex := no-subj-drop-verb-lex & no-obj-drop-verb-lex.'
        )

    mylang.set_section('phrases')

    # Create phrase-structure rules for each context
    for context in ch.get('context'):
        name = 'context' + str(context.iter_num())
        ptype = name + '-decl-head-opt-subj-phrase'
        features.customize_feature_values(mylang, ch, hierarchies, context,
                                          ptype, 'con')
        mylang.add(ptype + ':= decl-head-opt-subj-phrase.')
        rules.add(name + '-decl-head-opt-subj := ' + name +
                  '-decl-head-opt-subj-phrase.')

    # Trying to get co-occurrence of marker dropping to work

    if (ch.get('subj-mark-no-drop') == 'subj-mark-no-drop-not'
            and (ch.get('subj-mark-drop') == 'subj-mark-drop-opt'
                 or ch.get('subj-mark-drop') == 'subj-mark-drop-req')):
        mylang.add(
            'basic-head-subj-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.SUBJ.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ((ch.get('obj-mark-no-drop') == 'obj-mark-no-drop-not'
         and ch.get('obj-mark-drop') == 'obj-mark-drop-req')
            or ((ch.get('obj-mark-no-drop') == 'obj-mark-no-drop-opt'
                 and ch.get('obj-mark-drop') == 'obj-mark-drop-req'))):
        mylang.add(
            'basic-head-comp-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.COMPS.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ch.get('obj-mark-no-drop') == 'obj-mark-no-drop-not' and ch.get(
            'obj-mark-drop') == 'obj-mark-drop-opt':
        mylang.add(
            'basic-head-comp-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.COMPS.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ch.get('obj-mark-no-drop') == 'obj-mark-no-drop-req' and ch.get(
            'obj-mark-drop') == 'obj-mark-drop-not':
        mylang.add(
            'basic-head-comp-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.COMPS.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ch.get('obj-mark-no-drop') == 'obj-mark-no-drop-opt' and ch.get(
            'obj-mark-drop') == 'obj-mark-drop-not':
        mylang.add(
            'basic-head-comp-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.COMPS.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ch.get('obj-mark-drop') == 'obj-mark-drop-opt' and ch.get(
            'obj-mark-no-drop') == 'obj-mark-no-drop-req':
        mylang.add(
            'basic-head-comp-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.COMPS.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ch.get('subj-mark-drop') == 'subj-mark-drop-opt' and ch.get(
            'subj-mark-no-drop') == 'subj-mark-no-drop-req':
        mylang.add(
            'basic-head-subj-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.SUBJ.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ch.get('subj-mark-no-drop') == 'subj-mark-no-drop-not' and ch.get(
            'subj-mark-drop') == 'subj-mark-drop-opt':
        mylang.add(
            'basic-head-subj-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.SUBJ.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ch.get('subj-mark-no-drop') == 'subj-mark-no-drop-req' and ch.get(
            'subj-mark-drop') == 'subj-mark-drop-not':
        mylang.add(
            'basic-head-subj-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.SUBJ.FIRST.OPT -].',
            merge=True,
            section='addenda')

    if ch.get('subj-mark-no-drop') == 'subj-mark-no-drop-opt' and ch.get(
            'subj-mark-drop') == 'subj-mark-drop-not':
        mylang.add(
            'basic-head-subj-phrase :+ [HEAD-DTR.SYNSEM.LOCAL.CAT.VAL.SUBJ.FIRST.OPT -].',
            merge=True,
            section='addenda')
Example #6
0
def customize_adjs(mylang, ch, lexicon, hierarchies, rules):

  # Add basic adjective definition
  if ch.get('adj',[]):
    mylang.add("adj-lex := basic-intersective-adjective-lex.")

  # Check which rules need to be added to rules.tdl
  adj_rules = {'adj_head': False, 'head_adj': False}
  # Check which types need to be added to mylanguage.tdl
  adj_type_base = ('pred_word', 'pred_lex', 'pred_only',
                   'attr_word', 'attr_lex', 'attr_only',
                   'stative_word', 'stative_lex', 'any_adj')
  # Convert into dictionary with False default values
  #adj_types = {item: False for item in adj_types}
  adj_types = dict()
  for item in adj_type_base:
    adj_types[item] = False

  # Lexical super types of different adjective types
  lst_map = {"both": "attr-adj-lex",
             "attr": "attr-only-adj-lex",
             "pred": "pred-only-adj-lex",
             "none": "adj-lex" }

  # Go through adjective position classes...
  for adj_pc in ch.get('adj-pc',[]):
    # check if any have "any adj" as input
    if not adj_types['any_adj'] and 'adj' in adj_pc.get('inputs',[]).split(', '):
      adj_types['any_adj'] = True
    # Additional checks for switching adjectives
    switching = adj_pc.get('switching',False)
    if switching:
      # For each switching adjective...
      for lrt in adj_pc.get('lrt',[]):
        # Check its mode to get lexical types to add
        if not (adj_types['pred_lex'] and adj_types['attr_lex']):
          adj_pc_mod = lrt.get('mod','')
          if adj_pc_mod:
            # TJT 12-05-14: "both" lexical rule types are predicative, too!
            if adj_pc_mod in ('pred','both'):
              adj_types['pred_lex'] = True
            # TJT 11-06-14: "both" lexical rule types are attributive
            elif adj_pc_mod in ('attr','both'):
              adj_types['attr_lex'] = True
        # Check modification direction to get rules to add
        if not (adj_rules['head_adj'] and adj_rules['adj_head']):
          lrt_modpos = lrt.get('modpos',False)
          if lrt_modpos:
            if lrt_modpos == 'before':
              adj_rules['head_adj'] = True
            elif lrt_modpos == 'after':
              adj_rules['adj_head'] = True
            elif lrt_modpos == 'either':
              adj_rules['head_adj'] = True
              adj_rules['adj_head'] = True
        # Check predicative behavoir to get rules to add
        if not adj_types['stative_lex']:
          # If not a copula complement
          if not lrt.get('predcop',False):
            adj_types['stative_lex'] = True

  # Add the lextypes to mylanguage.tdl
  for adj in ch.get('adj',[]):
    # Reset values
    lst, posthead, subj, pred, adj_constraints, modunique = '', '', '', '', '', ''
    root = False

    # Get all supertypes to check for redundant specifications
    all_supertypes, pathToRoot = get_all_supertypes(adj, ch)
    if not pathToRoot:
      raise ValueError("No path to the root was found for type %s." % adj.get('name','') +\
                       "Please try validating your choices and compiling again.")
    # Keep track of redundancies
    supertype_redundancies = defaultdict(lambda: False)

    ## Check pivots
    # Pivot on type of adjective
    mode = adj.get('mod',False)
    # TJT 2014-09-04: Commenting this out because one should be able
    # to define subtypes for purely morphological use
    #if not mode: continue
    # Pivot on modification direction
    modpos = adj.get('modpos',False)
    # Pivot on copula complementation
    predcop = adj.get('predcop',False)
    # Pivot on unique modification
    modunique = adj.get('modunique',False)

    # Optionally copula complement and adjectives that only agree
    # in only position must be unspecified at the lexical level
    if predcop == "opt":
      mode = "none"

    # Check for redundancies and collisions
    def_error = " ".join('''Collision found in supertype at %s!
                            Validate your choices file and try again.
                            Supertype: %s; Supertype Choice: %s
                            Type: %s; Type choice: %s'''.split()).strip()
    for supertype in all_supertypes:
      supertype_choice = ch.get(supertype,False)
      if supertype_choice:
        # Check mode
        if mode:
          supertype_mode = supertype_choice.get('mode',False)
          if supertype_mode:
            if supertype_mode == "both" and mode in ('attr', 'pred'):
              pass # attr and pred unify with both
            elif mode != supertype_mode:
              raise ValueError(def_error % (supertype, supertype_mode, adj.get('name',''), mode))
        # Check modpos
        if modpos:
          supertype_modpos = supertype_choice.get('modpos',False)
          if supertype_modpos:
            if modpos == supertype_modpos:
              supertype_redundancies['modpos'] = True
            elif supertype_modpos == 'either' and modpos in ('before', 'after'):
              pass # before and after unify with either
            else:
              raise ValueError(def_error % (supertype, supertype_modpos, adj.get('name',''), modpos))
        # Check modunique
        if modunique and supertype_choice.get('modunique',False):
          supertype_redundancies['modunique'] = True
        # Check predcop
        if predcop:
          supertype_predcop = supertype_choice.get('predcop',False)
          if supertype_predcop:
            if predcop == supertype_predcop:
              supertype_redundancies['predcop'] = True
            elif supertype_predcop == 'opt' and predcop in ('opt', 'obl'):
              pass
            else:
              raise ValueError(def_error % (supertype, supertype_predcop, adj.get('name',''), predcop))

    ## Calculate supertypes
    stypes = adj.get('supertypes').split(', ')
    stype_names = []
    if '' in stypes: # Found root
      root = True
    # Set up root supertypes
    if root:
      stype_names = [lst_map[mode]]
    # Set up defined supertypes
    else:
      stype_names = [adj_id(ch[st]) for st in stypes if st]
    	  # Add pred-only or attr-only types
      if mode == 'pred' and predcop != 'opt':
        stype_names.append("pred-only-adj-lex")
      elif mode == 'attr':
        stype_names.append("attr-only-adj-lex")
    # Format supertypes
    stype_def = " & ".join(stype_names) or ""
    if stype_def: stype_def += " & "
    # Add pred-only and attr-only types if applicable
    if mode in ('attr','pred'):
      adj_types["%s_only" % mode] = True # Add proper type to mylanguage.tdl

    # For attributive adjectives...
    if mode in ("both", "attr"):
      # Set up proper rule for mylanguage.tdl
      adj_types['attr_word'] = True
      # Pivot on direction of modification
      if not supertype_redundancies['modpos']:
        if modpos == 'after':
          posthead = 'POSTHEAD - '
          adj_rules['adj_head'] = True
        elif modpos == 'before':
          posthead = 'POSTHEAD + '
          adj_rules['head_adj'] = True
        elif modpos == "either":
          adj_rules['head_adj'] = True
          adj_rules['adj_head'] = True
      # Set up unique modification if necessary
      if modunique:
        if not supertype_redundancies['modunique']:
          modunique = 'MOD < [ MODIFIED notmod ] >'
        else: modunique = ''

    if not supertype_redundancies['predcop']:
      # For predicative adjectives...
      if mode in ('both', 'pred'):
        # Set up proper rule for mylanguage.tdl
        # Pivot on copula complement
        if predcop == 'obl':
          # Adjective only appears as copula complement
          pred = '+'
          subj = 'VAL.SUBJ < >'
          if mode == 'pred': adj_types['pred_word'] = True
        elif predcop == 'opt':
          # Switching between copula complement and inflection
          # See deffile.py for zero affixes added here
          adj_types['stative_lex'] = True
          adj_types['pred_lex'] = True
        elif predcop == 'imp':
          # Adjective only appears as stative predicate
          pred = '-'
          adj_types['stative_word'] = True
          adj_types['pred_word'] = True
          # Add additional supertype
          if root: stype_def += 'stative-pred-adj-lex & '

    # Calculate HEAD value
    head = ''
    if pred and modunique:
      head = "HEAD [ PRD %s, %s ]" % (pred, modunique)
    elif pred:
      head = "HEAD.PRD %s" % pred
    elif modunique:
      head = "HEAD." + modunique

    # Only output constraints if defined
    if posthead or pred or subj or modunique:
      adj_constraints = "\n  [ SYNSEM.LOCAL.CAT [" + "\n".join([posthead, subj, head]).strip(",\n") + '] ]'

    # Add lexical types to mylanguage.tdl
    atype = adj_id(adj)
    mylang.add(atype + ' := ' + lst + stype_def + adj_constraints + '.')

  ### Add the proper lexical types to mylanguage.tdl
  ## Add attributive adjective types
  if adj_types['attr_word']:
    mylang.add('''attr-adj-lex := adj-lex & intersective-mod-lex &
                    [ SYNSEM.LOCAL.CAT.HEAD.MOD < [ LOCAL.CAT [ HEAD noun,
                                                                VAL.SPR cons ] ] > ].''',
               comment='Basic attributive adjective definition')
  if adj_types['attr_lex']:
    mylang.add('''attr-adj-lex-rule := add-only-no-ccont-rule &
                    [ SYNSEM [ LOCAL [ CAT.HEAD.MOD < [ LOCAL intersective-mod &
                                                        [ CONT.HOOK.INDEX #xarg,
                                                          CAT [ HEAD noun,
                                                                VAL.SPR cons ] ] ] >,
                                       CONT.HOOK.XARG #xarg ] ] ].''',
               comment='Basic attributive adjective lexical rule definition',
               section='lexrules')

  ## Add attributive-only adjective types
  if adj_types['attr_only']:
    attr_only_map = {'attr_word':
                      {'type_name':'attr-only-adj-lex := attr-adj-lex & ',
                       'section':''},
                     'attr_lex':
                      {'type_name':'attr-only-adj-lex-rule := attr-adj-lex-rule & ',
                       'section':'lexrules'} }
    for sort in ('attr_word', 'attr_lex'):
      if adj_types[sort]:
        mylang.add('''%s [ SYNSEM.LOCAL.CAT [ HEAD.PRD -,
                                              VAL.SUBJ < > ] ].''' % \
                      attr_only_map[sort]['type_name'],
                      section=attr_only_map[sort]['section'])

  ## Add predicative-only adjective types
  if adj_types['pred_only']:
    if adj_types['pred_word']:
      mylang.add('''pred-only-adj-lex := adj-lex & no-mod-lex.''')
    if adj_types['pred_lex']:
      mylang.add('''pred-only-adj-lex-rule := add-only-no-ccont-rule & no-mod-lex.''')

  ## Add additional types
  # If there are stative predicates, add the proper rule and supertype
  pred_adj_map = {'stative_word':
                    {'supertype':'stative-pred-adj-lex := adj-lex &',
                     'comment':'Stative predicate adjective definition',
                     'section':''},
                  'stative_lex':
                    {'supertype':'stative-pred-lex-rule := add-only-no-ccont-rule & ',
                     'comment':'Stative predicate adjective lexical rule definition',
                     'section':'lexrules'}}
  pred_adj_definition = '''%s
    [ SYNSEM.LOCAL [ CAT.VAL.SUBJ < [ LOCAL [ CONT.HOOK.INDEX #xarg,
  		   		    	                       CAT [ VAL [ SPR < >,
                                                           COMPS < > ],
                                                    HEAD noun ] ] ] >,
                     CONT.HOOK.XARG #xarg ] ].'''
  for form in ("stative_word", "stative_lex"):
    if adj_types[form]:
      mylang.add(pred_adj_definition % pred_adj_map[form]['supertype'],
                 comment=pred_adj_map[form]['comment'],
                 section=pred_adj_map[form]['section'])

  # If adjective incorporation, add to mylanguage.tdl
  if ch.get("adj_incorp",False):
    mylang.add('''adj_incorporation-lex-rule := add-only-rule &
                    [ C-CONT [ RELS <! arg1-ev-relation &
                                       [ LBL #ltop,
		                                 ARG1 #index ] !>,
	                           HOOK #hook ],
                      DTR.SYNSEM.LOCAL [ CAT.HEAD noun,
  		                                 CONT.HOOK #hook &
    			                                   [ LTOP #ltop,
			                                         INDEX #index ] ] ].''',
            comment='Adjective Incorporation',
            section='lexrules')

  # Add the proper syntactic rules to rules.tdl
  if adj_rules['head_adj']: rules.add("head-adj-int := head-adj-int-phrase.")
  if adj_rules['adj_head']: rules.add("adj-head-int := adj-head-int-phrase.")

  # Add the lexical entries to lexicon.tdl
  lexicon.add_literal(';;; Adjectives')

  for adj in ch.get('adj',[]):
    atype = adj_id(adj)

    # Automatically generate feature values based on choices
    features.customize_feature_values(mylang, ch, hierarchies, adj, atype, 'adj')

    for stem in adj.get('stem', []):
      typedef = TDLencode(stem.get('name')) + ' := ' + atype + ' & \n \
                [ STEM < "' + orth_encode(stem.get('orth')) + '" >, \
                SYNSEM.LKEYS.KEYREL.PRED "' + stem.get('pred') + '" ].'
      lexicon.add(typedef)
Example #7
0
def customize_nouns(mylang, ch, lexicon, hierarchies):
  # Figure out which kinds of determiner-marking are in the language
  seen = {'obl':False, 'opt':False, 'imp':False}
  seenCount = 0

  for noun in ch.get('noun',[]):
    det = noun.get('det')
    if not det == '' and not seen[det]:
      seen[det] = True
      seenCount += 1

  singlentype = (seenCount == 1)

  # Playing fast and loose with the meaning of OPT on SPR.  Using
  # OPT - to mean obligatory (as usual), OPT + to mean impossible (that's
  # weird), and leaving OPT unspecified for truly optional.  Hoping
  # this will work at least for LSA111 lab.

  # ERB 2006-11-28 Update: To make that weird use of OPT work, the
  # head-spec rule has to require [OPT -] on its non-head daughter.
  # Adding that just in case we add the no-spr-noun-lex type.

  typedef = \
    'noun-lex := basic-noun-lex & basic-one-arg & no-hcons-lex-item & \
       [ SYNSEM.LOCAL [ CAT.VAL [ SPR < #spr & [ LOCAL.CAT.HEAD det ] >, \
                                  COMPS < >, \
                                  SUBJ < >, \
                                  SPEC < > ] ], \
         ARG-ST < #spr > ].'
  mylang.add(typedef)

  # Adding empty MOD on general definitiion for noun-lex
  mylang.add('noun-lex := non-mod-lex-item.')

  # singlentype means there's only one type of n in the hierarchy.
  if singlentype:
    if seen['obl']:
      typedef = 'noun-lex := [ SYNSEM.LOCAL.CAT.VAL.SPR < [ OPT - ] > ].'
      mylang.add(typedef)
    elif seen['imp']:
      typedef = 'noun-lex := [ SYNSEM.LOCAL.CAT.VAL.SPR < [ OPT + ] > ].'
      mylang.add(typedef)
  else:
    if seen['obl']:
      typedef = \
        'obl-spr-noun-lex := noun-lex & \
           [ SYNSEM.LOCAL.CAT.VAL.SPR < [ OPT - ] > ].'
      mylang.add(typedef)

    if seen['imp']:
      typedef = \
        'no-spr-noun-lex := noun-lex & \
           [ SYNSEM.LOCAL.CAT.VAL.SPR < [ OPT + ] > ].'
      mylang.add(typedef)

  if seen['imp'] and ch.get('has-dets') == 'yes':
    mylang.add(
      'head-spec-phrase := [ NON-HEAD-DTR.SYNSEM.OPT - ].',
      'Nouns which cannot take specifiers mark their SPR requirement\n' +
      'as OPT +.  Making the non-head daughter OPT - in this rule\n' +
      'keeps such nouns out.')

  if ch.get('case-marking') != 'none':
    if not ch.has_adp_case():
      mylang.add('noun :+ [ CASE case ].', section='addenda')

  # Add the lexical entries
  lexicon.add_literal(';;; Nouns')

  # make a hash of nountypes --> lists of children so that we
  # can stopdet on children
  children = defaultdict(dict)
  for noun in ch.get('noun',[]):
    for p in noun.get('supertypes').split(', '):
      children[p][noun.full_key] = 1

  # make and populate a dictionary of stopdets, to avoid vacuous det supertypes
  # have to follow inheritance paths downwards from any nonempty det values
  stopdets={}
  for noun in ch.get('noun',[]):
    # if det is nonempty, child nouns shouldn't inherit det
    det = noun.get('det')
    if det != '':
      if noun.full_key in children:
      # there are children to stopdet on
      # recursively look for children
        parents = [ noun.full_key ]
        while (True):
          next_parents = []
          for p in parents:
            if p in children:
              for c in children[p].keys():
                stopdets[c]=True
                if not c in next_parents:
                  next_parents.append(c)
          if len(next_parents) == 0:
            break
          else:
            parents = next_parents


  for noun in ch.get('noun',[]):
    ntype = noun_id(noun)
    det = noun.get('det')
    if noun.full_key in stopdets:
      det = ''

    stypes = noun.get('supertypes').split(', ')
    stype_names = [noun_id(ch[st]) for st in stypes if st != '']

    #if singlentype or det == 'opt':
    #  stype = 'noun-lex'
    if not singlentype:
      if det == 'obl':
        stype_names.append('obl-spr-noun-lex')
      elif det == 'imp':
        stype_names.append('no-spr-noun-lex')

    if len(stype_names) == 0:
      mylang.add(ntype + ' := noun-lex .')
    else:
      mylang.add(ntype + ' := ' + ' & '.join(stype_names) + '.')

    features.customize_feature_values(mylang, ch, hierarchies, noun, ntype, 'noun')

    for stem in noun.get('stem', []):
      orthstr = orth_encode(stem.get('orth'))
      pred = stem.get('pred')
      name = stem.get('name')
      typedef = TDLencode(name) + ' := ' + ntype + ' & \
                  [ STEM < "' + orthstr + '" >, \
                    SYNSEM.LKEYS.KEYREL.PRED "' + pred + '" ].'
      lexicon.add(typedef)
Example #8
0
def customize_verbs(mylang, ch, lexicon, hierarchies):
  negmod = ch.get('neg-mod')
  negadv = ch.get('neg-adv')
  wo = ch.get('word-order')
  auxcomp = ch.get('aux-comp')
  auxorder = ch.get('aux-comp-order')
  # Do we need to constrain HC-LIGHT on verbs, to distinguish V from VP?
  hclight = (negadv == 'ind-adv' and negmod == 'v')
  hclightallverbs = False

  if ch.get('has-aux') == 'yes':
    vc = determine_vcluster(auxcomp, auxorder, wo, ch)
    if wo == 'vso' or wo == 'osv':
      wo = 'req-hcl-vp'
    if auxcomp == 'v' and hclight != True:
      hclight = True
      if wo != 'free' or vc == True:
        hclightallverbs = True
    if auxcomp == 'vp' and wo == 'req-hcl-vp':
      hclightallverbs = True
  else:
    vc = False

  if wo == 'req-hcl-vp':
    wo = ch.get('word-order')

  # Lexical types for verbs
  # I'm adding the constraint to associate XARG with the
  # first ARG-ST element here (so raising auxiliaries work),
  # but perhaps this belongs in matrix.tdl?  Or maybe this
  # is another module/parameter (like, the external argument
  # might not be the first one?

  mainorverbtype = main_or_verb(ch)
  # The variable mainorverbtype is a type name for lexical/main (non-aux) verbs.
  # Note that the use of 'main' instead of 'lexical' is strictly for
  # coding clarity
  # If there are auxiliaries, non-aux verbs are 'main-verb-lex', and 'verb-lex'
  # includes both aux and lexical/main verbs.
  # If there are no auxiliaries then 'verb-lex' covers all verbs

  # Neither mainverbs or auxs should start out as modifiers (for now)
  # Assigning constraint to verb-lex

  if ch.get('has-aux') == 'yes':
    mylang.add('head :+ [ AUX bool ].', section='addenda')
    #mainorverbtype = 'main-verb-lex'

    # we need to know whether the auxiliaries form a vcluster

    auxcomp = ch.get('aux-comp')
    wo = ch.get('word-order')
    auxorder = ch.get('aux-comp-order')
    vcluster = determine_vcluster(auxcomp, auxorder, wo, ch)

    typedef = \
      'verb-lex := non-mod-lex-item & \
                 [ SYNSEM.LOCAL.CAT.HEAD verb ].'
    mylang.add(typedef)
    typedef = \
      'main-verb-lex := verb-lex & basic-verb-lex & \
                      [ SYNSEM.LOCAL.CAT.HEAD.AUX - ].'
    mylang.add(typedef)
    typedef = \
      'aux-lex := verb-lex & \
                [ SYNSEM.LOCAL.CAT.HEAD.AUX + ].'
    mylang.add(typedef)
    if vcluster:
      mylang.add('main-verb-lex := [ SYNSEM.LOCAL.CAT.VC + ].')
      mylang.add('aux-lex := [ SYNSEM.LOCAL.CAT.VC - ].')
  else:
    #mainorverbtype = 'verb-lex'
    vcluster = False
    mylang.add('verb-lex := basic-verb-lex & non-mod-lex-item.')

  typedef = mainorverbtype + ' :=  \
       [ SYNSEM.LOCAL [ CAT.VAL [ SPR < >, \
                                  SPEC < >, \
                                  SUBJ < #subj > ], \
                        CONT.HOOK.XARG #xarg ], \
         ARG-ST < #subj & \
                  [ LOCAL [ CAT.VAL [ SPR < >, \
                                      COMPS < > ], \
                            CONT.HOOK.INDEX #xarg ] ], ... > ].'
  mylang.add(typedef)

  if hclightallverbs:
    mylang.add('verb-lex := [ SYNSEM.LOCAL.CAT.HC-LIGHT - ].')
  elif hclight:
    comment = \
      ';;; If there are aspects of the syntax which pick out\n' + \
      ';;; lexical Vs (transitive or intransitive) such as V-attachment\n' + \
      ';;; of adverbs or argument composition auxiliaries which take V\n' + \
      ';;; complements, we need to distinguish (intranstive) V and VP.\n' + \
      ';;; To do so, we make use of a feature LIGHT.  Phrases are\n' + \
      ';;; generally [LIGHT -] with the exception of head-complement\n' + \
      ';;; phrases, which take their value for LIGHT from the head\'s\n' + \
      ';;; HC-LIGHT feature.  To make this work for us here, constraint\n' + \
      ';;; HC-LIGHT on verbs to be -.'
#    mylang.add_literal(comment)
    mylang.add(mainorverbtype + ' := [ SYNSEM.LOCAL.CAT.HC-LIGHT - ].')

  # intransitive verb lexical type
  typedef = \
    'intransitive-verb-lex := ' + mainorverbtype + ' & intransitive-lex-item & \
       [ SYNSEM.LOCAL.CAT.VAL.COMPS < > ].'
  mylang.add(typedef)

  # transitive verb lexical type
  typedef = \
    'transitive-verb-lex := ' + mainorverbtype + ' & transitive-lex-item & \
       [ SYNSEM.LOCAL.CAT.VAL.COMPS < #comps >, \
         ARG-ST < [ ], \
                  #comps & \
                  [ LOCAL.CAT [ VAL [ SPR < >, \
                                      COMPS < > ] ] ] > ].'
  mylang.add(typedef)

  case.customize_verb_case(mylang, ch)

  # Add constraints to choices to create lex rules for bipartite stems
  customize_bipartite_stems(ch)

  # Lexical entries
  lexicon.add_literal(';;; Verbs')

  # Now create the lexical entries for all the defined verb types
  cases = case.case_names(ch)
  for verb in ch.get('verb',[]):
    stypes = verb.get('supertypes').split(', ')
    stype_names = [verb_id(ch[st]) for st in stypes if st != '']

    vtype = verb_id(verb)
    val = verb.get('valence')

    if not val == '':
      i = val.find(',')
      dir_inv = ''
      tivity = ''
      if i != -1:
        val = val[:i]
        dir_inv = 'dir-inv-'

      if val == 'trans':
        tivity = 'trans'
      elif val == 'intrans':
        tivity = 'intrans'
      elif val.find('-') != -1:
        c = val.split('-')
        a_case = case.canon_to_abbr(c[0], cases)
        o_case = case.canon_to_abbr(c[1], cases)
        tivity = a_case + '-' + o_case + '-trans'
      else:
        s_case = case.canon_to_abbr(val, cases)
        tivity = s_case + '-intrans'

      if not dir_inv == '' or not tivity == '':
        stype_names.append(dir_inv + tivity + 'itive-verb-lex')

    if len(stype_names) == 0:
      mylang.add(vtype + ' := verb-lex .')
    else:
      mylang.add(vtype + ' := ' + ' & '.join(stype_names) + '.')

    features.customize_feature_values(mylang, ch, hierarchies, verb, vtype, 'verb', None, cases)

    stems = verb.get('stem', [])
    stems.extend(verb.get('bistem', []))

    for stem in stems:
      orthstr = orth_encode(stem.get('orth'))
      pred = stem.get('pred')
      name = stem.get('name')
      typedef = \
        TDLencode(name) + ' := ' + vtype + ' & \
                    [ STEM < "' + orthstr + '" >, \
                      SYNSEM.LKEYS.KEYREL.PRED "' + pred + '" ].'
      lexicon.add(typedef)