/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* General instructions */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Consult flbc.pro ?- [flbc]. Run init ?- init. Run setup ?- setup. Use runThis/1 to observe how this system handles a specific KQML message; e.g., ?- runThis(tell). Use setQuiet(X) to change the amount of comments that are printed out. X=9 for most, X=1 for least. ?- setQuiet(9). */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Simulation management predicates */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ :- multifile(doThis/3). init :- dynamic(inBox/3), dynamic(quietLevel/1), dynamic(kb/2), dynamic(stdVocab/1), dynamic(stdVocab/3), dynamic(kqmlVocab/1), dynamic(kqmlVocab/3), dynamic(noun/1), dynamic(propositionCompatible/2), dynamic(xmlDef/3). setup :- setQuiet(9), init_gensym(t), init_gensym(m), init_gensym(var), setupDB. runThis(MsgType) :- testMsg(inBox(Who, Handled, flbcMsg(MsgType, What, Context))), asserta(inBox(Who, Handled, flbcMsg(MsgType, What, Context))), mms(Who), handleKB(Who). setupDB :- retractAllOldInfo, setupKB, setupPropCompatibleInfo, setupStdVocab, setupKQMLVocab, setupNounDictionary, setupStdVocab(end). retractAllOldInfo :- retractall(inBox(_, _, _)), retractall(propositionCompatible(_, _)), retractall(kb(_, _)), retractall(stdVocab(_)), retractall(stdVocab(_,_,_)), retractall(kqmlVocab(_)), retractall(kqmlVocab(_, _, _)), retractall(noun(_)), retractall(xmlDef(_, _, _)), !. setupKB :- assert(kb(person(123), isKnown(person(123, 'Scott')))), assert(kb(person(123), isKnown(person(234, 'Kenzie')))), assert(kb(person(123), isKnown(person(456, 'Nancy')))), assert(kb(person(123), isKnown(person(789, 'Lindsey')))), assert(kb(person(123), registered(person(123), thisMailList))), assert(kb(person(123), registered(person(234), thisMailList))), assert(kb(person(123), registered(person(456), thisMailList))), assert(kb(person(123), registered(person(456), thatMailList))), assert(kb(person(123), registered(person(789), thatMailList))), assert(kb(person(123), isAbleTo(deliver(person(123), person(234))))), assert(kb(person(123), isAbleTo(deliver(person(123), person(456))))), assert(kb(person(123), isAbleTo(process(person(234), request, do(person(234), registered(_, thisMailList)))))), assert(kb(person(123), isWillingTo(process(person(234), request, do(person(234), registered(_, thisMailList)))))), assert(kb(person(123), isAbleTo(process(person(789), request, do(person(789), registered(_, thisMailList)))))), /* have to have a generalRouter for each person */ assert(kb(person(123), generalRouter(person(789)))), !. setupNounDictionary :- assert(noun(thisMailList)), assert(noun(thatMailList)), assert(noun(otherMailList)), assert(noun(someAction)), !. handleAllMessages(H1) :- H = person(H1), flsas(H, DirMsg, IndirMsg), perlocutionaryEffects(H, DirMsg, IndirMsg), wrapUpMsg(H, DirMsg), fail. handleAllMessages(_) :- !. mms(person(H)) :- mms1(person(H)), !. mms(H1) :- H = person(H1), mms1(H), !. mms1(H) :- flsas(H, DirMsg, IndirMsg), perlocutionaryEffects(H, DirMsg, IndirMsg), wrapUpMsg(H, DirMsg). listKB(Who) :- kb(person(Who), X), debugMsg(2, [X]), fail. listKB(_). handleKB(person(H)) :- handleKB1(person(H)), !. handleKB(H) :- handleKB1(person(H)), !. handleKB1(Who) :- debugMsg(2, ['Handling KB']), getActiveProcessIDs(Who, ProcessIDList), debugMsg(9, [' ProcessIDs:', ProcessIDList]), handleKBForEachPID(Who, ProcessIDList). handleKBForEachPID(_Who, []) :- !. handleKBForEachPID(Who, [PID|RPID]) :- debugMsg(9, [' Handling KB for', PID]), getActionsForEachPID(PID, Actions1), debugMsg(6, ['Actions gathered for', PID]), debugMsg(8, Actions1), debugMsg(9, [' beginning to unify']), unifyVariables(Actions1, Actions), debugMsg(2, ['Beginning to do the actions for', PID]), doThese(Who, Actions), debugMsg(2, ['Done doing the actions for', PID]), !, handleKBForEachPID(Who, RPID). getActiveProcessIDs(Who, ProcessIDList) :- setof1(ProcessID, getActiveProcessIDs1(Who, ProcessID), ProcessIDList), !. getActiveProcessIDs(_, []) :- debugMsg(2, ['No active processes']), !. getActiveProcessIDs1(Who, ProcessID) :- kb(Who, do(ProcessID, Step, begin, _MsgID, Who, _What, _Var)), not kb(Who, do(ProcessID, Step, end, Who)). getActionsForEachPID(PID, Actions0) :- setof(do(PID, Step, OrigMsgID, Who, What, Variables), getActionsForEachPID1(PID, Step, OrigMsgID, Who, What, Variables), Actions0), !. getActionsForEachPID(_, []) :- !. getActionsForEachPID1(PID, Step, OrigMsgID, Who, What, Variables) :- kb(Who, do(PID, Step, begin, OrigMsgID, Who, What, Variables)), not kb(Who, do(PID, Step, end, Who)). doThese(_, []) :- !. doThese(Who, [do(ProcessID, Step, OMID, Who, What, Variables)|RActions]) :- debugMsg(6, ['Beginning to do an action']), debugMsg(9, [ProcessID, Step, Who, What]), doThis(Who, do(ProcessID, Step, OMID, Who, What, Variables)), addToKB(Who, do(ProcessID, Step, end, Who)), addToKB(Who, do(ProcessID, Step, end, Who, What, Variables)), !, debugMsg(6, ['Done doing an action']), doThese(Who, RActions). /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* FLSAS */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ flsas(H, DirMsg, IndirMsg) :- debugMsg(9, ['Entering flsas']), getFLSASsteps(H, DirMsg, IndirMsg, Steps), doFLSASsteps(H, Steps), debugMsg(9, ['Exiting flsas']). getFLSASsteps(Who, DirMsg, IndirMsg, [hearsMsg(Who, OriginalMsg), parseMsg(Who, OriginalMsg, ParsedMsg), spkrIsSaying(Who, OriginalMsg, ParsedMsg, IsSayingMsg), checkLocutionary(Who, OriginalMsg, IsSayingMsg, PossibleIlloc), evaluateDirect(Who, OriginalMsg, PossibleIlloc, DirMsg), evaluateIndirect(Who, OriginalMsg, ParsedMsg, DirMsg, IndirMsg)]). hearsMsg(Who, Msg, okay, _ErrorMsg, _Recover) :- /* simply retrieves msg from in-box */ retrieveNewMsg(Who, Msg), changeMsgStatus(Who, Msg, notHandled, startHandled). parseMsg(Who, Msg, Msg, Status, ErrorMsg, Recover) :- /* translates from a text string to a well-formed and valid XML flbcMsg document */ /* Since I'm currently working with Prolog terms, I can't do much with the "well-formed" portion. However, for the "valid" portion, I can ensure that I know the meaning of the terms in the message. */ checkBasicStructure(Who, Msg, Status1, ErrorMsg1, Recover1), ((Status1 = okay, substituteRefIntoMsg(Msg, Msg1), knowMeaningOfTerms(Who, Msg1, Status, ErrorMsg, Recover)) ; (Status1 \= okay, Status = Status1, Recover = Recover1, append(['Formatting problem with this msg:', Status, nl, 'Msg:', Msg, nl], ErrorMsg1, ErrorMsg))). spkrIsSaying(Who, _OriginalMsg, Msg, Msg1, Status, ErrorMsg, Recover) :- /* identifies referents in the message; ensures that hearer can identify them; flags other obvious errors */ substituteRefIntoMsg(Msg, Msg1), ensureReferentsKnown(Who, Msg1, Status, ErrorMsg, Recover). /* determines a possible illocutionary act from what is said and its context; also verifies that the proposition is compatible with the force */ checkLocutionary(Who, _OriginalMsg, Msg, Msg, Status, ErrorMsg, Recover) :- /* simple case */ Msg = flbcMsg(MsgID, simpleAct(From, _, IllocAct), _), checkPropCompatible(IllocAct, Who, MsgID, From, okay, Status, ErrorMsg, Recover). /* determines the unambiguous meaning of the illocutionary act; determines if this meaning is possible */ evaluateDirect(_Who, _OriginalMsg, X, X, _Status, _ErrorMsg, _Recover) :- !. evaluateIndirect(_Who, _OriginalMsg, _, _, none, _Status, _ErrorMsg, _Recover) :- !. wrapUpMsg(H, Msg) :- assert(inBox(H, endHandled, Msg)), !. perlocutionaryEffects(H, Direct, none) :- debugMsg(2, ['Beginning perlocutionary effects']), debugMsg(9, [Direct]), substituteRefIntoMsg(Direct, Msg), standardEffects(H, Msg), extendedEffects(H, Msg), debugMsg(2, ['Ending perlocutionary effects']), !. standardEffects(H, Msg) :- debugMsg(2, ['Beginning standard effects']), debugMsg(9, [H, Msg]), standardEffects(H, Msg, Effects), debugMsg(2, ['Standard effects found']), execEffects(Effects), debugMsg(2, ['Standard effects executed']). extendedEffects(_H, _Direct) :- /* I think this is where I'd put my conversation management stuff */ !. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Standard effects (never change) */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ getReplyTo(Spkr, [], Spkr) :- !. getReplyTo(_, [replyTo(ReplyTo)|_], ReplyTo) :- !. getReplyTo(Spkr, [_|Rest], ReplyTo) :- !, getReplyTo(Spkr, Rest, ReplyTo). /* These first two are simply to handle messages with any force that has an "and" content */ standardEffects(_H, flbcMsg(_ID, simpleAct(_Spkr, _Hearer, illocAct(_Force, and([]))), _Context), []). standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(Force, and([FR|RR]))), Context), Effects) :- standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(Force, FR)), Context), TheseEffects), standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(Force, and(RR))), Context), RestOfEffects), append(TheseEffects, RestOfEffects, Effects). /* These next two are to handle messages that have a series of forces and associated contents */ standardEffects(_, flbcMsg(_, simpleAct(_, _, and([])), _), []) :- !. standardEffects(Who, flbcMsg(ID, simpleAct(Spkr, Hearer, and([First|Rest])), Context), Effects) :- standardEffects(Who, flbcMsg(ID, simpleAct(Spkr, Hearer, First), Context), Effects1), standardEffects(Who, flbcMsg(ID, simpleAct(Spkr, Hearer, and(Rest)), Context), Effects2), append(Effects1, Effects2, Effects), !. /* Inform */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(inform, believes(Spkr, C))), _Context), [considerForKB(H, believes(Spkr, C), ID), considerForKB(H, believes(Spkr, not believes(Hearer, C)), ID), considerForKB(H, wants(Spkr, believes(Hearer, C)), ID)]). /* Inform...not */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(inform, not believes(Spkr, C))), _Context), [considerForKB(H, believes(Spkr, not believes(Spkr, C)), ID), considerForKB(H, believes(Spkr, not believes(Hearer, not believes(Spkr, C))), ID), considerForKB(H, wants(Spkr, believes(Hearer, not believes(Spkr, C))), ID)]). /* Asserts */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(asserts, C)), _Context), [considerForKB(H, believes(Spkr, C), ID), considerForKB(H, wants(Spkr, believes(Hearer, C)), ID)]). /* Describe */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(describe, is(Obj, F))), _Context), [considerForKB(H, believes(Spkr, is(Obj, F)), ID), considerForKB(H, wants(Spkr, believes(Hearer, is(Obj, F))), ID)]). /* Retract */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(retract, C)), _Context), [considerForKB(H, not believes(Spkr, C), ID), considerForKB(H, believes(Spkr, believes(Hearer, time(before(now), believes(Spkr, C)))), ID), considerForKB(H, wants(Spkr, not believes(Hearer, C)), ID)]). /* Dispute */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(dispute, C)), _Context), [considerForKB(H, not believes(Spkr, C), ID), considerForKB(H, believes(Spkr, believes(Hearer, C)), ID), considerForKB(H, wants(Spkr, not believes(Hearer, C)), ID)]). /* Denial */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(denial, C)), _Context), [considerForKB(H, believes(Spkr, not C), ID), considerForKB(H, believes(Spkr, not believes(Hearer, not C)), ID), considerForKB(H, wants(Spkr, believes(Hearer, not C)), ID)]). /* Question */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(question, isTrueFalse(Q))), Context), [considerForKB(H, wants(Spkr, do(H, determine(isTrueFalse(Q), TruthValue))), ID), considerForKB(H, wants(Spkr, do(H, sendMsg(flbcMsg(simpleAct(Hearer, ReplyTo, illocAct(inform, TruthValue)), [respondingTo(ID)])))), ID)]) :- getReplyTo(Spkr, Context, ReplyTo). /* Promise */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(promise, do(Spkr, What))), _Context), [considerForKB(H, believes(Spkr, obligated(Spkr, do(Spkr, What))), ID), considerForKB(H, wants(Spkr, do(Spkr, What)), ID), considerForKB(H, believes(Hearer, obligated(Spkr, do(Spkr, What))), ID)]). /* Request */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(request, What)), _Context), [considerForKB(H, wants(Spkr, do(Hearer, What)), ID), considerForKB(H, wants(Spkr, wants(Hearer, do(Hearer, What))), ID)]). /* Report */ standardEffects(H, flbcMsg(ID, simpleAct(Spkr, Hearer, illocAct(report, time(T, C))), _Context), [considerForKB(H, believes(Spkr, time(T, C)), ID), considerForKB(H, wants(Spkr, believes(Hearer, time(T, C))), ID)]). /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* General FLBC vocabulary terms */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ setupPropCompatibleInfo :- assert(propositionCompatible(question, isTrueFalse(_))), assert(propositionCompatible(request, do(_, _))), assert(propositionCompatible(request, undo(_, _))), assert(propositionCompatible(inform, believes(_, _))), assert(propositionCompatible(inform, not believes(_, _))), assert(propositionCompatible(denial, _)), assert(propositionCompatible(asserts, _)), assert(propositionCompatible(retract, _)), assert(propositionCompatible(dispute, _)), assert(propositionCompatible(describe, is(_, _))), assert(propositionCompatible(promise, do(_, _))), assert(propositionCompatible(report, time(before(_), _))), !. setupStdVocab(end) :- assert(:-(xmlDef(T, none, alwaysEmpty), atomic(T))), assert(xmlDef([F|R], none, [list([F|R])])), /* assert(:-(xmlDef([F|R], none, Result), (xmlDef([F|R], none, [], Result)))), */ assert(xmlDef(Z, none, [Z])), !. setupStdVocab :- assert(:-(stdVocab(I),integer(I))), assert(stdVocab(true)), assert(stdVocab(false)), assert(stdVocab(now)), /* stdVocab(Functor/Args, Term, vi(ValidationInfo, Status, ErrorMsg)) */ assert(stdVocab((:)/2, _, normal)), assert(stdVocab(and/1, _, normal)), assert(stdVocab(believes/2, _, normal)), assert(stdVocab((not)/1, _, normal)), assert(stdVocab(person/1, _, noValidation)), assert(stdVocab(do/2, _, normal)), assert(stdVocab(time/2, _, normal)), assert(stdVocab(before/1, _, normal)), assert(stdVocab(isTrueFalse/1, _, normal)), assert(stdVocab(resources/1, _, normal)), assert(stdVocab(actors/1, _, normal)), assert(stdVocab(determine/2, _, normal)), assert(stdVocab(sendMsg/1, _, normal)), assert(stdVocab(respondingTo/1, respondingTo(_ID), noValidation)), /* respondingTo could be validated by ensuring that ID is a valid message ID */ assert(stdVocab(believes/2, _, normal)), assert(stdVocab(flbcMsg/3, _, normal)), assert(stdVocab(flbcMsg/2, _, normal)), assert(stdVocab(illocAct/2, illocAct(F, C), vi([knowMeaningOfForce(F, Status1, ErrorMsg1), knowMeaningOfTerm(C, Status1, ErrorMsg1, Status, ErrorMsg)], Status, ErrorMsg))), assert(stdVocab(simpleAct/3, _, normal)), assert(stdVocab(var/1, _, noValidation)), assert(stdVocab(ref/2, ref(_, B), vi([knowMeaningOfTerm(B, okay, none, Status, ErrorMsg)], Status, ErrorMsg))), assert(stdVocab(correct/1, _, normal)), assert(stdVocab(format/1, _, normal)), assert(stdVocab(msg/1, _, noValidation)), assert(stdVocab(arg/2, _, normal)), assert(stdVocab(is/2, _, normal)), assert(stdVocab(propositionCompatible/2, propositionCompatible(F, C), vi([knowMeaningOfForce(F, Status1, ErrorMsg1), knowMeaningOfTerm(C, Status1, ErrorMsg1, Status, ErrorMsg)], Status, ErrorMsg))), assert(stdVocab(bitBucket/1, _, noValidation)), assert(stdVocab(replyTo/1, _, normal)), assert(:-(xmlDef(Var, none, alwaysEmpty), var(Var))), assert(xmlDef(flbcMsg(SimpleAct, Context), none, [SimpleAct, context(Context)])), assert(xmlDef(flbcMsg(ID, SimpleAct, Context), [arg(msgID, ID)], [SimpleAct, context(Context)])), assert(xmlDef(simpleAct(From, To, and(IllocActs)), [arg(speaker, From), arg(hearer, To)], IllocActs)), assert(xmlDef(simpleAct(From, To, IllocAct), [arg(speaker, From), arg(hearer, To)], [IllocAct])), assert(xmlDef(illocAct(Force, and(Contents)), [arg(force, Force)], Contents)), assert(xmlDef(illocAct(Force, Content), [arg(force, Force)], [Content])), assert(xmlDef(and(A), none, A)), assert(xmlDef(list(A), none, A)), assert(xmlDef(context(What), none, What)), assert(xmlDef(believes(Who, What), [arg(who, Who)], [What])), assert(xmlDef(not(A), none, [A])), assert(xmlDef(person(ID), [arg(id, ID)], alwaysEmpty)), assert(xmlDef(do(Who, What), [arg(who, Who)], [What])), assert(xmlDef(time(When, What), none, [When, What])), assert(xmlDef(before(When), none, [When])), assert(xmlDef(isTrueFalse(What), none, [What])), assert(xmlDef(resources(What), none, What)), assert(xmlDef(actors(Who), none, Who)), assert(xmlDef(determine(What, Value), none, [What, Value])), assert(xmlDef(sendMsg(Msg), none, [Msg])), assert(xmlDef(respondingTo(What), [arg(id, What)], alwaysEmpty)), assert(xmlDef(replyTo(Whom), [arg(toWhom, Whom)], alwaysEmpty)), assert(xmlDef(var(TheVar), [arg(name, TheVar)], alwaysEmpty)), assert(xmlDef(ref(ID, ReferTo), [arg(id, ID)], [ReferTo])), assert(xmlDef(correct(What), none, [What])), assert(xmlDef(format(What), none, [What])), assert(xmlDef(msg(ID), [arg(id, ID)], alwaysEmpty)), assert(xmlDef(arg(Which, OfWhat), [arg(num, Which)], [OfWhat])), assert(xmlDef(is(Who, What), none, [Who, What])), assert(xmlDef(propositionCompatible(Force, Content), [arg(force, Force)], [Content])), assert(xmlDef(A:B, none, [A, ':', B])), !. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Predicates specific to KQML vocabulary */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ setupKQMLVocab :- assert(kqmlVocab(registered/2, _, normal)), assert(kqmlVocab(findValue/3, _, normal)), assert(kqmlVocab(truthStatus/2, _, normal)), assert(kqmlVocab(evaluate/2, _, normal)), assert(kqmlVocab(complete/1, _, normal)), assert(kqmlVocab(undo/2, _, normal)), assert(kqmlVocab(subscribe/2, _, normal)), assert(kqmlVocab(process/2, _, normal)), assert(kqmlVocab(physicalAddr/1, _, noValidation)), assert(kqmlVocab(emailAddr/1, _, noValidation)), assert(kqmlVocab(forward/3, _, normal)), assert(kqmlVocab(forwardedBy/1, _, normal)), assert(kqmlVocab(forwardResponse/2, _, normal)), assert(kqmlVocab(isAbleTo/1, _, normal)), assert(kqmlVocab(isWillingTo/1, _, normal)), assert(kqmlVocab(deliver/2, _, normal)), assert(kqmlVocab(maintains/2, _, normal)), assert(kqmlVocab(process/3, process(A, B, C), vi([knowMeaningOfForce(B, Status1, ErrorMsg1), knowMeaningOfTerm(A, Status1, ErrorMsg1, Status2, ErrorMsg2), knowMeaningOfTerm(C, Status2, ErrorMsg2, Status, ErrorMsg)], Status, ErrorMsg))), assert(kqmlVocab(all)), assert(kqmlVocab(one)), assert(kqmlVocab(identify)), assert(kqmlVocab(notIdentify)), assert(xmlDef(registered(Who, What), [arg(who, Who)], [What])), assert(xmlDef(findValue(HowMany, What, DoThis), [arg(howMany, HowMany)], [What, DoThis])), assert(xmlDef(truthStatus(TF, Term), [arg(truthStatus, TF)], [Term])), assert(xmlDef(evaluate(What, Result), none, [What, Result])), assert(xmlDef(complete(What), none, [What])), assert(xmlDef(undo(Who, What), [arg(who, Who)], [What])), assert(xmlDef(subscribe(Who, What), [arg(who, Who)], [What])), assert(xmlDef(process(Who, What), [arg(who, Who)], [What])), assert(xmlDef(physicalAddr(Addr), none, [Addr])), assert(xmlDef(emailAddr(Addr), [arg(addr, Addr)], alwaysEmpty)), assert(xmlDef(forward(ToWhom, Identify, What), [arg(toWhom, ToWhom), arg(identify, Identify)], [What])), assert(xmlDef(forwardedBy(Whom), [arg(whom, Whom)], alwaysEmpty)), assert(xmlDef(forwardResponse(What, ToWhom), [arg(toWhom, ToWhom)], [What])), assert(xmlDef(isAbleTo(What), none, [What])), assert(xmlDef(isWillingTo(What), none, [What])), assert(xmlDef(deliver(Who, ToWhom), [arg(who, Who), arg(toWhom, ToWhom)], alwaysEmpty)), assert(xmlDef(maintains(Who, What), [arg(who, Who)], [What])), assert(xmlDef(process(Who, Force, Content), [arg(who, Who), arg(force, Force)], [Content])), !. getValues(one, [[F]|_], F) :- !. getValues(one, [[F|R]|_], [F|R]) :- !. getValues(one, [F|_], F) :- !. getValues(one, [], none) :- !. getValues(all, X, X) :- !. sendToAll([], _, _) :- !. sendToAll([SendTo|R], Who, do(PID, Step, OMID, Who, do(CurrentIntermediary, forward(flbcMsg(simpleAct(Originator, EventualRecipient, IllocAct), InnerContext))), V)) :- doThis(Who, do(PID, Step, OMID, Who, do(CurrentIntermediary, sendMsg(flbcMsg(simpleAct(CurrentIntermediary, SendTo, IllocAct), InnerContext))), V)), !, sendToAll(R, Who, do(PID, Step, OMID, Who, do(CurrentIntermediary, forward(flbcMsg(simpleAct(Originator, EventualRecipient, IllocAct), InnerContext))), V)). sendMsgsForResponse(_, do(_, _, _, _, do(_, [])), _, _) :- !. sendMsgsForResponse(Who, do(PID, Step, OMID, Who, do(Who, [flbcMsg(simpleAct(From, To, IA), Context)|RM])), ToWhom, Var) :- doThis(Who, do(PID, Step, OMID, Who, do(Who, sendMsg(flbcMsg(ID, simpleAct(From, To, IA), Context))), Var)), getNewStep(Who, PID, NewStep), execThisEffect(considerForKB(From, wants(From, do(From, sendResponse(msg(ID), ToWhom))), OMID), PID, NewStep, Var), !, sendMsgsForResponse(Who, do(PID, Step, OMID, Who, do(Who, RM)), ToWhom, Var). getForwardAddressee(Who, all, SendToList) :- setof1(ToWhom, kb(Who, isAbleTo(deliver(Who, ToWhom))), SendToList1), ((SendToList1 = [], kb(Who, generalRouter(SendTo)), SendToList = [SendTo]) ; (SendToList1 \= [], SendToList = SendToList1)), !. getForwardAddressee(Who, Someone, [Someone]) :- kb(Who, isAbleTo(deliver(Who, Someone))), !. getForwardAddressee(Who, Someone, [SendTo]) :- not kb(Who, isAbleTo(deliver(Who, Someone))), kb(Who, generalRouter(SendTo)), !. sendForwardedMsgs(_, do(_, _, _, _, do(_, []), _)) :- !. sendForwardedMsgs(Who, do(PID, Step, OMID, Who, do(Forwarder, [FM|RM]), V)) :- doThis(Who, do(PID, Step, OMID, Who, do(Forwarder, sendMsg(FM)), V)), !, sendForwardedMsgs(Who, do(PID, Step, OMID, Who, do(Forwarder, RM), V)). createForwardedMsgs(forward(_:[], _), X, X) :- !. createForwardedMsgs(forward(Identifiers:[FValues|RValues], FLBCMsg), Temp, ForwardedMsgs) :- ((Identifiers = [_|_], Identifiers1 = Identifiers) ; (Identifiers \= [_|_], Identifiers1 = [Identifiers])), substituteInTerm(Identifiers1, FValues, FLBCMsg, NewFLBCMsg), !, createForwardedMsgs(forward(Identifiers:RValues, FLBCMsg), [NewFLBCMsg|Temp], ForwardedMsgs). getSetValues(VarWhat, kb(Who, [F|R]), SortSet) :- setof1(VarWhat, kb(Who, F), NewInfo), getSetValues(VarWhat, kb(Who, R), NewInfo, SortSet), !. getSetValues(VarWhat, kb(Who, What), SortSet) :- What \= [_|_], setof1(VarWhat, kb(Who, What), Set), sort(Set, SortSet), !. getSetValues(_, _, [], []) :- !. getSetValues(_, kb(_, []), X, X) :- !. getSetValues(VarWhat, kb(Who, [F|R]), Temp, SortSet) :- setof1(VarWhat, kb(Who, F), NewInfo1), intersect(Temp, NewInfo1, NewTemp), !, getSetValues(VarWhat, kb(Who, R), NewTemp, SortSet). getNewStep(Who, PID, NewStep) :- setof1(Step, kb(Who, do(PID, Step, begin, _, Who, _What, _V)), Steps), getMax(Steps, MaxStep), NewStep is MaxStep + 1, !. doThis(Who, do(_PID, _Step, _OMID, Who, determine(isTrueFalse(Q), TruthValue), _V)) :- /* Here I'm assuming that "Q" is in the agent's vocabulary. */ /* This would be okay if it were translated in the FLSAS. */ /* Otherwise, this is not vocabulary specific. */ debugMsg(6, ['doThis 1']), ((kb(Who, Q), TruthValue=true) ; (TruthValue=false)), debugMsg(1, ['Truth of', Q, 'determined as', TruthValue]), !. doThis(Who, do(PID, Step, OMID, Who, do(Who, forward(To, Identify, flbcMsg(simpleAct(From, To, IllocAct), Context))), V)) :- /* this predicate is for the case when the person who is to receive the message is the person to whom the message is addressed */ debugMsg(6, ['doThis 2']), inBox(Who, _, flbcMsg(OMID, Content, OuterContext1)), substituteRefIntoMsg(flbcMsg(OMID, Content, OuterContext1), flbcMsg(OMID, _, OuterContext2)), /* I'm not sure about using replyTo() but I'm sure that I should use forwardedBy() */ getMatches([forwardedBy(_), replyTo(_)], OuterContext2, OuterContext3), ((Identify = identify, append(OuterContext3, [forwardedBy(Who)], OuterContext4)) ; (Identify = notIdentify, OuterContext4 = OuterContext3)), append(OuterContext4, Context, NewContext), doThis(Who, do(PID, Step, OMID, Who, do(Who, sendMsg(flbcMsg(_, simpleAct(From, To, IllocAct), NewContext))), V)). doThis(Who, do(PID, Step, OMID, Who, do(CurrentIntermediary, forward(Identifiers:Values, Identify, FLBCMsg)), V)) :- debugMsg(6, ['doThis 2a']), FLBCMsg = flbcMsg(IllocAct, Context), ((Identify = identify, append(Context, [forwardedBy(CurrentIntermediary)], NewContext)) ; (Identify = notIdentify, NewContext = Context)), createForwardedMsgs(forward(Identifiers:Values, flbcMsg(IllocAct, NewContext)), [], ForwardedMsgs), sendForwardedMsgs(Who, do(PID, Step, OMID, Who, do(CurrentIntermediary, ForwardedMsgs), V)). doThis(Who, do(PID, Step, OMID, Who, do(Who, forwardResponse(sendMsg(flbcMsg(simpleAct(From, Identifiers:Values, IllocAct), Context)), ToWhom)), Var)) :- debugMsg(6, ['doThis 3a']), createForwardedMsgs(forward(Identifiers:Values, flbcMsg(simpleAct(From, Identifiers, IllocAct), Context)), [], ForwardedMsgs), sendMsgsForResponse(Who, do(PID, Step, OMID, Who, do(Who, ForwardedMsgs)), ToWhom, Var). doThis(Who, do(PID, Step, OMID, Who, do(Who, forwardResponse(sendMsg(flbcMsg(simpleAct(From, To, IllocAct), Context)), ToWhom)), Var)) :- /* 1 Notice here that To will receive a message from From, and To will not know that ToWhom is who really asked for the information in the first place. 2 Also notice that ToWhom will not know that To is the person responding to ToWhom. 3 ToWhom will also not know that the message is going to even be sent to To in the first place */ debugMsg(6, ['doThis 3b']), doThis(Who, do(PID, Step, OMID, Who, do(Who, sendMsg(flbcMsg(ID, simpleAct(From, To, IllocAct), Context))), Var)), /* the above says to send the IllocAct with Context to To and have it be from From */ getNewStep(Who, PID, NewStep), execThisEffect(considerForKB(From, wants(From, do(From, sendResponse(msg(ID), ToWhom))), OMID), PID, NewStep, Var). /* the above says to send the response to ID (the message sent according to the previous predicate) to ToWhom */ doThis(Who, do(PID, Step, OMID, Who, do(Who, forward(Someone, _Identify, flbcMsg(simpleAct(From, To, IllocAct), Context))), V)) :- Someone \= To, debugMsg(6, ['doThis 4']), getForwardAddressee(Who, Someone, SendTo), sendToAll(SendTo, Who, do(PID, Step, OMID, Who, do(Who, forward(flbcMsg(simpleAct(From, To, IllocAct), Context))), V)). doThis(Who, do(_PID, _Step, _OMID, Who, do(Who, evaluate(believes(Who, findValue(HowMany, What, truthStatus(true, Term))), RetVal)), _V)) :- /* Here I'm assuming that "Term" is in the agent's vocabulary. */ /* This would be okay if it were translated in the FLSAS. */ /* Otherwise, this is not vocabulary specific. */ debugMsg(6, ['Evaluating believe', What, Term]), createVarTerms(What, Term, VarWhat, VarTerm), setof1(VarWhat, kb(Who, VarTerm), Set), getValues(HowMany, Set, RetVal), debugMsg(1, ['The value has been determined:', RetVal]), !. doThis(Who, do(_PID, _Step, _OMID, Who, do(Who, evaluate(believes(Who, findValue(HowMany, What, DoThis)), RetVal)), _V)) :- /* Here I'm assuming that "DoThis" is in the agent's vocabulary. */ /* This is okay since the FLSAS verified this to begin with. */ debugMsg(6, ['Evaluating believe', What, DoThis]), createVarTerms(What, DoThis, VarWhat, VarTerm), getSetValues(VarWhat, kb(Who, VarTerm), Set), getValues(HowMany, Set, RetVal), debugMsg(1, ['The value has been determined:', RetVal]), !. /* illocAct(dispute, registered(a, thisMailList)) */ doThis(Who, do(_PID, _Step, _OMID, Who, undo(Who, simpleAct(_From, Who, illocAct(dispute, What))), _V)) :- debugMsg(6, ['doThis 13a']), ((kb(Who, removedFromKB(Who, What)), removeFromKB(Who, removedFromKB(Who, What)), addToKB(Who, What)) ; (not kb(Who, removedFromKB(Who, What)))), /* nothing to remove*/ debugMsg(1, [What, 'is no longer removed from the database. It has been added back.']), !. doThis(Who, do(_PID, _Step, _OMID, Who, undo(Who, registered(Who, What)), _V)) :- debugMsg(6, ['doThis 7']), ((kb(Who, registered(Who, What)), removeFromKB(Who, registered(Who, What))) ; (not kb(Who, registered(Who, What)) /* nothing to remove*/)), debugMsg(1, ['It is now NOT the case that', registered(Who, What)]), !. doThis(Who, do(_PID, _Step, _OMID, Who, do(Who, registered(Who, What)), _V)) :- debugMsg(6, ['doThis 8']), ((kb(Who, registered(Who, What)) /* could respond */) ; (not kb(Who, registered(Who, What)), addToKB(Who, registered(Who, What)))), debugMsg(1, ['It is now the case that', registered(Who, What)]), !. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* General predicates for handling messages */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* could set Who if actions for one agent are different than for another */ doThis(_Who, do(_, _, _, _, and([]), _)) :- debugMsg(9, [' and action completed']), !. doThis(Who, do(PID, Step, OMID, Who, and([F|R]), Var)) :- debugMsg(9, [' Doing an and action']), debugMsg(9, [PID, Step, Who, F, Var]), doThis(Who, do(PID, Step, OMID, Who, F, Var)), debugMsg(9, [' Done with an and action']), !, doThis(Who, do(PID, Step, OMID, Who, and(R), Var)). doThis(Who, do(PID, Step, OMID, Who, do(Who, sendMsg(flbcMsg(simpleAct(From, To, IllocAct), Context))), Var)) :- messageID(NewID), debugMsg(6, ['doThis 10']), doThis(Who, do(PID, Step, OMID, Who, do(Who, sendMsg(flbcMsg(NewID, simpleAct(From, To, IllocAct), Context))), Var)), !. doThis(Who, do(PID, Step, OMID, Who, sendMsg(flbcMsg(simpleAct(From, To, IllocAct), Context)), Var)) :- debugMsg(6, ['doThis 11']), doThis(Who, do(PID, Step, OMID, Who, do(Who, sendMsg(flbcMsg(_, simpleAct(From, To, IllocAct), Context))), Var)). doThis(Who, do(_PID, _Step, OMID, Who, do(Who, sendMsg(flbcMsg(ID, simpleAct(From, To, IllocAct), Context))), _Var)) :- /* This is just a dummy predicate but the actual thing shouldn't be that much more complicated */ debugMsg(6, ['Attempting to send a message']), ((var(ID), messageID(ID)) ; (true)), ((inBox(Who, _, flbcMsg(OMID, Content, Context1)), substituteRefIntoMsg(flbcMsg(OMID, Content, Context1), flbcMsg(OMID, _, Context2))) ; (Context2 = [])), debugMsg(9, ['to', To, 'Context2', Context2]), getReplyTo(To, Context2, ReplyTo), debugMsg(9, ['replyto', ReplyTo]), debugMsg(1, ['Message', ID, 'sent from', From, 'to', ReplyTo]), assert(inBox(ReplyTo, notHandled, flbcMsg(ID, simpleAct(From, To, IllocAct), Context))), displayIllocActs(IllocAct), append([' Ctxt: '], Context, DebugContext), debugMsg(9, DebugContext), !. doThis(Who, do(_PID, _Step, _OMID, Who, undo(Who, WhatIsRequestedUnDone), _V)) :- debugMsg(6, ['doThis 13']), ((kb(Who, WhatIsRequestedUnDone), removeFromKB(Who, WhatIsRequestedUnDone)) ; (not kb(Who, WhatIsRequestedUnDone) /* nothing to remove*/)), debugMsg(1, ['It is now NOT the case that', WhatIsRequestedUnDone]), !. doThis(Who, do(_PID, _Step, _OMID, Who, do(Who, WhatIsRequestedDone), _V)) :- debugMsg(6, ['doThis 14']), ((kb(Who, WhatIsRequestedDone) /* could respond */) ; (not kb(Who, WhatIsRequestedDone), addToKB(Who, WhatIsRequestedDone))), debugMsg(1, ['It is now the case that', WhatIsRequestedDone]), !. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Support predicates specific to the FLSAS */ /* Not specific to this vocabulary but needed to run the FLSAS */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ doFLSASsteps(Who, Steps) :- doFLSASsteps1(Who, Steps, okay, _EndStatus, _ErrorMsg, _Recover). doFLSASsteps1(_, [], _, okay, none, none) :- !. doFLSASsteps1(Who, [Step|Rest], okay, _EndStatus, _ErrorMsg, _Recover) :- Step =.. Step1, beginningStep(Step1), append(Step1, [EndStatus, ErrorMsg, Recover], Step2), StepToExecute =.. Step2, debugMsg(9, [StepToExecute]), call(StepToExecute), endingStep(Step1), !, doFLSASsteps1(Who, Rest, EndStatus, _NextEndStatus, ErrorMsg, Recover). doFLSASsteps1(Who, [Step|_], NotOKAY, _, ErrorMsg, Recover) :- NotOKAY \= okay, !, debugMsg(1, ['Problem in FLSAS:', NotOKAY]), debugMsg(1, ErrorMsg), getMsgFromStep(Msg, Step), changeMsgStatus(Who, Msg, startHandled, discard(badFormat)), execEffects(Recover). beginningStep([Name|_]) :- debugMsg(9, ['Entering', Name]). endingStep([Name|_]) :- debugMsg(9, ['Ending', Name]). getMsgFromStep(Msg, hearsMsg(_, Msg)). getMsgFromStep(Msg, parseMsg(_, Msg, _)). getMsgFromStep(Msg, spkrIsSaying(_, Msg, _, _)). getMsgFromStep(Msg, checkLocutionary(_, Msg, _, _)). getMsgFromStep(Msg, evaluateDirect(_, Msg, _, _)). getMsgFromStep(Msg, evaluateIndirect(_, Msg, _, _, _)). changeMsgStatus(H, Msg, OldStatus, NewStatus) :- retract(inBox(H, OldStatus, Msg)), assert(inBox(H, NewStatus, Msg)), !. retrieveNewMsg(H, Msg) :- inBox(H, notHandled, Msg), not inBox(H, endHandled, Msg). checkBasicStructure(_, flbcMsg(_, simpleAct(_, _, illocAct(_, _)), _), okay, _, _). checkBasicStructure(_, flbcMsg(MsgID, simpleAct(From, _, and(List)), _), Status, ErrorMsg, Recover) :- debugMsg(9, ['Checking illocutionary structure']), checkIllocStructure(List, MsgID, From, Status, ErrorMsg, Recover), !. checkBasicStructure(Who, flbcMsg(MsgID, simpleAct(From, _To, _X), _), badFormat(simpleAct(arg3)), ['Argument 3 of simpleAct() is not formatted correctly.'], [considerForKB(Who, believes(Who, not correct(format(arg(3, arg(2, msg(MsgID)))))), MsgID), considerForKB(Who, wants(Who, do(Who, sendMsg(flbcMsg(simpleAct(Who, From, illocAct(inform, believes(Who, not correct(format(arg(3, arg(2, msg(MsgID)))))))), [respondingTo(MsgID)])))), MsgID)]). checkBasicStructure(Who, flbcMsg(MsgID, _X, _), badFormat(arg2), ['Argument 2 of flbcMsg() is not formatted correctly.'], [considerForKB(Who, believes(Who, not correct(format(arg(2, msg(MsgID))))), MsgID)]). checkBasicStructure(Who, Msg, badFormat(topLevel), ['The message', Msg, 'is not formatted correctly.'], [considerForKB(Who, believes(Who, not correct(format(Msg))), incomingMsg)]). checkIllocStructure([], _, _, okay, _, _) :- !. checkIllocStructure([illocAct(_, _)|Rest], MsgID, From, Status, ErrorMsg, Recover) :- checkIllocStructure(Rest, MsgID, From, Status, ErrorMsg, Recover). checkIllocStructure([F|_], MsgID, From, badFormat(simpleAct(arg3)), ['Argument 3 of simpleAct() is not formatted correctly.'], [considerForKB(Who, believes(Who, not correct(format(arg(3, arg(2, msg(MsgID)))))), MsgID), considerForKB(Who, wants(Who, do(Who, sendMsg(flbcMsg(simpleAct(Who, From, illocAct(inform, believes(Who, not correct(format(arg(3, arg(2, msg(MsgID)))))))), [respondingTo(MsgID)])))), MsgID)]) :- F \= illocAct(_, _), !. knowMeaningOfTerms(Who, flbcMsg(MsgID, simpleAct(From, To, IllocAct), Ctxt), Status, ErrorMsg, Recover) :- debugMsg(8, [' Looking for meaning of terms']), checkMeaningOfIllocAct(IllocAct, MsgID, From, okay, _, Status1, ErrorMsg1), knowMeaningOfTerm(From, Status1, ErrorMsg1, Status2, ErrorMsg2), knowMeaningOfTerm(To, Status2, ErrorMsg2, Status3, ErrorMsg3), knowMeaningOfTerm(Ctxt, Status3, ErrorMsg3, Status, ErrorMsg), knowMeaningOfTermsRecover(Status, Who, MsgID, From, Recover). checkMeaningOfIllocAct(and([]), _, _, okay, _, okay, _) :- debugMsg(9, ['List of illocAct()s check out okay']), !. checkMeaningOfIllocAct(and(_), _, _, unknownTerm(X), E, unknownTerm(X), E) :- !. checkMeaningOfIllocAct(and([illocAct(Force, Content)|Rest]), MsgID, From, okay, _, Status, ErrorMsg) :- debugMsg(9, ['Checking list of illocAct()s']), knowMeaningOfForce(Force, Status1, ErrorMsg1), knowMeaningOfTerm(Content, Status1, ErrorMsg1, Status2, ErrorMsg2), debugMsg(9, [Content, Status1, ErrorMsg1, Status2, ErrorMsg2]), debugMsg(9, [Rest, MsgID, From, Status2, ErrorMsg2, Status, ErrorMsg]), !, checkMeaningOfIllocAct(and(Rest), MsgID, From, Status2, ErrorMsg2, Status, ErrorMsg). checkMeaningOfIllocAct(illocAct(Force, Content), _MsgID, _From, okay, _, Status, ErrorMsg) :- debugMsg(9, ['Checking one illocAct()']), knowMeaningOfForce(Force, Status1, ErrorMsg1), knowMeaningOfTerm(Content, Status1, ErrorMsg1, Status, ErrorMsg). knowMeaningOfTermsRecover(okay, _, _, _, _) :- !. knowMeaningOfTermsRecover(unknownTerm(T), Who, MsgID, From, [considerForKB(Who, believes(Who, not isKnown(T)), MsgID), considerForKB(Who, wants(Who, do(Who, sendMsg(flbcMsg(simpleAct(Who, From, illocAct(inform, believes(Who, not isKnown(T)))), [respondingTo(MsgID)])))), MsgID)]) :- !. knowMeaningOfForce(F, okay, none) :- standardEffects(_, flbcMsg(_, simpleAct(_, _, illocAct(F, _)), _), _), debugMsg(9, [' Force', F, 'known']), !. knowMeaningOfForce(F, unknownTerm(F), ['Force', F, 'unknown']). knowMeaningOfTerm(_, unknownTerm(T), ErrorMsg, unknownTerm(T), ErrorMsg) :- !. knowMeaningOfTerm(V, okay, _, okay, none) :- var(V), debugMsg(9, [' Variable']), !. knowMeaningOfTerm([], okay, _, okay, none) :- debugMsg(8, [' Done looking up terms in vocabulary']), !. knowMeaningOfTerm([F|R], okay, _Ein, Sout, Eout) :- var(F), debugMsg(9, [' Variable']), !, knowMeaningOfTerm(R, okay, _, Sout, Eout). knowMeaningOfTerm([F|R], okay, _, Sout, Eout) :- knowMeaningOfTerm(F, okay, _, Sout1, Eout1), knowMeaningOfTerm(R, Sout1, Eout1, Sout, Eout), !. knowMeaningOfTerm(I, okay, _, okay, none) :- integer(I), debugMsg(9, ['Integer']), !. knowMeaningOfTerm(T, okay, _, okay, none) :- atomic(T), debugMsg(9, [' Looking up', T, 'in vocabulary']), inVocabulary(T), debugMsg(9, [' Found', T]), !. knowMeaningOfTerm(T, okay, _, Status, ErrorMsg) :- compound(T), functor(T, F, NoOfArgs), debugMsg(9, [' Looking up', F, '/', NoOfArgs, 'in vocabulary']), inVocabulary(F/NoOfArgs), debugMsg(9, [' Found', F, '/', NoOfArgs]), validationInfo(F/NoOfArgs, T, HowToValidate), /* we know validationInfo exists because we just tested for it */ ((HowToValidate = normal, T =.. [F|Args], knowMeaningOfTerm(Args, okay, _, Status, ErrorMsg)) ; (HowToValidate = noValidation, Status = okay) ; (HowToValidate = vi(TheSteps, Status, ErrorMsg), validateTerm(TheSteps, Status, ErrorMsg))), !. knowMeaningOfTerm(T, _, _, unknownTerm(T), ['Unknown term:', T]) :- debugMsg(9, ['unknown:', T]), !. validateTerm([], okay, none) :- debugMsg(9, ['All terms validated']), !. validateTerm([F|R], Status, ErrorMsg) :- call(F), !, validateTerm(R, Status, ErrorMsg). validateTerm([F|R], Status, ErrorMsg) :- call(F), ((not var(Status)) ; (validateTerm(R, Status, ErrorMsg))). inVocabulary(T) :- stdVocab(T), !. inVocabulary(T) :- stdVocab(T, _, _), !. inVocabulary(T) :- kqmlVocab(T), !. inVocabulary(T) :- kqmlVocab(T, _, _), !. inVocabulary(N) :- noun(N), !. validationInfo(Desc, Term, Info) :- stdVocab(Desc, Term, Info), !. validationInfo(Desc, Term, Info) :- kqmlVocab(Desc, Term, Info), !. ensureReferentsKnown(Who, flbcMsg(MsgID, simpleAct(From, _, _), Ctxt), Status, ErrorMsg, Recover) :- getActors(Ctxt, ListOfActors), verifyKnown(Who, ListOfActors, MsgID, From, Status, ErrorMsg, Recover). substituteRefIntoMsg(flbcMsg(ID, Act, Context), flbcMsg(ID, NewAct, NewContext)) :- getActors(Context, ListOfActors), substituteRefIntoMsg1(ListOfActors, Act, NewAct), substituteRefIntoMsg1(ListOfActors, Context, NewContext). substituteRefIntoMsg1([], X, X) :- !. substituteRefIntoMsg1([ref(Ref, Desc)|RestActors], Act0, Act) :- substituteInTerm1(Ref, Desc, Act0, Act1), !, substituteRefIntoMsg1(RestActors, Act1, Act). getActors(Ctxt, ListOfActors) :- getResources(Ctxt, Resources), getActorsFromResources(Resources, ListOfActors). getResources([], _) :- !, fail. getResources([resources(X)|_], X) :- !. getResources([_|R], X) :- !, getResources(R, X). getActorsFromResources([], _) :- !, fail. getActorsFromResources([actors(A)|_], A) :- !. getActorsFromResources([_|R], A) :- !, getActorsFromResources(R, A). verifyKnown(_, [], _, _, okay, none, none) :- !. verifyKnown(H, [ref(_Ref, person(ID))|RA], MsgID, From, Status, ErrorMsg, Recover) :- kb(H, isKnown(person(ID, _))), !, verifyKnown(H, RA, MsgID, From, Status, ErrorMsg, Recover). verifyKnown(Who, [ref(Ref, person(ID))|_], MsgID, From, unknownRef(ID), ['Reference', Ref, 'to person', ID, 'is not known'], [considerForKB(Who, believes(Who, not isKnown(person(ID))), MsgID), considerForKB(Who, wants(Who, do(Who, sendMsg(flbcMsg(simpleAct(Who, From, illocAct(inform, believes(Who, not isKnown(person(ID))))), [respondingTo(MsgID)])))), MsgID)]) :- not kb(Who, isKnown(person(ID, _))), !. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Predicates that execute the standard effects */ /* Not specific to this vocabulary but needed to run the FLSAS */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ execEffects([]) :- !. execEffects(Effects) :- getListOfVariables(Effects, ListOfVariables), processID(PID), execEffects1(Effects, PID, 1, ListOfVariables). execEffects1([], _, _, _) :- !. execEffects1([F|R], PID, Step, Variables) :- debugMsg(2, ['Exec this effect:', F, PID, Step, Variables]), execThisEffect(F, PID, Step, Variables), debugMsg(2, ['Effect executed', PID, Step, Variables]), NextStep is Step + 1, execEffects1(R, PID, NextStep, Variables). /* could set Other if actions desired by one agent define different actions than actions desired by another agent */ /* really should evaluate whether or not I want to add to KB before actually adding it */ execThisEffect(considerForKB(Who, wants(Spkr, do(Spkr, What)), _OrigMsgID), _ProcessID, _Step, _Var) :- Who \= Spkr, ((kb(Who, believes(Who, wants(Spkr, do(Spkr, What))))) ; (addToKB(Who, believes(Who, wants(Spkr, do(Spkr, What)))))), !. execThisEffect(considerForKB(Who, wants(_Other, do(Who, What)), _OrigMsgID), ProcessID, _Step, _Var) :- /* This predicate specifies that if I already have determined that I'm going to do something, there's no need to add it to the KB again. */ kb(Who, do(ProcessID, _, begin, _, Who, What, _)), debugMsg(2, ['execThisEffect 1']), !. execThisEffect(considerForKB(Who, wants(_Other, do(Who, What)), OrigMsgID), ProcessID, Step, Var) :- debugMsg(2, ['execThisEffect 1a']), addToKB(Who, do(ProcessID, Step, begin, OrigMsgID, Who, What, Var)), debugMsg(2, ['Added to KB for', Who, ': do(', Who, ',', What, ')']), !. execThisEffect(considerForKB(Who, wants(_Someone, believes(Who, believes(Who, What))), _OrigMsgID), _ProcessID, _Step, _Var) :- debugMsg(2, ['execThisEffect 2']), addToKB(Who, believes(Who, What)), !. execThisEffect(considerForKB(Who, wants(_Someone, believes(Who, What)), _OrigMsgID), _ProcessID, _Step, _Var) :- debugMsg(2, ['execThisEffect 3']), addToKB(Who, believes(Who, What)), !. execThisEffect(considerForKB(Who, wants(_Someone, not believes(Who, What)), _OrigMsgID), _ProcessID, _Step, _Var) :- debugMsg(2, ['execThisEffect 4']), debugMsg(2, ['Attempting to remove', Who, What]), removeFromKB(Who, believes(Who, What)), !. execThisEffect(considerForKB(Who, wants(_Other, wants(Who, do(Who, What))), _OrigMsgID), ProcessID, _Step, _Var) :- /* This predicate specifies that if I already have determined that I'm going to do something, there's no need to add it to the KB again. */ debugMsg(2, ['execThisEffect 5']), kb(Who, do(ProcessID, _, begin, _, Who, What, _)), !. execThisEffect(considerForKB(Who, wants(_Other, wants(Who, do(Who, What))), OrigMsgID), ProcessID, Step, Var) :- debugMsg(2, ['execThisEffect 6']), debugMsg(2, [What]), addToKB(Who, do(ProcessID, Step, begin, OrigMsgID, Who, What, Var)), !. execThisEffect(considerForKB(Who, believes(Someone, believes(Someone, What)), _OrigMsgID), _ProcessID, _Step, _Var) :- debugMsg(9, ['execThisEffect 7']), addToKB(Who, believes(Someone, What)), !. execThisEffect(considerForKB(Who, believes(Someone, not believes(Who, What)), _OrigMsgID), _ProcessID, _Step, _Var) :- Who \= Someone, debugMsg(2, ['execThisEffect 8']), addToKB(Who, believes(Someone, not believes(Who, What))), !. execThisEffect(considerForKB(_, not believes(_, is(_, and([]))), _), _, _, _) :- !. execThisEffect(considerForKB(Who, not believes(Other, is(Someone, and([F|R]))), OrigMsgID), ProcessID, Step, Var) :- debugMsg(2, ['execThisEffect 9a']), addToKB(Who, not believes(Other, is(Someone, F))), !, execThisEffect(considerForKB(Who, not believes(Other, is(Someone, and(R))), OrigMsgID), ProcessID, Step, Var). execThisEffect(considerForKB(Who, not believes(Someone, What), _OrigMsgID), _ProcessID, _Step, _Var) :- debugMsg(2, ['execThisEffect 9']), addToKB(Who, not believes(Someone, What)), !. execThisEffect(considerForKB(Who, believes(Someone, What), _OrigMsgID), _ProcessID, _Step, _Var) :- debugMsg(2, ['execThisEffect 10']), ((kb(Who, believes(Someone, What))) ; (addToKB(Who, believes(Someone, What)))), !. execThisEffect(ToDo, _ProcessID, _Step, _Var) :- debugMsg(2, ['execThisEffect 11']), call(ToDo), !. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Other predicates specific to the FLSAS */ /* Not specific to this vocabulary but needed to run the FLSAS */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ addToKB(_, believes(_, believes(_, time(_, believes(_, is(_, and([]))))))) :- !. addToKB(Who, believes(W1, believes(W2, time(When, believes(W3, is(W4, and([F|R]))))))) :- addToKB(Who, believes(W1, believes(W2, time(When, believes(W3, is(W4, F)))))), !, addToKB(Who, believes(W1, believes(W2, time(When, believes(W3, is(W4, and(R))))))). addToKB(_, believes(_, is(_, and([])))) :- !. addToKB(Who, believes(Some, is(X, and([F|R])))) :- addToKB(Who, believes(Some, is(X, F))), !, addToKB(Who, believes(Some, is(X, and(R)))). addToKB(Who, What) :- assertz(kb(Who, What)), !. removeFromKB(_, believes(_, is(_, and([])))) :- !. removeFromKB(Who, believes(Some, is(X, and([F|R])))) :- removeFromKB(Who, believes(Some, is(X, F))), !, removeFromKB(Who, believes(Some, is(X, and(R)))). removeFromKB(Who, believes(Who, What)) :- removeFromKB1(Who, What). removeFromKB(Who, What) :- removeFromKB1(Who, What). removeFromKB(_, _) :- !. /* the following handles the difference between delete-one and delete-all */ removeFromKB1(Who, What) :- addToKB(Who, removedFromKB(Who, What)), ((ground(What), retract(kb(Who, What))) ; (not ground(What), retractall(kb(Who, What)))), !. checkPropCompatible(_, _, _, _, notCompatible(_, _), notCompatible(_, _), _, _) :- !. checkPropCompatible(and([]), _, _, _, okay, okay, _, _) :- !. checkPropCompatible(and([First|Rest]), Who, MsgID, From, okay, Status, ErrorMsg, Recover) :- checkPropCompatible(First, Who, MsgID, From, okay, Status1, ErrorMsg, Recover), !, checkPropCompatible(and(Rest), Who, MsgID, From, Status1, Status, ErrorMsg, Recover). checkPropCompatible(illocAct(_, and([])), _, _, _, okay, okay, _, _) :- !. checkPropCompatible(illocAct(Force, and([F|R])), Who, MsgID, From, okay, Status, ErrorMsg, Recover) :- checkPropCompatible(illocAct(Force, F), Who, MsgID, From, okay, Status1, ErrorMsg, Recover), !, checkPropCompatible(illocAct(Force, and(R)), Who, MsgID, From, Status1, Status, ErrorMsg, Recover). checkPropCompatible(illocAct(Force, Content), _, _, _, okay, okay, _, _) :- propositionCompatible(Force, Content), !. checkPropCompatible(illocAct(Force, Content), Who, MsgID, From, okay, notCompatible(Force, Content), ['Force', Force, 'and', Content, 'are not proposition compatible'], [considerForKB(Who, believes(Who, not propositionCompatible(Force, Content)), MsgID), considerForKB(Who, wants(Who, do(Who, sendMsg(flbcMsg(simpleAct(Who, From, illocAct(inform, believes(Who, not propositionCompatible(Force, Content)))), [respondingTo(MsgID)])))), MsgID)]) :- not propositionCompatible(Force, Content), !. displayIllocActs(and([])) :- !. displayIllocActs(and([illocAct(Force, Content)|R])) :- debugMsg(1, [' Msg: ', Force, Content]), !, displayIllocActs(and(R)). displayIllocActs(illocAct(Force, Content)) :- debugMsg(1, [' Msg: ', Force, Content]), !. xmlDef(flbcMsg(ID, IllocAct, Context), XML) :- xmlDef(xml, XML1), xmlDef(docType, XML2), append(XML1, XML2, XML3), assembleXML(flbcMsg(ID, IllocAct, Context), FLBCXML), append(XML3, FLBCXML, XML). xmlDef(xml, XML) :- xmlDef(xml([arg(version, '1.0'), arg(encoding, 'UTF-8'), arg(standalone, 'no')]), XML). xmlDef(xml(Args), XML) :- getArgXML(Args, ArgXML), append([''], XML). xmlDef(docType, XML) :- xmlDef(docType('flbcMsg', 'SYSTEM', '"http://www-personal.umich.edu/~samoore/research/flbcMsg.dtd"'), XML). xmlDef(docType(Name, Type, DTD), ['']). xmlDef([], _, X, X) :- !. xmlDef([F|R], none, Temp, Result) :- assembleXML(F, XML), append(Temp, XML, Temp1), !, xmlDef(R, none, Temp1, Result). assembleXML([F|R], XML) :- xmlDef([F|R], none, [], XML1), append([''], XML1, XML2), append(XML2, [''], XML). assembleXML(Term, XML) :- xmlDef(Term, Args, Content), functor(Term, TermName, _), assembleXML1(TermName, Args, Content, XML). assembleXML1(T, none, alwaysEmpty, [T]) :- ((stdVocab(T)) ; (kqmlVocab(T)) ; (noun(T))). assembleXML1(TermName, ArgInfo, alwaysEmpty, XML) :- getArgXML(ArgInfo, ArgXML), append(['<', TermName], ArgXML, XML1), append(XML1, ['/>'], XML). assembleXML1(TermName, ArgInfo, [], XML) :- getArgXML(ArgInfo, ArgXML), append(['<', TermName], ArgXML, XML1), append(XML1, ['>'], XML). assembleXML1(TermName, ArgInfo, Contents, XML) :- /* debugMsg(9, ['working on', TermName, ArgInfo, Contents]), */ getArgXML(ArgInfo, ArgXML), assembleXMLContents(Contents, ContentsXML), append(['<', TermName], ArgXML, XML1), append(XML1, ['>'], XML2), append(XML2, ContentsXML, XML3), append(XML3, [''], XML). assembleXMLContents(Contents, XML) :- assembleXMLContents(Contents, [], XML). assembleXMLContents([], X, X) :- !. assembleXMLContents([F|R], Temp, Final) :- var(F), append(Temp, [F], Temp1), !, assembleXMLContents(R, Temp1, Final). assembleXMLContents([F|R], Temp, Final) :- /* debugMsg(9, ['2 contents', F]), */ assembleXML(F, XMLforF), /* debugMsg(9, ['2 xml:', XMLforF]), */ append(Temp, XMLforF, Temp1), !, assembleXMLContents(R, Temp1, Final). getArgXML(none, []) :- !. getArgXML(ArgInfo, XML) :- getArgXML(ArgInfo, [], XML). getArgXML([], X, X) :- !. getArgXML([arg(Name, Value)|R], Temp, Final) :- append(Temp, [' ', Name, '="', Value, '"'], Temp1), !, getArgXML(R, Temp1, Final). printSE(MsgID) :- testMsg(inBox(Who, _, flbcMsg(MsgID, Content, Context))), standardEffects(Who, flbcMsg(MsgID, Content, Context), SE), printSE1(SE). printSE1([]) :- !. printSE1([F|R]) :- translate(F, Trans), printThis(Trans), nl, !, printSE1(R). translate(V, [VSym]) :- var(V), gensym(var, VSym), V = VSym, !. translate(considerForKB(Who, What, Why), Trans) :- translate(Who, WhoTrans), translate(What, WhatTrans), append(WhoTrans, [' should consider adding to its knowledge base'], Trans1), append(Trans1, WhatTrans, Trans2), append(Trans2, [' because of ', Why], Trans), !. translate(wants(Who, What), Trans) :- translate(What, WhatTrans), append([' (', Who, ' wants'], WhatTrans, Trans1), append(Trans1, [')'], Trans), !. translate(do(Who, What), Trans) :- translate(What, WhatTrans), append([' (', Who, ' does'], WhatTrans, Trans1), append(Trans1, [')'], Trans), !. translate(undo(Who, What), Trans) :- translate(What, WhatTrans), append([' (', Who, ' undoes'], WhatTrans, Trans1), append(Trans1, [')'], Trans), !. translate(believes(Who, What), Trans) :- translate(What, WhatTrans), translate(Who, WhoTrans), append([' ('], WhoTrans, T1), append(T1, [' believes that'], T2), append(T2, WhatTrans, T3), append(T3, [')'], Trans), !. translate(I, [' ', I]) :- atomic(I). translate([F|R], Trans) :- translate(F, FTrans), translate1(R, [FTrans], Trans). /* translate(findValue(all, Vars, What), Trans), translate(What, WhatTrans), append([' find all the values of ', Vars, ' in '], WhatTrans, Trans), !. translate(person(X), [' ', Name]) :- kb(_, isKnown(person(X, Name))), !. */ translate(T, Trans) :- T =.. [F|R], translate1(R, [' ', F, '('], Trans). translate(T, [' ', T]) :- !. translate1([], X, Trans) :- append(X, [')'], Trans), !. translate1([F|R], Temp, Final) :- debugMsg(9, ['working on', F]), translate(F, FTrans), append(Temp, FTrans, Temp1), !, translate1(R, Temp1, Final). /* considerForKB(person(123), wants(a,do(b,undo(b,simpleAct(a,b,illocAct(dispute,registered(a,thisMailList)))))), undelete) considerForKB(person(123), wants(a,wants(b,do(b,undo(b,simpleAct(a,b,illocAct(dispute,registered(a,thisMailList))))))), undelete) */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* General system predicates */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ setQuiet(X) :- retractall(quietLevel(_)), assert(quietLevel(X)). getQuiet(X) :- quietLevel(X), !. debugMsg(X, Msg) :- getQuiet(QL), ((X =< QL, writeList(Msg), nl) ; (X > QL)), !. writeList([]) :- !. writeList([L]) :- write(L), !. writeList([F|R]) :- var(F), write(F), write(' '), !, writeList(R). writeList([nl|R]) :- nl, !, writeList(R). writeList([F|R]) :- write(F), write(' '), !, writeList(R). printXML(Term) :- write(Term), nl, ((xmlDef(Term, XML)) ; (assembleXML(Term, XML))), printThis(XML). printXMLTerm(X) :- testMsg(inBox(_, _, flbcMsg(X, Y, Z))), printXML(flbcMsg(X, Y, Z)). printThis([]) :- !. printThis([F|R]) :- write(F), !, printThis(R). processID(X) :- gensym(t, X). messageID(M) :- gensym(m, M). getMax([F], F) :- !. getMax([F|R], Max) :- getMax(R, F, Max), !. getMax([], X, X) :- !. getMax([F|R], Temp, Max) :- compare(>, F, Temp), !, getMax(R, F, Max). getMax([_|R], Temp, Max) :- !, getMax(R, Temp, Max). getListOfVariables(Term, List) :- getListOfVariables1(Term, [], List1), sort(List1, List), !. getListOfVariables1(Term, L, L) :- atomic(Term). getListOfVariables1(Term, L, [Term|L]) :- var(Term). getListOfVariables1([F|R], L0, L) :- getListOfVariables1(F, L0, L1), getListOfVariables1(R, L1, L). /* Should be able to do the following. Bug work-around. getListOfVariables1(Term, L, Final) :- compound(Term), Term =.. [F|R], getListOfVariables1(R, L, Final). */ getListOfVariables1(Term, L1, L) :- compound(Term), functor(Term, _F, NoOfArgs), getListOfVariables2(Term, 0, NoOfArgs, [], L2), append(L1, L2, L), !. getListOfVariables2(_, X, X, L, L) :- !. getListOfVariables2(Term, LastArg, NoOfArgs, L0, L) :- Arg is LastArg + 1, arg(Arg, Term, Value), getListOfVariables1(Value, L0, L1), !, getListOfVariables2(Term, Arg, NoOfArgs, L1, L). createVarTerms(What, Term, VarWhat, VarTerm) :- createVarList(What, VarWhat), substituteInTerm(What, VarWhat, Term, VarTerm). createVarList(ListOfGroundTerms, ListOfVarTerms) :- length(ListOfGroundTerms, Len), createVarList1(Len, 0, ListOfVarTerms), !. createVarList1(0, 0, []) :- !. createVarList1(Len, 0, [_|R]) :- NewLen is Len - 1, !, createVarList1(NewLen, 0, R). substituteInTerm([], _, X, X) :- !. substituteInTerm([GT|RGT], [VT|RVT], Term0, Term) :- debugMsg(11, [1, GT, VT, Term0]), substituteInTerm1(GT, VT, Term0, Term1), !, debugMsg(11, [2, GT, VT, Term1]), substituteInTerm(RGT, RVT, Term1, Term). substituteInTerm1(_Ground, _Var, Var1, Var1) :- var(Var1), !. substituteInTerm1(Ref, Var, Ref, Var) :- !. substituteInTerm1(_Ground, _Var, T, T) :- atomic(T). substituteInTerm1(_, _, [], []) :- !. substituteInTerm1(Ground, Var, [F|R], [Term1|Term2]) :- substituteInTerm1(Ground, Var, F, Term1), substituteInTerm1(Ground, Var, R, Term2), !. substituteInTerm1(_, _, ref(A, B), ref(A, B)) :- !. substituteInTerm1(Ground, Var, CT, NewCT) :- compound(CT), functor(CT, _F, NoOfArgs), debugMsg(11, ['Substituting in a compound term']), debugMsg(11, [' ', Ground, Var, NoOfArgs, CT]), substituteInTerm2(Ground, Var, 0, NoOfArgs, CT, [], NewCT), !. substituteInTerm2(_, _, Arg, Arg, Term, ListOfArgs, NewTerm) :- functor(Term, Functor, _), NewTerm =.. [Functor|ListOfArgs], debugMsg(11, [' The new term is', NewTerm]), !. substituteInTerm2(Ground, Var, Arg, NoOfArgs, CT, ListOfArgs1, NewCT) :- NewArg is Arg + 1, !, debugMsg(11, [' Working on arg', NewArg]), arg(NewArg, CT, Value), debugMsg(11, [' The value is', Value, ' G', Ground, ' V', Var]), substituteInTerm1(Ground, Var, Value, Term1), debugMsg(11, [' The new term is', Term1]), append(ListOfArgs1, [Term1], ListOfArgs), debugMsg(11, [' The list of args is', ListOfArgs]), !, substituteInTerm2(Ground, Var, NewArg, NoOfArgs, CT, ListOfArgs, NewCT). unifyVariables([], []) :- debugMsg(9, [' Nothing to unify.']), !. unifyVariables([do(PID, Step, OMID, Who, What, V)|RD], L) :- debugMsg(9, [' Setting up unification process']), unifyVariables1(V, [do(PID, Step, OMID, Who, What, V)|RD], L). unifyVariables1(_, [], []) :- debugMsg(9, [' Done unifying']), !. unifyVariables1(V, [do(PID, Step, OMID, Who, What, V)|RD1], [do(PID, Step, OMID, Who, What, V)|RD]) :- debugMsg(9, [' a unify step']), !, unifyVariables1(V, RD1, RD). intersect(S1, S2, SortResult) :- sort(S1, Sort1), sort(S2, Sort2), intersect(Sort1, Sort2, [], Result), sort(Result, SortResult). intersect([], _, X, X) :- !. intersect(_, [], X, X) :- !. intersect([F|R1], [F|R2], Temp, Result) :- !, intersect(R1, R2, [F|Temp], Result). intersect([F1|R1], [F2|R2], Temp, Result) :- compare(<, F1, F2), !, intersect(R1, [F2|R2], Temp, Result). intersect([F1|R1], [_F2|R2], Temp, Result) :- !, intersect([F1|R1], R2, Temp, Result). getMatches([], X, X) :- !. getMatches(Match, In, Out) :- getMatches(Match, In, [], Out). getMatches([], _, X, X) :- !. getMatches([Match|RMatch], In, Temp, Out) :- getMatches1(Match, In, [], [], Temp1, Residual), append(Temp, Temp1, Temp2), !, getMatches(RMatch, Residual, Temp2, Out). getMatches1(_Term, [], X, Y, X, Y) :- !. getMatches1(Term, [Term|RIn], Match1, NotMatch1, Match, NotMatch) :- functor(Term, F, NoOfArgs), functor(TermCopy, F, NoOfArgs), !, getMatches1(TermCopy, RIn, [Term|Match1], NotMatch1, Match, NotMatch). getMatches1(Term, [FTerm|RIn], Match1, NotMatch1, Match, NotMatch) :- !, getMatches1(Term, RIn, Match1, [FTerm|NotMatch1], Match, NotMatch). setof1(A, B, C) :- ((setof(A, B, C), !) ; (C = [])). /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* For testing */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* test1(substituteRefIntoMsg(flbcMsg(x, simpleAct(a, b, illocAct(question, y)), [resources([actors([ref(a, person(456)), ref(b, person(123))])])]), ABC)). :- test1(X), call(X). */ testMsg(inBox(person(123), notHandled, flbcMsg(deleteOne, simpleAct(a, b, illocAct(dispute, registered(a, thisMailList))), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(undelete, simpleAct(a, b, illocAct(request, undo(b, simpleAct(a, b, illocAct(dispute, registered(a, thisMailList)))))), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(askIf, simpleAct(a, b, illocAct(question, isTrueFalse(registered(a, thisMailList)))), [resources([actors([ref(a, person(456)), ref(b, person(123))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(askAll, simpleAct(d, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(all, [var(1)], truthStatus(true, registered(d, var(1))))), TheVal)), do(b, sendMsg(flbcMsg(simpleAct(b, d, illocAct(inform, TheVal)), [respondingTo(askAll)])))]))), [resources([actors([ref(b, person(123)), ref(d, person(789))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(streamAll, simpleAct(d, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(all, [var(1)], truthStatus(true, registered(d, var(1))))), TheVal)), do(b, forward([var(1)]:TheVal, notIdentify, flbcMsg(simpleAct(b, d, illocAct(inform, var(1))), [respondingTo(streamAll)])))]))), [resources([actors([ref(b, person(123)), ref(d, person(789))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(askOne, simpleAct(d, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(one, [var(1)], truthStatus(true, registered(d, var(1))))), TheVal)), do(b, sendMsg(flbcMsg(simpleAct(b, d, illocAct(inform, TheVal)), [respondingTo(askOne)])))]))), [resources([actors([ref(b, person(123)), ref(d, person(789))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(eos, simpleAct(a, b, illocAct(inform, believes(a, complete(do(a, respondingTo(rw)))))), [resources([actors([ref(b, person(123)), ref(a, person(789))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(tell, simpleAct(a, b, illocAct(inform, believes(a, registered(a, thisMailList)))), [resources([actors([ref(b, person(123)), ref(a, person(789))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(untell, simpleAct(a, b, illocAct(inform, not believes(a, registered(a, thisMailList)))), [resources([actors([ref(b, person(123)), ref(a, person(456))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(deny, simpleAct(a, b, illocAct(denial, registered(a, thisMailList))), [resources([actors([ref(b, person(123)), ref(a, person(456))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(insert, simpleAct(a, b, illocAct(asserts, registered(a, thisMailList))), [resources([actors([ref(b, person(123)), ref(a, person(789))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(uninsert, simpleAct(a, b, illocAct(retract, registered(a, thisMailList))), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(achieve, simpleAct(a, b, illocAct(request, do(b, registered(a, thatMailList)))), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(unachieve, simpleAct(a, b, illocAct(request, undo(b, registered(a, thatMailList)))), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(subscribe, simpleAct(a, b, illocAct(request, do(b, subscribe(a, someAction)))), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(badIllocAct, simpleAct(a, b, poorlyFormattedIllocAct), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(badSimpleAct, poorlyFormattedSimpleAct, [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, poorlyFormattedMsg)). testMsg(inBox(person(123), notHandled, flbcMsg(unknownRef, simpleAct(a, b, illocAct(request, do(b, subscribe(a, someAction)))), [resources([actors([ref(b, person(66)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(notPropCompatible, simpleAct(a, b, illocAct(request, believes(b, subscribe(a, someAction)))), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(advertise, simpleAct(a, b, illocAct(promise, do(a, process(a, subscribe(b, someAction))))), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(error, simpleAct(a, b, illocAct(report, time(before(now), not process(a, msg(678))))), [resources([actors([ref(b, person(123)), ref(a, person(234))])]), respondingTo(567)]))). testMsg(inBox(person(123), notHandled, flbcMsg(sorry, simpleAct(a, b, illocAct(inform, believes(a, complete(do(a, respondingTo(567)))))), [resources([actors([ref(b, person(123)), ref(a, person(234))])]), respondingTo(567)]))). testMsg(inBox(person(123), notHandled, flbcMsg(register, simpleAct(a, b, and([illocAct(request, do(b, registered(a, b))), illocAct(describe, is(a, and([physicalAddr(x1), emailAddr(x2)])))])), [resources([actors([ref(b, person(123)), ref(a, person(234))])]), respondingTo(567)]))). testMsg(inBox(person(123), notHandled, flbcMsg(unregister, simpleAct(a, b, and([illocAct(retract, is(a, and([physicalAddr(x1), emailAddr(x2)]))), illocAct(request, undo(b, registered(a, b)))])), [resources([actors([ref(b, person(123)), ref(a, person(234))])]), respondingTo(567)]))). testMsg(inBox(person(123), notHandled, flbcMsg(transport-address, simpleAct(a, b, and([illocAct(retract, is(a, physicalAddr(x1))), illocAct(describe, is(a, physicalAddr(x2)))])), [resources([actors([ref(b, person(123)), ref(a, person(234))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(forward, simpleAct(c, d, illocAct(request, do(d, forward(b, identify, flbcMsg(simpleAct(a, b, illocAct(request, do(b, registered(a, thisMailList)))), []))))), [resources([actors([ref(d, person(123)), ref(c, person(234)), ref(a, person(456)), ref(b, person(789))])]), forwardedBy(c)]))). testMsg(inBox(person(123), notHandled, flbcMsg(broadcast, simpleAct(a, c, illocAct(request, and([do(c, evaluate(believes(c, findValue(all, [var(1)], isAbleTo(deliver(c, var(1))))), TheVal)), do(c, forward([var(1)]:TheVal, identify, flbcMsg(simpleAct(a, var(1), illocAct(asserts, maintains(a, otherMailList))), [])))]))), [resources([actors([ref(c, person(123)), ref(a, person(456))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(broker-one, simpleAct(a, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(one, [var(1)], [isAbleTo(process(var(1), request, do(var(1), registered(_, thisMailList)))), isWillingTo(process(var(1), request, do(var(1), registered(_, thisMailList))))])), TheVal)), do(b, forwardResponse(sendMsg(flbcMsg(simpleAct(b, TheVal, illocAct(asserts, maintains(a, otherMailList))), [])), a))]))), [resources([actors([ref(b, person(123)), ref(a, person(456))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(broker-all, simpleAct(a, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(all, [var(1)], [isAbleTo(process(var(1), request, do(var(1), registered(_, thisMailList)))), isWillingTo(process(var(1), request, do(var(1), registered(_, thisMailList))))])), TheVal)), do(b, forwardResponse(sendMsg(flbcMsg(simpleAct(b, var(1):TheVal, illocAct(asserts, maintains(a, otherMailList))), [])), a))]))), [resources([actors([ref(b, person(123)), ref(a, person(456))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(recommend-one, simpleAct(a, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(one, [var(1)], truthStatus(true, isAbleTo(process(var(1), request, do(var(1), registered(_, thisMailList))))))), TheVal)), do(b, sendMsg(flbcMsg(simpleAct(b, a, illocAct(inform, TheVal)), [respondingTo(recommend-one)])))]))), [resources([actors([ref(b, person(123)), ref(a, person(789))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(recommend-all, simpleAct(a, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(all, [var(1)], truthStatus(true, isAbleTo(process(var(1), request, do(var(1), registered(_, thisMailList))))))), TheVal)), do(b, sendMsg(flbcMsg(simpleAct(b, a, illocAct(inform, TheVal)), [respondingTo(recommend-all)])))]))), [resources([actors([ref(b, person(123)), ref(a, person(789))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(recruit-one, simpleAct(a, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(one, [var(1)], [isAbleTo(process(var(1), request, do(var(1), registered(_, thisMailList)))), isWillingTo(process(var(1), request, do(var(1), registered(_, thisMailList))))])), TheVal)), do(b, forward(TheVal, identify, flbcMsg(simpleAct(b, TheVal, illocAct(asserts, maintains(a, otherMailList))), [replyTo(a), respondingTo(recruit-one)])))]))), [resources([actors([ref(b, person(123)), ref(a, person(456))])])]))). testMsg(inBox(person(123), notHandled, flbcMsg(recruit-all, simpleAct(a, b, illocAct(request, and([do(b, evaluate(believes(b, findValue(all, [var(1)], [isAbleTo(process(var(1), request, do(var(1), registered(_, thisMailList)))), isWillingTo(process(var(1), request, do(var(1), registered(_, thisMailList))))])), TheVal)), do(b, forward([var(1)]:TheVal, identify, flbcMsg(simpleAct(b, var(1), illocAct(asserts, maintains(a, otherMailList))), [replyTo(a), respondingTo(recruit-all)])))]))), [resources([actors([ref(b, person(123)), ref(a, person(456))])])]))). tt :- Who = person(123), Identifiers = [var(1)], Values = [[person(234)], [person(456)]], FLBCMsg = flbcMsg(simpleAct(person(456), var(1), illocAct(asserts, maintains(person(456), otherMailList))), []), createForwardedMsgs(forward(Identifiers:Values, FLBCMsg), [], ForwardedMsgs), debugMsg(2, ['4', Who, ForwardedMsgs]), sendForwardedMsgs(Who, do(_, _, _, Who, do(Who, ForwardedMsgs), _)). testgsv :- getSetValues([Y], kb(person(123), [isAbleTo(process(Y,request, do(Y, registered(_x98605, thisMailList)))), isWillingTo(process(Y, request, do(Y, registered(_x98607,thisMailList))))]), X), debugMsg(1, [X]) . testfw :- createForwardedMsgs(forward(var(1):[[person(234)]], flbcMsg(simpleAct(person(123), var(1), illocAct(asserts, maintains(person(123), otherMailList))), [])), [], FM), debugMsg(9, ['FM:', FM]). testXMLData(flbcMsg(a, b, c)). testXMLData(flbcMsg(theID, simpleAct(from, to, illocAct(theForce, content)), context)). testXMLData(flbcMsg(id2, simpleAct(a, b, illocAct(request, runHome)), context([resources([actors([ref(a, nancy), ref(b, scott)])]), replyTo(abc)]))). testXML :- setof1(Term, testXMLData(Term), Terms), testXML(Terms, screen). testx(ID, Where) :- testMsg(inBox(_, _, flbcMsg(ID, Content, Context))), testXML([flbcMsg(ID, Content, Context)], Where). testXMLfile1 :- setof1(Term, testXMLData(Term), Terms), testXML(Terms, file). testXMLfile2 :- setof1(Term, testMsg(inBox(_, _, Term)), Terms), testXML(Terms, file). testXML(Terms, Where) :- ((Where = screen, testXML(Terms)) ; (Where = file, tell('flbc.txt'), testXML(Terms), told)), write('Succeeded'), !. testXML([]) :- !. testXML([F|R]) :- printXML(F), nl, !, testXML(R). testXML([_|R]) :- nl, write('failed'), nl, !, testXML(R).