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 YMDHMSToTsComm(int day_of_the_week, int year, int month, int day, int hour, int min, int sec, /* RESULTS */ Ts *ts) { int actual_day_of_the_week; Obj *day_obj, *obj; TsRange tsr; ts->unixts = YMDHMSToUnixTs(year, month, day, hour, min, sec); ts->flag = 0; ts->cx = ContextRoot; if (day_of_the_week != DAYNA && day_of_the_week != (actual_day_of_the_week = TsToDay(ts))) { if ((day_obj = GenValueObj((Float)actual_day_of_the_week, N("day-of-the-week")))) { /* todo: To do this properly, full blown timestamp objects are needed, * which include a description of which components to generate. */ obj = L(N("standard-copula"), day_obj, E); TsRangeSetNever(&tsr); tsr.startts = *ts; tsr.stopts = *ts; ObjSetTsRange(obj, &tsr); CommentaryAdd(NULL, ObjListCreate(obj, NULL), N("current-date-without-day-request")); } } }
/****************************************************************************** * Example: * emotion: [pride Jim WEIGHT_DEFAULT] * goal: [succeeded-goal Jim [a-social-esteem Jim]] ******************************************************************************/ void UA_EmotionAdd(Actor *ac, Ts *ts, Obj *emotion, Obj *goal, Obj *action) { ac->emotions = ObjListCreate(emotion, ac->emotions); AS(ts, 0, emotion); if (action) LEADTO(ts, action, emotion); if (goal) LEADTO(ts, goal, emotion); }
ObjList *PNodeConceptsFor(PNode *pn, ObjList *concepts) { ObjList *r, *p; r = NULL; for (p = concepts; p; p = p->next) { if (p->u.sp.pn == pn) r = ObjListCreate(p->obj, r); r = PNodeConceptsFor1(pn, p->obj, r); } return(r); }
ObjList *ContextMapAssertions(Context *cx_parent, Context *cx_child, ObjList *objs_parent) { Obj *obj; ObjList *r, *p; r = NULL; for (p = objs_parent; p; p = p->next) { if ((obj = ContextMapAssertion(cx_parent, cx_child, p->obj))) { r = ObjListCreate(obj, r); } } return(r); }
ObjList *PNodeConceptsFor1(PNode *pn, Obj *con, ObjList *r) { int i, len; if (!ObjIsList(con)) return(r); for (i = 0, len = ObjLen(con); i < len; i++) { if (PNI(con, i) == pn) { r = ObjListCreate(I(con, i), r); } else { r = PNodeConceptsFor1(pn, I(con, i), r); } } return(r); }
ObjList *ObjListFileRead(char *filename) { FILE *instream; ObjList *objs; Obj *obj; if (NULL == (instream = StreamOpen(filename, "r"))) { return NULL; } objs = NULL; while ((obj = ObjRead(instream))) { objs = ObjListCreate(obj, objs); } return objs; }
ObjList *ContextFindGrids(Context *cx) { Actor *ac; Obj *polity, *grid; ObjList *r; GridCoord row, col; r = NULL; for (ac = cx->actors; ac; ac = ac->next) { if (SpaceLocateObject(NULL, &cx->story_time, ac->actor, NULL, 1, &polity, &grid, &row, &col)) { r = ObjListCreate(grid, r); } } return(r); }
ObjList *ContextSubgoals(Context *cx, Obj *subgoal_obj) { ObjList *r; Actor *ac; Subgoal *super, *sg; r = NULL; if ((super = ContextFindSubgoal(cx, subgoal_obj))) { for (ac = cx->actors; ac; ac = ac->next) { for (sg = ac->subgoals; sg; sg = sg->next) { if (sg->supergoal == super) r = ObjListCreate(sg->obj, r); } } } return(r); }
/* Find specific subgoal objectives unifying with pattern. */ ObjList *ContextFindMatchingSubgoals(Context *cx, Obj *subgoal_obj) { Actor *ac; Subgoal *sg; ObjList *r; r = NULL; for (ac = cx->actors; ac; ac = ac->next) { for (sg = ac->subgoals; sg; sg = sg->next) { if (ObjUnify(subgoal_obj, sg->obj)) { /* todoFREE: bd */ r = ObjListCreate(sg->obj, r); } } } return(r); }
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); }
/****************************************************************************** * This is called when a goal is activated, fails, or succeeds, in order to * generate the appropriate emotional response. * This is not called if the emotional response was already input. * Example: * in: [succeeded-goal Jim [a-social-esteem Jim]] * asserts: [pride Jim WEIGHT_DEFAULT] [leadto [succeeded-goal ...] * [pride ...]] * todo: Generate anger/gratitude. Goal importance determines emotion weight. ******************************************************************************/ void UA_EmotionGoal(Actor *ac, Ts *ts, Obj *a, Obj *goal, ObjList *causes) { int causing_actors_cnt; Float weight, weight1; Obj *goal_status, *objective, *actor, *emot_class, *emotion; ObjList *p, *causing_actors; goal_status = I(goal, 0); /* todo: Determine weight based on importance of goal. * Intrinsic importance of goal. * Dynamic importance of goal, such as whether an appointment was wanted. * For example, dentist appointments aren't normally wanted. */ weight = WEIGHT_DEFAULT; /* Generate anger/gratitude emotion(s). */ if ((emot_class = UA_Emotion_GStoAEC(goal_status))) { /* Figure out who besides self caused this goal failure. */ causing_actors = NULL; causing_actors_cnt = 0; for (p = causes; p; p = p->next) { actor = I(p->obj, 1); if (actor != a) { if (!ObjListIn(actor, causing_actors)) { causing_actors = ObjListCreate(actor, causing_actors); causing_actors->u.tgt_obj = p->obj; causing_actors_cnt++; } } } /* Divide up the anger/gratitude among the causing actors, * factoring in general attitude. * Examples: * A goal failure is caused by an actor <a> is neutral about: * Half the emotion is anger toward the actor. * Half the emotion is undirected. * A goal failure is caused by an actor <a> hates: * All of the emotion is anger toward the actor. * A goal failure is caused by an actor <a> loves: * All of the emotion is undirected. * A goal failure is caused by two actors <a> is neutral about: * One quarter of the emotion is anger toward actor1. * One quarter of the emotion is anger toward actor2. * Half the emotion is undirected. */ for (p = causing_actors; p; p = p->next) { if (weight < 0) break; weight1 = (weight*0.5*(1.0 - UA_FriendAttitude(ts, a, p->obj, 1, NULL)))/ causing_actors_cnt; emotion = L(emot_class, a, p->obj, D(weight1), E); weight -= weight1; UA_EmotionAdd(ac, ts, emotion, goal, p->u.tgt_obj); } } /* todo: Generate FortunesOfOthers emotions for other actors who * know about this goal outcome for <a>. Or just wait for them * to be stated? */ /* Generate undirected pos/neg emotion. */ if (weight > 0.0) { objective = I(goal, 2); emot_class = UA_Emotion_GSCtoEC(goal_status, I(objective, 0)); emotion = L(emot_class, a, D(weight), E); UA_EmotionAdd(ac, ts, emotion, goal, NULL); } }
/* "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)); }