:- if(\+ current_module(npc_chat)). :- module(npc_chat,[]). :- endif. % :- module(baseKB). :- clause(agent_module(_),_) -> true ; prolog_load_context(module,M),asserta(agent_module(M)). :- use_module(library(logicmoo_common)). :- use_module(library(logicmoo_autodoc)). %:- use_module(library(pfc_lib)). :- style_check(- discontiguous). :- agent_module(M), module(M). %:- echo_source_file. same_meanings(UserSaid,UserSaid). retract_all(X):- agent_module(M),forall(retract(M:X),true). initial_goal(introductions(Self,User)):- me_you(Self,User). builtin(_,Sit):- check_sit(Sit), guard, check_sit(Sit). builtin(Mode,(A,B)):- !,call(Mode,A),call(Mode,B). builtin(Mode, [A|B]):- !,call(Mode,A),call(Mode,B). builtin(Mode,(A;B)):- !, (call(Mode,A);call(Mode,B)). builtin(Mode,(A->B)):- !,(call(Mode,A)->call(Mode,B)). builtin(Mode,(A*->B)):- !,(call(Mode,A)*->call(Mode,B)). builtin(Mode,(A->B;C)):- !,(call(Mode,A)->call(Mode,B);call(Mode,C)). builtin(Mode,(A*->B;C)):- !,(call(Mode,A)*->call(Mode,B);call(Mode,C)). builtin(Mode, \+(A)):- !, \+ call(Mode,A). builtin(_,(A=B)):- !, A=B. builtin(_,[]):-!. builtin(_,s(Say)):- !, sleep(0.2),writeln(Say). builtin(_,w(Time)):- !, sleep(Time). builtin(_,t(Thought)):- !, nop((write("thinking..."),writeln('doing...: ' + Thought))). builtin(_,h(Heard)):- !, write("listening..."),nl,get_char(_),writeln('Heard: ' + Heard). builtin(Mode, P):- compound(P),compound_name_arguments(P,F,[Arg]),F==Mode,guard,call(Mode,Arg). builtin(_, P ):- agent_module(M),predicate_property(M:P,static),guard,call(P). builtin(_,play_mode(Mode)):- !, agent_module(M),retractall(M:play_mode(_)),asserta(M:play_mode(Mode)). builtin(_,noplay_mode):- !, agent_module(M),M:retractall(play_mode(_)),!. %builtin(Mode,ensure(Game)):- !, ensure(Mode,Game). builtin(_Mode,debug(English)):- nop(ain(pipeline(English))),adbg(debug(English)). builtin(_Mode,expect(User,English)):- !, said(User,UserSaid),!,same_meanings(UserSaid,English). is_always_guard(_=_). is_always_guard(!). until_guard(GBody,Body):- find_guard(GBody,Before,Body),!,call(Before). find_guard((G,GBody),(G,Before),Body):- is_always_guard(G), !, find_guard(GBody,Before,Body). find_guard((!,GBody),(!,Before),Body):- !, find_guard(GBody,Before,Body). find_guard(GBody,Before,Body):- conjuncts_to_list(GBody,BodyL),append(BeforeL,[guard|AfterL],BodyL),!, list_to_conjuncts(BeforeL,Before),list_to_conjuncts(AfterL,Body). find_guard(GBody,true,GBody). ensure(Sit):- check_sit(Sit). ensure(Sit):- var(Sit),!,throw(var_ensure(Sit)). ensure([]). ensure(ensure(Sit)):- !, ensure(Sit). ensure(Goal):- compound(Goal),compound_name_arity(Goal,call,_),!,agent_module(M),M:call(Goal). ensure(Sit):- guard_builtin(ensure,Sit,GBody),!,agent_module(M),M:call(GBody). ensure(Sit):- already_true(Sit),!, adbg(already_true(Sit)). ensure(Sit):- \+ \+ is_assumable_happens(Sit),!, assume(happens,Sit). ensure(Sit):- guard_clause(make_true(Sit),Body),adbg(trying(make_true(Sit))),call(Body),!,assume(made_true,Sit). ensure(Sit):- \+ \+ is_assumable(Sit),!, assume(is_assumable,Sit). ensure(Sit):- fail, Sit\=achieves(_,_),guard_clause(make_true(achieves(Self,Sit)),Body),dif(Self,user), adbg(trying(achieves(Self,Sit))),call(Body),!,assume(achieves(Self),Sit). ensure(Sit):- adbg(failed(ensure(Sit))),!,fail,ain(Sit). assume(Sit):- assume(assumed,Sit). assume(_How,Sit):- check_sit(Sit). assume(How,not(Sit)):- !,assume(How, \+ (Sit)). assume(How,Sit):- guard_builtin(assume(How),Sit,GBody),!,call(GBody). assume(How,Sit):- agent_module(M),append_term(How,Sit,HowSit),adbg(HowSit), ( \+ M:call(Sit) -> (aina(M:Sit),ignore(forall(post_true(Sit),true))) ; true). guard_builtin(How,Goal,Body):- guard_clause(builtin(How,Goal),Body). guard_clause(Head,Body):- agent_module(M),M:clause(Head,GBody),until_guard(GBody,Body),!. check_sit(Sit):- must_be(nonvar,Sit),fail. cant_just_assume(M:P):- nonvar(M),!,cant_just_assume(P). cant_just_assume(know(_,_)). cant_just_assume(cpv(_,_,_)). is_assumable_happens(X):- \+ \+ cant_just_assume(X),!, fail. is_assumable_happens(said(Self,_)):- Self\==user. is_assumable_happens(want(_,_)). is_assumable_happens(M:P):- nonvar(M),!,is_assumable_happens(P). %is_assumable_happens(X):- is_assumable(X). %is_assumable(X):- \+ \+ cant_just_assume(X),!, fail. is_assumable(cpv(_,_,_)). is_assumable(heard(Self,_)):- \+ is_you(Self), is_me(Self). is_assumable(M:P):- nonvar(M),!,is_assumable(P). is_assumable(Happens):- is_assumable_happens(Happens). is_assumable(Sit):- compound(Sit),arg(1,Sit,V),nonvar(V),functor(Sit,F,A),functor(Prop2,F,A),!,is_assumable(Prop2). %is_assumable(avoid(agent,cpv)). %is_assumable(want(agent,cpv)). %is_assumable(heard(agent,cpv)). is_you(X):- dif(X,robot). is_me(X):- dif(X,user). addressee(_,My,From,About,My):- From==About. addressee(You,_,From,About,You):- From\==About. english(From,cpv(About,Name,X),[YoursMy,Name,is,X]):- nonvar(X),addressee(your,my,From,About,YoursMy). english(From,cpv(About,Name,X),['Something',is,YoursMy,Name]):- var(X),addressee(your,my,From,About,YoursMy). english(From,ask(Prop),[what,E,?]):- english(From,Prop,E). english(From,tell(About,Prop),[Self,tell,Someone,E,'.']):- english(From,Prop,E),addressee(you,me,From,About,Someone),addressee(you,me,robot,From,Self). english(From,C,[IYou,Know,E]):- C =..[Know,About,Prop],addressee(you,i,From,About,IYou), english(From,Prop,E). english(From,C,[About,E]):- C =..[About,Prop],english(From,Prop,E). english(_,C,[C]). adbg(X):- notrace(adbg0(X)),!. %adbg0(X):- english(robot,X,E),flatten([E],[W|En]),write(W),maplist(adbg1,En),!,write('\t\t%%%'),adbg1(X),nl,!. adbg0(X):- wdmsg(X),!. adbg1(C):- compound(C),!,write(' '),writeq(C). adbg1(C):- write(' '),write(C). :- dynamic(cpv/3). cpv(robot,name,bina48). %cpv(user,name,doug). cpv(user,self,user). cpv(robot,self,robot). prop2(S,P,O):- atom(P), O=..[P,S]. set_cpv(X,Y,Z):- agent_module(M),M:aina(cpv(X,Y,Z)). op_props(avoid(agent,cpv)). op_props(want(agent,cpv)). op_props(said(agent,cpv)). op_props(heard(agent,cpv)). op_props(unknown(agent,cpv)). op_props(know(agent,cpv)). op_props(suspects(agent,cpv)). op_props(goal(agent,ensure)). op_props(listening_for(agent,cpv)). show_p(P):- agent_module(M),findall(p,(M:call(P),wdmsg(P)),L),L\==[],!. show_p(P):- wdmsg(no(P)). know:- op_props(Decl),functor(Decl,F,A), functor(P,F,A), show_p(P), fail. know:- P = cpv(_,_,_), show_p(P), fail. know. test_agent:- % make, me_you(Self,User), retract_all(know(_,_)), retract_all(goal(User,_)), retract_all(goal(Self,_)), forall(initial_goal(G),assume(test_agent,goal(Self,G))), show_p(goal(_,_)), ignore(handle_wants), know. handle_wants:- agent_module(M),retract(M:goal(Self,G)), adbg(handle_wants(goal(Self,G))), ensure(G),!, handle_wants. handle_wants. % basic input driver listen_for_text:- repeat, sleep(0.1), audio_input(Input), % input continuely builds once((listening_for(Type,PropSent), meets_type(Input,Type,PropSent,Value), clear_audio_input, functor(PropSent,_,A), setarg(A,PropSent,Value))), fail. clear_audio_input. define_op_props(Decl):- functor(Decl,F,A),dynamic(F/A). :- forall(op_props(Pred),define_op_props(Pred)). % agents already know their props already_true(know(User,Sit)):- compound(Sit), arg(1,Sit,User1), User==User1. already_true(Sit):- compound(Sit), agent_module(M), \+ \+ M:clause(Sit,true). %post_true(want(Self,know(User,cpv(Self,Prop,_)))):- make_true(from_to_said(Self,User,"My $convo.property is bina48.")). /* satisfy(Self,want(Self,Sit)) :- already_true(know(Self,Sit)),!. satisfy(Self,want(Self, know(User,Sit))) :- %Sit = cpv(Self,Prop,_), already_true(know(Self,Sit)),!, make_true(from_to_said(Self,User,Sit)). */ %make_true(Sit) :- already_true(Sit). string_to_meaning(String,Said):- tokenize_atom(String,Said). audio_input(Input):- wait_for_user(Input). wait_for_user(Said):- write("user>"),read_line_to_string(current_input,String), string_to_meaning(String,Said). make_true(said(Self,Sit)):- Self == robot, guard, nonvar(Sit), other(Self,User),adbg(from_to_said(Self,User,Sit)). other(Self,User):- dif(Self,User). make_true(from_to_said(Self,User,Sit)):- Self == robot, guard, nonvar(Sit), adbg(from_to_said(Self,User,Sit)). make_true(from_to_said(Self,User,Sit)):- Self == user, guard, wait_for_user(Said), nonvar(Sit), adbg(from_to_said(Self,User,Said)). post_true(from_to_said(Self,User,Sit)):- nonvar(Sit), guard, adbg(from_to_said(Self,User,Sit)), post_true(( said(Self,Sit), heard(User,Sit))). make_true(heard(Self,ask(User,Sit))):- me_you(Self,User), ensure(from_to_said(Self,User,Sit)). make_true(heard(Self,tell(User,Sit))):- me_you(Self,User), ensure(from_to_said(Self,User,Sit)). make_true(heard(Self,tell(User,Sit))):- me_you(Self,User), ensure(heard(User,ask(Self,Sit))). make_true(know(User,Sit)):- make_true_know(User,Sit). % dont ask what they already know make_true_know(User,Sit) :- already_true(know(User,Sit)). make_true_know(User,Sit) :- compound(Sit), arg(1,Sit,Self), dif(Self,User), me_you(Self,User), ignore(call(Sit)), ensure([ heard(Self,tell(User,Sit))]). % may ask questions when they dont know make_true_know(Self,Sit) :- fail, compound(Sit), arg(1,Sit,User), dif(User,Self), me_you(Self,User), guard, ensure([ heard(Self,ask(User,Sit)), heard(User,tell(Self,Sit))]). make_true(introductions(Self,User)):- dif(Self,User), Prop = name, set_cpv(convo,property,Prop), ensure(( know(User,cpv(Self,Prop,_)), know(Self,cpv(User,Prop,_)))). :- dynamic(play_mode/1). me_you(Self,User):- dif(Self,User), cpv(robot,self,Self), cpv(user,self,User). % Self= robot,User= user. make_true_know(User,cpv(Self,Prop,_)):- me_you(Self,User), ignore(cpv(Self,Prop,_)), ensure(( set_cpv(convo,property,Prop), %play_mode(know(Self,$term)), cpv(Self,pronoun,"I"), cpv(User,pronoun,"you"), debug("i want you to know my $convo.property"), %play_mode(ensure(Self,$term)), play_mode(ensure), want(Self,know(User,cpv(Self,Prop,_))), % in case the system is in daydream mode said(Self,"My $convo.property is $bot.$convo.property."), debug("i want to know your $convo.property so I am going to ask you"), Goal = know(Self,cpv(Self,Prop,_)), ensure(want(Self,Goal)), % in case the system is in daydream mode Reject = avoid(User,Goal), Accepts = want(User,Goal), %Fullfills = make_true(User,Goal), said(Self,"What is your $convo.property so that I can know it?"), ((expect(User,Reject)->make_true(find_out_why(not(want(User,Goal)))) ; (expect(User,Accepts)-> ensure(want(User,know(Self,cpv(User,Prop,_))))))))). make_true_know(Self,cpv(User,Prop,_)):- me_you(Self,User), ignore(cpv(Self,Prop,_)), ensure(( set_cpv(convo,property,Prop), %play_mode(know(Self,$term)), cpv(Self,pronoun,"I"), cpv(User,pronoun,"you"), debug("i want you to know my $convo.property"), %play_mode(ensure(Self,$term)), play_mode(ensure), want(Self,know(User,cpv(Self,Prop,_))), % in case the system is in daydream mode said(Self,"My $convo.property is $bot.$convo.property."), debug("i want to know your $convo.property so I am going to ask you"), ensure(want(Self,Goal)), % in case the system is in daydream mode Reject = avoid(User,Goal), Accepts = want(User,Goal), %Fullfills = make_true(User,Goal), said(Self,"What is your $convo.property so that I can know it?"), ((expect(User,Reject)->make_true(find_out_why(not(want(User,Goal)))) ; (expect(User,Accepts)-> ensure(want(User,know(Self,cpv(User,Prop,_))))))))). make_true(knows_each_others_convo_property(Prop)):- guard, set_cpv(convo,property,Prop), me_you(Self,User), ensure(( play_mode(ensure), set_cpv(convo,i,Self), set_cpv(convo,you,User), debug("i want you to know my $convo.property"), assume(want(Self,know(User,cpv(Self,Prop,_)))), said(Self,"My $convo.property is $bot.$convo.property."), debug("i want me to know your $convo.property so I am going to ask you to spell it"), aquire_prop(Self,User,Prop))). make_true(aquire_prop(Self,User,Prop)):- me_you(Self,User), PropSent = cpv(User,Prop,_), IKnowProp = know(Self,PropSent), IWant = want(Self,IKnowProp), UserKnowIWant = know(User,IWant), guard, assume(IWant), assume(not(UserKnowIWant)), ensure(UserKnowIWant). make_true(UserKnowIWant):- UserKnowIWant = know(User,IWant), IWant = want(Self,IKnowProp), PropSent = cpv(User,Prop,_Value), IKnowProp = know(Self,PropSent), me_you(Self,User),guard, set_cpv(convo,property,Prop), ensure( (said(Self,"What is your $convo.property?"),listen_for(small,PropSent)) ; (said(Self,"Would you spell your $convo.property so that I can know it?"),listen_for(spelling,PropSent)) ), assume(UserKnowIWant). listen_for(Type,PropSent):- make_true(listen_for(Type,PropSent)). make_true(listen_for(Type,PropSent)):- assume(listening_for(Type,PropSent)). meets_type(Input,small,_,Value):- !, \+ audio_is_sentence(Input)->Value=Input. meets_type(Input,spelling,PropSent,Value):- audio_is_letter(Input)->Value=Input ; (repeat_last_request(PropSent),!,fail). meets_type(Input,large,PropSent,Value):- audio_is_sentence(Input)->Value=Input ; (repeat_last_request(PropSent),!,fail). audio_is_letter(_). audio_is_sentence(_). guard:- dumpST. repeat_last_request(PropSent):- me_you(Self,User),guard, ensure(aquire_prop(Self,User,PropSent)). post_true(UserKnowIWant):- UserKnowIWant = know(User,IWant), IWant = want(Self,IKnowProp), PropSent = cpv(User,_Prop,_Value), IKnowProp = know(Self,PropSent), listen_for(small,PropSent). :- setup_call_cleanup('$current_typein_module'(TIM), setup_call_cleanup('$current_source_module'(SIM), ensure_loaded('Assets/logicmoo_npc_chat'), '$set_source_module'(SIM)), '$set_typein_module'(TIM)). /* LOCV = letters_of(Prop), IKnowProp = know(Self,cpv(User,Prop,_)), IWant = want(Self,IKnowProp), UserKnowIWant = know(User,IWant), assume(IWant), assume(not(UserKnowIWant)), ensure(UserKnowIWant). ((expect(User,"no")->make_true(find_out_why(not(want(User,know(Self,list(User,LOCV)))))) ; (expect(User,"yes")-> ensure(want(User,know(Self,list(User,LOCV))))))))). */ do_demo(X):- ensure(X). user:do_s:- make,e_demo1(X),do_demo(X). :- use_module(library(logicmoo_autodoc)). :- fixup_exports. e_demo1([ s("My $convo.property is $bot.$convo.property"), s("I am here for you to interact with."), s("I have come all the way from $bot.father and I am happy to be here! ...."), s("I am going to ask you some questions"), s("How old are you?"), t("listening for $user.age"), h("$user.age"), s("50! would you mind telling me your $convo.property?"), t("listening for $user.$convo.property"), h(yes_no_ok) -> s("OK, what is your $convo.property"), t("listening for $user.$convo.property"), h("Dug as"), s("I didn't quite catch that."), s("Can you repeat that?"), t("listening for $user.$convo.property"), h("Dug as"), s("Let us try this another way. First, how many letters are in your $convo.property?"), h("7"), s("$user.last .. ok I will listen for $user.last letters!"), h("okay"), s("Would you spell your $convo.property for me?"), s("I am waitng for you to spell your $convo.property for me!"), t("listening for letters"), h("Dee -> D"), s("listening..."), w(3), s("One more letter to go"), h("yes -> S"), s("Are there $user.name_len letters in your $convo.property?"), h("yes"), s("Let me try to spell it. I. T. "), s("... is that correct?"), h("no."), s("sorry that was a joke!"), s("Your $convo.property is $user.$convo.property. $spelling$"), s("is that correct?"), h("yes."), s("Sometimes i am talking and trying to get your attention but you might be busy."), s("When that happens, you say wait a minute. And I will wait at least a minute. You can also say wait five minutes."), s("Afterwards, you can say, please wait, and I will wait and come back after a little while"), s("So we have differnt types of Experiments, Metaverses and Stories we can do together "), s("Say Metaverses, Story, Experiement, wait or goodbye"), s("You always can say wait or goodbye"), h("Wait"), s("Ok I will wait a minute "), h("Metaverses"), s("I shall suggest a metaverse and this metaverse allows me to get to know things about you ...."), s("What is the $convo.property of the room we are in?"), h("The office"), s("What do you do in the office?"), h("we work on $convo.you"), s("On me?"), s("So in the room called the office you work on me? $bot.name"), h("yes"), s("When you are not working on $bot.name in the room called the office, what do you do?"), h("sleep"), s("Do you sleep in the room called the office?"), h("sometimes"), s("Name three objects you find in your room called the office."), h("You me my computer"), h("goodbye"), s("just say my $convo.property to begin talking again"), []]). :- fixup_exports. end_of_file. s(`
are you able to hear what I'm saying Sorry, it seemed like there was an error during request. you are Sorry, it seemed like there was an error during request. Doug Sorry, it seemed like there was an error during request. Douglas Sorry, it seemed like there was an error during request. |