Exemple #1
0
/* todo: Something compatible with the dialect is chosen.
 * Alter this to PREFER dialect-specific choices?
 * <value_prop> can also just be value number.
 */
ObjToLexEntry *ObjToLexEntryGet3(Obj *obj, Obj *value_prop, char *features,
                                 char *not_usagefeat, int subcat, int paruniv,
                                 int *theta_filled, int pass_two,
                                 Discourse *dc)
{
  int		i, pos, address;
  char		features1[FEATLEN];
  ObjToLexEntry *ole, *p;
  ole = obj->ole;
  address = DiscourseAddress(dc);
  if (dc->ga.qwq &&
      (ISA(N("question-word"), obj) || ISA(N("copula"), obj))) {
    StringCpy(features1, features, FEATLEN);
    StringElimChar(features1, F_NOUN);
    features = features1;
  }
  for (i = 0, p = ole; p; i++, p = p->next) {
    if (i >= MAXOLELEN) {
      Dbg(DBGGENER, DBGBAD, "increase MAXOLELEN");
      break;
    }
    pos = FeatureGet(p->le->features, FT_POS);

    /* todo: For super debugging, if we return NULL from this function,
     * print out list of why each lexical entry failed.
     */
    consider[i] = ((DC(dc).lang == FeatureGetRequired("ObjToLexEntryGet",
                                                      p->le->features,
                                                      FT_LANG))
                   && StringAnyIn(features, p->le->features)
                   && paruniv == FeatureGet(p->features, FT_PARUNIV)
                   && (subcat == F_NULL ||
                       subcat == ThetaRoleGetAnySubcat(p->theta_roles))
                   && F_NULL == FeatureGet(p->features, FT_CONNOTE) /* todo */
                   && FeatureDialectMatch(DC(dc).dialect,
                                          FeatureGet(p->features, FT_DIALECT))
                   && DC(dc).style == FeatureGet(p->features, FT_STYLE)
                   && FeatureTaskOK(p->features, dc->task)
                   && FeatureMatch(address, FeatureGet(p->features, FT_ADDRESS))
                   && (not_usagefeat == NULL ||
                       (!StringAnyIn(not_usagefeat, p->features)))
                   && ((pos != F_NOUN) || ISA(N("relation"), obj) ||
                       ThetaRoleMatch(theta_filled, p->theta_roles, pass_two)));
    Nop(); /* Debugging anchor. */
  }
  if (!dc->ga.consistent) {
    for (i = 0, p = ole; p && i < MAXOLELEN; i++, p = p->next) {
      if (consider[i] && F_FREQUENT == ((uc)FeatureGet(p->features, FT_FREQ)) &&
          p->lastused == UNIXTSNA) {
        p->lastused = time(NULL); return(p);
      }
    }
    for (i = 0, p = ole; p && i < MAXOLELEN; i++, p = p->next) {
      if (consider[i] && F_NULL == FeatureGet(p->features, FT_FREQ) &&
          p->lastused == UNIXTSNA) {
        p->lastused = time(NULL); return(p);
      }
    }
    if (DC(dc).infrequent_ok) {
      for (i = 0, p = ole; p && i < MAXOLELEN; i++, p = p->next) {
        if (consider[i] && F_INFREQUENT == FeatureGet(p->features, FT_FREQ) &&
            p->lastused == UNIXTSNA) {
          p->lastused = time(NULL); return(p);
        }
      }
    }
  }
  if (pass_two) {
    /* In this case ObjToLexEntryClearLastused has already been done. */
    return(NULL);
  }
  ObjToLexEntryClearLastused(ole, dc);
  for (i = 0, p = ole; p && i < MAXOLELEN; i++, p = p->next) {
    if (consider[i] && F_FREQUENT == FeatureGet(p->features, FT_FREQ)) {
      p->lastused = time(NULL); return(p);
    }
  }
  for (i = 0, p = ole; p && i < MAXOLELEN; i++, p = p->next) {
    if (consider[i] && F_NULL == FeatureGet(p->features, FT_FREQ)) {
      p->lastused = time(NULL); return(p);
    }
  }
  /* Note in this case we do permit the generation of infrequent. */
  for (i = 0, p = ole; p && i < MAXOLELEN; i++, p = p->next) {
    if (consider[i] && F_INFREQUENT == FeatureGet(p->features, FT_FREQ)) {
      p->lastused = time(NULL); return(p);
    }
  }
  return(NULL);
}
Exemple #2
0
ThetaRole *ThetaRoleBuild(char *features, LexEntry **les, int lelen,
                          int *delims, int *subcats, Obj *con,
                          ThetaRole *theta_roles_expl)
{
    int		i, j, pos, subjfound, subcat, is_optional;
    LexEntry	*le;
    ThetaRole	*trs[MAXCPSIZE], *r;
    for (j = 0; j < MAXCPSIZE; j++) {
        trs[j] = NULL;
    }
    pos = FeatureGetRequired("ThetaRoleBuild", features, FT_POS);
    subjfound = 0;
    if (pos == F_ADJECTIVE || pos == F_NOUN || pos == F_VERB) {
#ifdef maxchecking
        ThetaRoleCheckSubcat(features);
#endif
        /* subj */
        if (StringIn(F_SUBJ3, features)) {
            trs[3] = ThetaRoleCreate(0, ThetaRoleSubjCase(pos), NULL, F_NULL, NULL);
            subjfound = 1;
        }
        if (StringIn(F_SUBJ2, features)) {
            if (subjfound) {
                Dbg(DBGLEX, DBGBAD, "ThetaRoleBuild: multiple subjects");
            }
            trs[2] = ThetaRoleCreate(0, ThetaRoleSubjCase(pos), NULL, F_NULL, NULL);
            subjfound = 1;
        }
        if (pos == F_NOUN) {
            if (subjfound) {
                Dbg(DBGLEX, DBGBAD, "ThetaRoleBuild: subj defined for noun");
            }
        } else {
            if (!subjfound) {
                trs[1] = ThetaRoleCreate(0, ThetaRoleSubjCase(pos), NULL, F_NULL, NULL);
                subjfound = 1;
            }
        }
        /* obj */
        if (ThetaRoleGetSubcat(F_OBJ3, features, &is_optional, &subcat)) {
            if (trs[3]) {
                Dbg(DBGLEX, DBGBAD, "ThetaRoleBuild: object index same as subject");
            }
            trs[3] = ThetaRoleCreate(is_optional, N("obj"), NULL, subcat, NULL);
        }
        if (ThetaRoleGetSubcat(F_OBJ2, features, &is_optional, &subcat)) {
            if (trs[2]) {
                Dbg(DBGLEX, DBGBAD, "ThetaRoleBuild: object index same as subject");
            }
            trs[2] = ThetaRoleCreate(is_optional, N("obj"), NULL, subcat, NULL);
        }
        if (ThetaRoleGetSubcat(F_OBJ1, features, &is_optional, &subcat)) {
            if (trs[1]) {
                Dbg(DBGLEX, DBGBAD, "ThetaRoleBuild: object index same as subject");
            }
            trs[1] = ThetaRoleCreate(is_optional, N("obj"), NULL, subcat, NULL);
        }
    } else {
        subcat = FeatureGet(features, FT_SUBCAT);
        if (pos == F_CONJUNCTION || pos == F_PREPOSITION ||
                pos == F_PRONOUN) {
            if (subcat != F_NULL) {
                /* todo: Inelegant. In order to hold the subcategorization restriction
                 * for later use by ObjToLexEntryGet2 in generating conjunctions.
                 */
                trs[1] = ThetaRoleCreate(0, N("kobj1"), NULL, subcat, NULL);
            }
        } else {
#ifdef maxchecking
            if (subcat != F_NULL) {
                Dbg(DBGLEX, DBGBAD, "ThetaRoleBuild: <%s> unexpected FT_SUBCAT",
                    features);
            }
#endif
        }
#ifdef maxchecking
        if (F_NULL != FeatureGet(features, FT_SUBJLOC) ||
                F_NULL != FeatureGet(features, FT_OBJLOC)) {
            Dbg(DBGLEX, DBGBAD, "inapplicable subj/obj location specs <%s>",
                features);
        }
#endif
    }
    if (les) {
        for (i = 0; i < lelen; i++) {
            if (delims[i] == LE_PHRASE_PREP || delims[i] == LE_PHRASE_OPT_PREP) {
                if (!(le = les[i])) {
                    Dbg(DBGLEX, DBGBAD, "ThetaRoleBuild: empty le");
                } else {
                    for (j = ThetaRoleIOBJStart(features); j < MAXCPSIZE; j++) {
                        if (trs[j] == NULL) {
                            trs[j] = ThetaRoleCreate(delims[i] == LE_PHRASE_OPT_PREP,
                                                     N("iobj"), le, subcats[i], NULL);
                            break;
                        }
                    }
                }
            }
        }
    }
    for (j = MAXCPSIZE-1; j >= 1; j--) {
        if (trs[j]) {
            for (j = j-1; j >= 1; j--) {
                if (trs[j] == NULL) {
                    trs[j] = ThetaRoleCreate(1, ObjNA, NULL, F_NULL, NULL);
                }
            }
            r = theta_roles_expl;
            for (j = MAXCPSIZE-1; j >= 1; j--) {
                if (trs[j]) {
                    trs[j]->next = r;
                    r = trs[j];
                }
            }
            return(r);
        }
    }
    return(NULL);
}