/****************************************************************************** * Top-level Emotion Understanding Agent. * todo: Anger reduces friendship level slightly, increases enemy level. ******************************************************************************/ void UA_Emotion(Actor *ac, Ts *ts, Obj *a, Obj *in) { Obj *emot_class, *from, *to; ObjList *p, *causes; if (GetActorSpatial(in, a, &from, &to)) { /* todo: If you ptrans to a place you like, you are happy. */ } else if (ISA(N("emotion"), I(in, 0)) && (!ISA(N("attitude"), I(in, 0))) && a == I(in, 1)) { /* [happy Jim] [sad Jim] [happy-for Mary Mary-roommate] */ emot_class = I(in, 0); for (p = ac->emotions; p; p = p->next) { if (I(p->obj, 0) == emot_class) { /* Emotion is same as an existing one: alter intensity. * For example, after A canceling an appointment with B, the input * "B is angry at A" makes sense because this emotion was * already added by the cancel. */ ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_EXPECTED); if ((causes = CAUSES(p->obj, ac->cx))) { ContextAddMakeSenseReasons(ac->cx, causes); ObjListFree(causes); } ObjWeightSet(p->obj, ObjWeight(p->obj) + ObjWeight(in)); return; } /* todo: Perhaps handle emotion specifications and generalizations. * But this might not have so much meaning: You can be both happy * and proud. */ } UA_Emotion1(ac, ts, a, in); UA_EmotionAdd(ac, ts, in, NULL, NULL); } }
Obj *UA_Emotion_GStoAEC(Obj *goal_status) { if (ISA(N("failed-goal"), goal_status)) { return(N("anger")); } else if (ISA(N("succeeded-goal"), goal_status)) { return(N("gratitude")); } else { return(NULL); } }
Float UA_EmotionSignedWeight(Obj *emot) { Float sgn; if (ISA(N("negative-emotion"), I(emot, 0))) { sgn = -1.0; } else if (ISA(N("positive-emotion"), I(emot, 0))) { sgn = 1.0; } else { sgn = 0.0; /* ? */ } return sgn*ObjWeight(emot); }
void UA_Trade(Actor *ac, Ts *ts, Obj *a, Obj *in) { ObjList *products, *forsales, *p, *commentary; Intension *itn; if (ISA(N("active-goal"), I(in, 0)) && I(in, 1) == a && ISA(N("buy-from"), I(I(in, 2), 0)) && I(I(in, 2), 1) == a && (!ObjIsNa(I(I(in, 2), 3)))) { /* "I want to buy a desk phone." */ if ((products = UA_AskerSelect(ac->cx, I(I(in, 2), 3), &itn))) { commentary = NULL; for (p = products; p; p = p->next) { /* todo: Filter out old ads. */ forsales = RE(&TsNA, L(N("for-sale"), p->obj, ObjWild, ObjWild, ObjWild, ObjWild, ObjWild, E)); commentary = ObjListAppendDestructive(commentary, forsales); } /* if ((!(ac->cx->dc->mode & DC_MODE_CONV)) || ObjListLen(products) < 10 || ObjListLen(commentary) < 10) */ if ((!(ac->cx->dc->mode & DC_MODE_CONV)) || ObjListLen(products) < 18) { if (commentary) { CommentaryAdd(ac->cx, commentary, NULL); ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_TOTAL); } } else { /* Too much output. Try to narrow down with a question. An answer * to the question should result in this function being reinvoked * with something that UA_AskerSelect is able to use to narrow down * the selected products. */ if (UA_AskerNarrowDown(ac->cx, 1.0, N("UA_Trade"), itn, products, L(N("active-goal"), a, L(N("buy-from"), a, I(I(in, 2), 2), N("?answer"), I(I(in, 2), 4), E), E), 1)) { ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_TOTAL); } } } } }
/* SUBGOAL switch-on ?knob * SUBGOAL switch-off ?knob */ void PA_SwitchX(Context *cx, Subgoal *sg, Ts *ts, Obj *a, Obj *o) { Obj *p; Dbg(DBGPLAN, DBGOK, "PA_SwitchX", E); switch (sg->state) { case STBEGIN: if (!ISA(N("lock"), I(o,1))) { TOSTATE(cx, sg, 1); return; } if (!(p = R1EI(2, ts, L(N("key-of"), I(o,1), ObjWild, E)))) { Dbg(DBGPLAN, DBGBAD, "PA_SwitchX: no key found"); goto failure; } SG(cx, sg, 1, STFAILURE, L(N("inside"), p, I(o,1), E)); return; case 1: if (!(p = PA_GetFreeHand(ts, a))) goto failure; SG(cx, sg, STSUCCESS, STFAILURE, L(N("flip-to"), p, I(o,1), ObjNA, I(o,0), E)); return; default: Dbg(DBGPLAN, DBGBAD, "PA_SwitchX: undefined state %d", sg->state); } failure: TOSTATE(cx, sg, STFAILURE); }
/* "Trix's book" */ PNode *TranslateGenitive(PNode *pn, PNode *pnp, Obj *max, PNode *pn_np, PNode *pn_of_np, int srclang, int tgtlang, Discourse *dc) { int of_animate; PNode *np_tgt, *of_np_tgt, *pn1, *pn2, *r, *r1; np_tgt = Translate1(pn_np, pn, max, NULL, srclang, tgtlang, dc); of_np_tgt = Translate1(pn_of_np, pn, max, NULL, srclang, tgtlang, dc); of_animate = pn_of_np->pn1->type == PNTYPE_NAME; /* todo: other animate cases */ r = NULL; for (pn1 = np_tgt; pn1; pn1 = pn1->next_altern) { for (pn2 = of_np_tgt; pn2; pn2 = pn2->next_altern) { r1 = GenGenitive2(pn1, pn2, of_animate || ISA(N("animate-object"), PNodeNounConcept(pn2)), dc); r1->next_altern = r; r = r1; } } PNodeBreakup(np_tgt); PNodeBreakup(of_np_tgt); return(r); }
unsigned int MSufSort::Sort(SYMBOL_TYPE * source, unsigned int sourceLength) { ///tch: //printf("\nIn MSufSort::Sort()\n"); // set the member variables to the source string and its length. m_source = source; m_sourceLength = sourceLength; m_sourceLengthMinusOne = sourceLength - 1; Initialize(); unsigned int start = clock(); InitialSort(); while (m_chainHeadStack.Count()) ProcessNextChain(); while (m_currentSuffixChainId <= 0xffff) ProcessSuffixesSortedByEnhancedInduction(m_currentSuffixChainId++); unsigned int finish = clock(); m_sortTime = finish - start; ///tch: //printf("\nFinished MSufSort::Sort()\nPress any key to continue...\n"); //printf("%s\n",m_source); //system("pause"); //getchar(); // printf(" %c", 13); return ISA(0); }
OBJECT cpu_open_class(STATE, cpu c, OBJECT under, OBJECT sup, OBJECT sym, int *created) { OBJECT val, s1, s2, s3, s4, sup_itr; *created = FALSE; /* Evil people could do A = 12; class A::B; end */ if(!ISA(under, BASIC_CLASS(module))) { cpu_raise_exception(state, c, cpu_new_exception(state, c, state->global->exc_type, "Nesting constant is not a Module")); return Qundef; } val = module_const_get(state, under, sym); if(RTEST(val)) { if(ISA(val, BASIC_CLASS(class))) { if(!NIL_P(sup) && class_superclass(state, val) != sup) { cpu_raise_exception(state, c, cpu_new_exception(state, c, state->global->exc_type, "superclass mismatch")); return Qundef; } } else { cpu_raise_exception(state, c, cpu_new_exception(state, c, state->global->exc_type, "constant is not a class")); return Qundef; } return val; } else {
::libmaus::autoarray::AutoArray< typename SUF_TYPE::value_type > computeISA(SUF_TYPE & SUF, uint64_t const n) { // compute shifted inverse of suffix array extended by one ::libmaus::autoarray::AutoArray< typename SUF_TYPE::value_type > ISA(n,false); for ( size_t i = 0; i < n; ++i ) ISA[SUF[i]] = i; return ISA; }
PNode *TransformGenFrenchContractions(PNode *pn, Discourse *dc, /* RESULTS */ int *change) { int det_gender, det_number; PNode *pnword2; Obj *noun_con; pnword2 = PNodeLeftmost(pn->pn2); if (pn->pn1 && pn->pn1->feature == F_PREPOSITION && pnword2 && pnword2->feature == F_DETERMINER && pnword2->lexitem && LexEntryConceptIsAncestor(N("definite-article"), pnword2->lexitem->le)) { det_number = FeatureGet(pnword2->lexitem->features, FT_NUMBER); det_gender = FeatureGet(pnword2->lexitem->features, FT_GENDER); if ((!StringIn(F_ELISION, pnword2->lexitem->features)) && (det_number == F_PLURAL || det_gender == F_MASCULINE)) { if (LexEntryConceptIsAncestor(N("prep-to"), pn->pn1->lexitem->le)) { /* à le -> au * à les -> aux */ pn->pn1 = GenMakePrep(N("prep-au"), det_gender, det_number, dc); LexitemMakeTrace(pnword2->lexitem); *change = 1; return(pn); } else if (LexEntryConceptIsAncestor(N("prep-of"), pn->pn1->lexitem->le)) { /* de le -> du * de les -> des */ pn->pn1 = GenMakePrep(N("prep-du"), det_gender, det_number, dc); LexitemMakeTrace(pnword2->lexitem); *change = 1; return(pn); } } if ((noun_con = PNodeNounConcept(pn->pn2)) && ISA(N("polity"), noun_con) && LexEntryConceptIsAncestor(N("prep-en"), pn->pn1->lexitem->le)) { /* If noun is "polity". * en la -> en * en le + vowel -> en * en le + nonvowel -> au * en les -> aux */ if (det_gender == F_FEMININE || (F_VOCALIC == LexitemInitialSound(PNodeLeftmostLexitem(pn->pn2), dc))) { LexitemMakeTrace(pnword2->lexitem); *change = 1; return(pn); } else { pn->pn1 = GenMakePrep(N("prep-au"), det_gender, det_number, dc); LexitemMakeTrace(pnword2->lexitem); *change = 1; return(pn); } } } return(pn); }
Bool GetSpatial(Obj *con, /* RESULTS */ Obj **from, Obj **to) { if (ISA(N("location-of"), I(con, 0))) { /* Example: [location-of Martine maison-de-Lucie] * "Martine arrive chez Lucie." */ *from = NULL; *to = I(con, 2); return(1); } else if (ISA(N("ptrans"), I(con, 0))) { /* Example: [ptrans Jim na Opéra-Comique] * "Jim est allé à l'Opéra Comique" */ *from = I(con, 2); *to = I(con, 3); return(1); } return(0); }
/* SUBGOAL inside ?object ?container */ void PA_Inside(Context *cx, Subgoal *sg, Ts *ts, Obj *a, Obj *o) { Dbg(DBGPLAN, DBGOK, "PA_Inside", E); switch (sg->state) { case STBEGIN: if (ISA(N("animate-object"), I(o, 1)) && ISA(N("large-container"), I(o, 2))) { TOSTATE(cx, sg, 200); } else { TOSTATE(cx, sg, 100); } return; case 100: SG(cx, sg, 101, STFAILURE, L(N("open"), I(o,2), E)); return; case 101: if (!(sg->w.Inside.hand = PA_GetFreeHand(ts, a))) goto failure; /* Subgoal is (S6). */ SG(cx, sg, 102, STFAILURE, L(N("holding"), sg->w.Inside.hand, I(o,1), E)); return; case 102: SG(cx, sg, 103, STFAILURE, L(N("move-to"), sg->w.Inside.hand, sg->w.Inside.hand, I(o,2), E)); return; case 103: SG(cx, sg, 104, STFAILURE, L(N("release"), sg->w.Inside.hand, I(o,1), E)); return; case 104: AS(ts, 0, L(N("inside"), I(o,1), I(o,2), E)); TOSTATE(cx, sg, STSUCCESS); return; case 200: SG(cx, sg, STSUCCESS, STFAILURE, L(N("near-reachable"), I(o,1), I(o,2), E)); return; default: Dbg(DBGPLAN, DBGBAD, "PA_Inside: undefined state %d", sg->state); } failure: TOSTATE(cx, sg, STFAILURE); }
/****************************************************************************** * Top-level Goal Understanding Agent. ******************************************************************************/ void UA_Goal(Actor *ac, Ts *ts, Obj *a, Obj *in) { Obj *goal; Subgoal *sg; if (ISA(N("goal-status"), I(in, 0)) && a == I(in, 1)) { /* Goal is stated explicitly. * Examples: * [active-goal Jim [s-employment Jim]] * [succeeded-goal Jim [s-employment Jim]] * [failed-goal Jim [s-employment Jim]] * Note that emotional responses occur as a result of spinning * the goal. */ goal = I(in, 2); /* If <in> corresponds to existing subgoal, steer that subgoal according * to <in>. */ for (sg = ac->subgoals; sg; sg = sg->next) { if (ObjSimilarList(goal, sg->obj)) { UA_GoalSetStatus(ac, sg, I(in, 0), NULL); return; } } /* This is a new subgoal. */ /* todo: Add more heuristics for making sense. * For example, N("s-employment") doesn't make sense if <a> already has * a job. */ ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_TOTAL); if ((sg = TG(ac->cx, &ac->cx->story_time.stopts, a, goal))) { PA_SpinToGoalStatus(ac->cx, sg, I(in, 0), NULL); } } else if (ISA(N("prep-goal-for"), I(in, 0))) { UA_GoalSubgoal(ac, ts, a, in, I(in, 2), I(in, 1)); } else if (ISA(N("intends"), I(in, 0))) { UA_GoalSubgoal(ac, ts, a, in, I(in, 1), I(in, 2)); } }
/****************************************************************************** * Understanding previously unknown emotions. * todo: Angry, grateful. ******************************************************************************/ void UA_Emotion1(Actor *ac, Ts *ts, Obj *a, Obj *in) { Obj *emot_class, *other; emot_class = I(in, 0); if (ISA(N("fortunes-of-others-emotion"), emot_class)) { other = I(in, 2); if (ISA(N("happy-for"), emot_class)) { UA_Emotion_FortunesOfOthers(ac, ts, a, in, other, ObjWeight(in), N("positive-emotion")); } else if (ISA(N("sorry-for"), emot_class)) { UA_Emotion_FortunesOfOthers(ac, ts, a, in, other, ObjWeight(in), N("negative-emotion")); } else if (ISA(N("gloating"), emot_class)) { UA_Emotion_FortunesOfOthers(ac, ts, a, in, other, -ObjWeight(in), N("negative-emotion")); } else if (ISA(N("resentment"), emot_class)) { UA_Emotion_FortunesOfOthers(ac, ts, a, in, other, -ObjWeight(in), N("positive-emotion")); } else Dbg(DBGUA, DBGBAD, "UA_Emotion1 1"); return; } if (UA_Emotion_ExistingGoals(ac, ts, a, in)) return; if (UA_Emotion_NewGoals(ac, ts, a, in, N("failure-emotion-of"), N("failed-goal"))) { return; } if (UA_Emotion_NewGoals(ac, ts, a, in, N("success-emotion-of"), N("succeeded-goal"))) { return; } if (UA_Emotion_NewGoals(ac, ts, a, in, N("activated-emotion-of"), N("active-goal"))) { return; } /* todo: In worst case, assume emotion resulted from the most recently * performed action? */ }
/****************************************************************************** * Examples: * goal_status: N("succeeded-goal") N("failed-goal") N("active-goal") * goal_class: N("a-social-esteem") N("a-social-esteem") N("s-air") * result: pride embarrassment suffocation ******************************************************************************/ Obj *UA_Emotion_GSCtoEC(Obj *goal_status, Obj *goal_class) { Obj *r; if (ISA(N("active-goal"), goal_status)) { if ((r = UA_Emotion_GCtoEC(N("activated-emotion-of"), goal_class))) { return(r); } return(N("motivation")); } else if (ISA(N("failed-goal"), goal_status)) { if ((r = UA_Emotion_GCtoEC(N("failure-emotion-of"), goal_class))) { return(r); } return(N("sadness")); } else if (ISA(N("succeeded-goal"), goal_status)) { if ((r = UA_Emotion_GCtoEC(N("success-emotion-of"), goal_class))) { return(r); } return(N("happiness")); } else { Dbg(DBGUA, DBGBAD, "UA_Emotion_GSCtoEC 1"); return(N("sadness")); } }
ObjList *PA_Graspers(Ts *ts, Obj *obj) { ObjList *r; Obj *o; r = NULL; if (ISA(N("animal"), obj)) { if ((o = DbRetrievePart(ts, NULL, N("right-hand"), obj))) { r = ObjListCreate(o, r); } if ((o = DbRetrievePart(ts, NULL, N("left-hand"), obj))) { r = ObjListCreate(o, r); } } return(r); }
void UA_Weather1(Context *cx, Ts *ts, Obj *in, Obj *grid) { Obj *head, *obj; if (I(in, 0) == N("not") && (head = I(I(in, 1), 0)) && (obj = I(I(in, 1), 1)) && ISA(N("weather-evaluation"), head) && WeatherPronoun(obj)) { /* "It was not a beautiful day." [not [beautiful-day pronoun-ce-expletive]] * todo: Generalize this. */ ContextSetRSN(cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_TOTAL); if (ISA(N("good-weather"), head)) { AS(ts, 0L, L(N("bad-weather"), grid, E)); } else if (ISA(N("bad-weather"), head)) { AS(ts, 0L, L(N("good-weather"), grid, E)); } return; } if (!(head = I(in, 0))) return; if (!(obj = I(in, 1))) return; if (ISA(N("weather-evaluation"), head) && WeatherPronoun(obj)) { /* "It was beautiful." [beautiful-day pronoun-it-expletive] */ goto assertit; } else if (ISA(N("sky-coverage"), head) && WeatherPronounSky(obj)) { /* "The sky was overcast." [overcast-sky sky] * "It was sunny." [sunny pronoun-it-expletive] */ goto assertit; } else if (ISA(N("humidity-description"), head) && WeatherPronounAir(obj)) { /* "The air was dry." [dry air] * "It was humid". [humid pronoun-it-expletive] */ goto assertit; } else if (ISA(N("temperature-description"), head) && WeatherPronounAir(obj)) { /* "The air was cold." [cold air] * "It was freezing." [freezing pronoun-it-expletive] */ goto assertit; } return; assertit: ContextSetRSN(cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_TOTAL); AS(ts, 0L, L(head, grid, E)); }
Bool GetActorPair1(Obj *con, Obj *actor, int i, /* RESULTS */ Obj **counter_actor) { ObjList *members, *p, *counter_group; if (ISA(N("group"), I(con, i))) { members = GroupMembers(&TsNA, I(con, i)); if (ObjListIn(actor, members)) { counter_group = NULL; for (p = members; p; p = p->next) { if (p->obj == actor) continue; counter_group = ObjListCreate(p->obj, counter_group); } *counter_actor = GroupCreate(&TsNA, counter_group); ObjListFree(counter_group); ObjListFree(members); return(1); } ObjListFree(members); } return(0); }
void ContextOnAssert(TsRange *tsrange, Obj *assertion) { Discourse *dc; Context *cx; if (!(dc = ContextCurrentDc)) return; /* todoTHREAD: not thread safe */ /* Of course, the above = is correct. NOT == */ /* todo: Add this info to db. [affected-object-of off-hook phone] */ if (ISA(N("state"), I(assertion, 0))) { Dbg(DBGPLAN, DBGHYPER, "object state assertion", E); PA_ObjStateChange(tsrange, I(assertion, 1), 0); } else if (N("dial") == I(assertion, 0)) { /* todo: Perhaps dial should be a plan for a state [dialed-digits ]? Nah. */ PA_ObjStateChange(tsrange, I(assertion, 2), 0); } if (tsrange->cx == ContextRoot) { /* Root assertion gets run in all contexts. */ for (cx = dc->cx_alterns; cx; cx = cx->next) { DemonPtnTestAll(cx, assertion); } } else { /* Context assertion gets run only in that context. */ DemonPtnTestAll(tsrange->cx, assertion); } }
Bool IsActor(Obj *obj) { return(ISA(N("human"), obj) && obj != N("human") && (!ISA(N("group"), obj)) && (!IsInterrogative(obj))); }
/* 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); }
Bool UA_GoalDoesHandle(Obj *rel) { return(ISA(N("goal-status"), rel)); }
/* "Trix is silly" (TranslateS_AscriptiveAdj) * "Trix sat on the rug" (TranslateS_VerbPred) */ PNode *TranslateNPVP(PNode *pn, PNode *pnp, Obj *max, int srclang, int tgtlang, Discourse *dc) { int theta_filled[MAXTHETAFILLED]; PNode *vp; LexEntry *le_mainverb; Obj *comptense, *mood; ObjList *mainverbs, *p; PNode *r, *pn_mainverb, *pn_agreeverb; Arguments args; le_mainverb = NULL; comptense = mood = NULL; mainverbs = NULL; ArgumentsClear(&args); if (!ArgumentsAddSUBJ(pn->pn1, &args)) goto failure; vp = pn->pn2; while (vp) { if (PNodeIsCompoundTense(vp)) { TenseParseCompTense(vp, srclang, &pn_mainverb, &le_mainverb, &pn_agreeverb, &comptense, &mood, &args.adv1, &args.adv2, &args.adv3); if (le_mainverb == NULL) { Dbg(DBGSEMPAR, DBGBAD, "TranslateNPVP 1"); return(pn); } comptense = TranslateCompoundTense(comptense, srclang, tgtlang); mainverbs = TranslateGetAllcons(pn_mainverb, le_mainverb); vp = NULL; } else if (vp->pn2 == NULL) { vp = vp->pn1; } else if (vp->pn1->feature == F_VP && vp->pn2->feature == F_ADJP) { if (!ArgumentsAddADJP(vp->pn2, &args)) goto failure; vp = vp->pn1; } else if (vp->pn1->feature == F_VP && vp->pn2->feature == F_PP) { if (!ArgumentsAddIOBJ(vp->pn2, &args)) goto failure; vp = vp->pn1; } else if (vp->pn1->feature == F_VP && vp->pn2->feature == F_NP) { if (!ArgumentsAddOBJ(vp->pn2, &args)) goto failure; vp = vp->pn1; } else if (vp->pn1->feature == F_VERB && vp->pn2->feature == F_PRONOUN) { Dbg(DBGSEMPAR, DBGBAD, "TranslateNPVP VH should be transformed away?"); if (!ArgumentsAddOBJ(vp->pn2, &args)) goto failure; vp = vp->pn1; } else if (vp->pn1->feature == F_PRONOUN && vp->pn2->feature == F_VP) { Dbg(DBGSEMPAR, DBGBAD, "TranslateNPVP HW should be transformed away?"); if (!ArgumentsAddOBJ(vp->pn1, &args)) goto failure; vp = vp->pn2; } else if (vp->pn1->feature == F_ADVERB && vp->pn2->feature == F_VP) { /* But this doesn't preserve exact order. But that is OK. */ if (!ArgumentsAddPreAdv(vp->pn1, &args)) goto failure; vp = vp->pn2; } else if (vp->pn1->feature == F_VP && vp->pn2->feature == F_ADVERB) { if (!ArgumentsAddPostAdv(vp->pn2, &args)) goto failure; vp = vp->pn1; } else if (vp->pn1->feature == F_VP && vp->pn2->feature == F_EXPLETIVE) { vp = vp->pn1; } else if (vp->pn1->feature == F_VP && vp->pn2->feature == F_VP) { Dbg(DBGSEMPAR, DBGBAD, "TranslateNPVP WW?"); vp = vp->pn1; } else { vp = NULL; } } if (le_mainverb == NULL) { Dbg(DBGSEMPAR, DBGBAD, "TranslateNPVP 2"); return(pn); } r = NULL; ArgumentsToThetaFilled(&args, theta_filled); if (args.adjp_src) { if (mainverbs == NULL) { Dbg(DBGSEMPAR, DBGBAD, "TranslateNPVP: empty mainverbs"); mainverbs = ObjListCreate(N("standard-copula"), NULL); /* temporary */ } for (p = mainverbs; p; p = p->next) { if (ObjIsList(p->obj)) continue; if (!ISA(N("copula"), p->obj)) continue; /* todo: This is inefficent, because we retranslate components each time * through loop. Same below. */ r = TranslateS_AscriptiveAdj(pn, pnp, max, p->obj, le_mainverb, comptense, args.subjnp_src, args.adjp_src, theta_filled, srclang, tgtlang, r, dc); } } else { /* Intransitive (including neither obj nor iobj) and transitive verbs. */ for (p = mainverbs; p; p = p->next) { if (ObjIsList(p->obj)) continue; r = TranslateS_VerbPred(pn, pnp, max, p->obj, le_mainverb, comptense, &args, theta_filled, srclang, tgtlang, r, dc); } } if (r) return(r); failure: /* todo: In this case, prefer other translations besides this one. */ return(TranslateJuxtaposition(pn, pnp, max, NULL, srclang, tgtlang, dc)); }
Bool WeatherPronoun(Obj *obj) { return(ISA(N("pronoun-it-expletive"), obj) || ISA(N("pronoun-ce-expletive"), obj)); }
Bool IsInterrogative(Obj *obj) { return(ISA(N("interrogative-pronoun"), obj) || ISA(N("interrogative-adverb"), obj) || ISA(N("interrogative-determiner"), obj)); }
/****************************************************************************** * Examples: * a: Jim Jim Jim * other: Mary Mary Mary * in: [happy-for Jim Mary] [sorry-for J. M.] [gloating J. M.] * (positive-emotion) (negative-emotion) (positive-emotion) * attitude: like-human like-human like-human * weight: WEIGHT_DEFAULT WEIGHT_DEFAULT -WEIGHT_DEFAULT * o.e.c.: positive-emotion negative-emotion negative-emotion * att: [like-human J. M. WD] [like-human J. M. WD] [like-human J. M. * -WD] * * todo: Generalize this to work for all the related like/love attitudes as well * as friends/enemies relations. * The intensity rules are more complex: something like * value of actor2's emotion = value of actor1's emotion x * value of how much actor2 likes actor1. ******************************************************************************/ void UA_Emotion_FortunesOfOthers(Actor *ac, Ts *ts, Obj *a, Obj *in, Obj *other, Float weight, Obj *other_emot_class) { int found; Float weight1; Obj *other_emot_class1; ObjList *causes, *objs, *atts, *p, *q; /* Relate <a>'s emotion to <a>'s attitudes. */ if (0.0 != (weight1 = UA_FriendAttitude(ts, a, other, 1, &atts))) { if (FloatSign(weight1) == FloatSign(weight)) { /* The input emotion agrees with known attitudes. */ ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_HALF); ContextAddMakeSenseReasons(ac->cx, atts); } else { /* The input emotion disagrees with known attitudes. */ ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_LITTLE, NOVELTY_TOTAL); ContextAddNotMakeSenseReasons(ac->cx, atts); } } else { /* Attitude of <a> toward <other> is unknown. */ ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_MOSTLY, NOVELTY_MOSTLY); UA_Infer(ac->cx->dc, ac->cx, ts, L(N("like-human"), a, other, NumberToObj(weight), E), in); } /* Relate <a>'s emotion to <other>'s emotion. * found = <other>'s emotion implied by <a>'s emotion is already known, * excluding motivating emotions. */ objs = RD(ts, L(other_emot_class, other, E), 0); found = 0; for (p = objs; p; p = p->next) { if (ISA(N("motivation"), I(p->obj, 0))) continue; if ((causes = CAUSES(p->obj, ac->cx))) { for (q = causes; q; q = q->next) { if (!ISA(N("active-goal"), I(q->obj, 0))) { found = 1; ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_HALF); ContextAddMakeSenseReason(ac->cx, q->obj); } } } else { found = 1; ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_TOTAL, NOVELTY_HALF); ContextAddMakeSenseReason(ac->cx, p->obj); } ObjListFree(causes); } ObjListFree(objs); if (!found) { /* <other>'s emotion implied by <a>'s emotion is not yet known. */ ContextSetRSN(ac->cx, RELEVANCE_TOTAL, SENSE_MOSTLY, NOVELTY_MOSTLY); if (other_emot_class == N("positive-emotion")) { other_emot_class1 = N("happiness"); } else if (other_emot_class == N("negative-emotion")) { other_emot_class1 = N("sadness"); } else { other_emot_class1 = other_emot_class; } UA_Infer(ac->cx->dc, ac->cx, ts, L(other_emot_class1, other, NumberToObj(FloatAbs(weight)), E), in); } /* todo: Relate <a>'s emotion to <other>'s goal. */ }
Obj *SexOpposite(Obj *sex) { if (ISA(N("male"), sex)) return(N("female")); else return(N("male")); }