def test_serialization(): df1 = DialogueFlow('A', initial_speaker=DialogueFlow.Speaker.USER) df1.add_state('A', 'X') df1.add_state('X') df1.add_state('C', 'D') df1.add_state('D') df1.add_user_transition('A', 'D', '$fruit=apple dog') df1.add_system_transition('X', 'C', 'banana catfish') df1.add_system_transition('D', 'A', 'dog apple') #df1.add_system_transition('X', ('movie', 'Y'), 'movie') #df1.run(debugging=True) df2 = DialogueFlow('A', initial_speaker=DialogueFlow.Speaker.USER) df2.add_state('A', 'X') df2.add_state('X') df2.add_state('C', 'D') df2.add_state('D') df2.add_user_transition('A', 'D', '$state=alaska down') df2.add_state(('SYSTEM', 'topic_err'), global_nlu='back') df2.add_state(('one', 'X'), global_nlu='dog') cdf = CompositeDialogueFlow('start', 'topic_err', 'topic', initial_speaker=DialogueFlow.Speaker.USER) cdf.add_component(df1, 'one') cdf.add_component(df2, 'two') cdf.add_state('start', 'greet') cdf.add_state('greet') cdf.add_state('topic', 'topic_err') cdf.add_state('topic_err') cdf.add_system_transition('topic_err', 'topic', 'what do you want to discuss') cdf.add_system_transition('greet', 'topic', 'hello') cdf.add_user_transition('topic', ('one', 'X'), '$animal={catfish, dog}') cdf.add_user_transition('topic', ('two', 'X'), '$item={alaska, bark, down}') cdf.add_user_transition(('one', 'A'), ('SYSTEM', 'topic_err'), 'back') cdf.new_turn() cdf.user_turn('hello') assert cdf.system_turn() == 'hello' s = cdf.serialize() cdf.new_turn() cdf.deserialize(s) cdf.user_turn('bark') assert cdf.controller_name() == 'two' assert cdf.system_turn().strip() == 'what do you want to discuss' s = cdf.serialize() cdf.new_turn() cdf.deserialize(s) cdf.user_turn('catfish') assert cdf.controller_name() == 'one'
def test_serialization(): df1 = DialogueFlow("A", initial_speaker=DialogueFlow.Speaker.USER) df1.add_state("A", "X") df1.add_state("X") df1.add_state("C", "D") df1.add_state("D") df1.add_user_transition("A", "D", "$fruit=apple dog") df1.add_system_transition("X", "C", "banana catfish") df1.add_system_transition("D", "A", "dog apple") # df1.add_system_transition('X', ('movie', 'Y'), 'movie') # df1.run(debugging=True) df2 = DialogueFlow("A", initial_speaker=DialogueFlow.Speaker.USER) df2.add_state("A", "X") df2.add_state("X") df2.add_state("C", "D") df2.add_state("D") df2.add_user_transition("A", "D", "$state=alaska down") df2.add_state(("SYSTEM", "topic_err"), global_nlu="back") df2.add_state(("one", "X"), global_nlu="dog") cdf = CompositeDialogueFlow( "start", "topic_err", "topic", initial_speaker=DialogueFlow.Speaker.USER ) cdf.add_component(df1, "one") cdf.add_component(df2, "two") cdf.add_state("start", "greet") cdf.add_state("greet") cdf.add_state("topic", "topic_err") cdf.add_state("topic_err") cdf.add_system_transition("topic_err", "topic", "what do you want to discuss") cdf.add_system_transition("greet", "topic", "hello") cdf.add_user_transition("topic", ("one", "X"), "$animal={catfish, dog}") cdf.add_user_transition("topic", ("two", "X"), "$item={alaska, bark, down}") cdf.add_user_transition(("one", "A"), ("SYSTEM", "topic_err"), "back") cdf.new_turn() cdf.user_turn("hello") assert cdf.system_turn() == "hello" s = cdf.serialize() cdf.new_turn() cdf.deserialize(s) cdf.user_turn("bark") assert cdf.controller_name() == "two" assert cdf.system_turn().strip() == "what do you want to discuss" s = cdf.serialize() cdf.new_turn() cdf.deserialize(s) cdf.user_turn("catfish") assert cdf.controller_name() == "one"
def test_composite_df_with_error_in_composite(): #NOT A VALID TEST: MODIFY TO MAKE ERROR IN COMPOSITE DIALOGUE FLOW df1 = DialogueFlow('A', initial_speaker=DialogueFlow.Speaker.USER) df1.add_state('A', 'X') df1.add_state('X') df1.add_state('C', 'D') df1.add_state('D') df1.add_user_transition('A', 'D', '$fruit=apple dog') df1.add_system_transition('X', 'C', 'banana catfish') df1.add_system_transition('D', 'A', 'dog apple') #df1.add_system_transition('X', ('movie', 'Y'), 'movie') #df1.run(debugging=True) df2 = DialogueFlow('A', initial_speaker=DialogueFlow.Speaker.USER) df2.add_state('A', 'X') df2.add_state('X') df2.add_state('C', 'D') df2.add_state('D') df2.add_user_transition('A', 'D', '$state=alaska down') df2.add_state(('SYSTEM', 'topic_err'), global_nlu='back') df2.add_state(('one', 'X'), global_nlu='dog') cdf = CompositeDialogueFlow('start', 'topic_err', 'topic', initial_speaker=DialogueFlow.Speaker.USER) cdf.add_component(df1, 'one') cdf.add_component(df2, 'two') cdf.add_state('start', 'greet') cdf.add_state('greet') cdf.add_state('topic', 'topic_err') cdf.add_state('topic_err') cdf.add_system_transition('topic_err', 'topic', 'what do you want to discuss') cdf.add_system_transition('greet', 'topic', 'hello') cdf.add_user_transition('topic', ('one', 'X'), '$animal={catfish, dog}') cdf.add_user_transition('topic', ('two', 'X'), '$item={alaska, bark, down}') cdf.add_user_transition(('one', 'A'), ('SYSTEM', 'topic_err'), 'back') cdf.user_turn('hello') assert cdf.system_turn() == 'hello' cdf.user_turn('bark') assert cdf.controller_name() == 'two' assert cdf.system_turn().strip() == 'what do you want to discuss' cdf.user_turn('catfish') assert cdf.controller_name() == 'one'
def __init__( self, initial_state: Union[Enum, str, tuple] = "", initial_speaker=DialogueFlow.Speaker.USER, macros: Dict[str, Macro] = None, kb: Union[KnowledgeBase, str, List[str]] = None, default_system_state=None, end_state="__end__", all_multi_hop=True, wordnet=False, dialogflow=None, ): if dialogflow: self.df = dialogflow else: assert initial_state self.df = DialogueFlow( initial_state, initial_speaker, macros, kb, default_system_state, end_state, all_multi_hop, wordnet, ) self.local_user_transitions = collections.defaultdict(dict) self.global_user_transitions = {} self.error_transitions = {} self.states = set() if initial_state: self._add_states(initial_state)
def test_composite_df_with_error_in_composite(): # NOT A VALID TEST: MODIFY TO MAKE ERROR IN COMPOSITE DIALOGUE FLOW df1 = DialogueFlow("A", initial_speaker=DialogueFlow.Speaker.USER) df1.add_state("A", "X") df1.add_state("X") df1.add_state("C", "D") df1.add_state("D") df1.add_user_transition("A", "D", "$fruit=apple dog") df1.add_system_transition("X", "C", "banana catfish") df1.add_system_transition("D", "A", "dog apple") # df1.add_system_transition('X', ('movie', 'Y'), 'movie') # df1.run(debugging=True) df2 = DialogueFlow("A", initial_speaker=DialogueFlow.Speaker.USER) df2.add_state("A", "X") df2.add_state("X") df2.add_state("C", "D") df2.add_state("D") df2.add_user_transition("A", "D", "$state=alaska down") df2.add_state(("SYSTEM", "topic_err"), global_nlu="back") df2.add_state(("one", "X"), global_nlu="dog") cdf = CompositeDialogueFlow( "start", "topic_err", "topic", initial_speaker=DialogueFlow.Speaker.USER ) cdf.add_component(df1, "one") cdf.add_component(df2, "two") cdf.add_state("start", "greet") cdf.add_state("greet") cdf.add_state("topic", "topic_err") cdf.add_state("topic_err") cdf.add_system_transition("topic_err", "topic", "what do you want to discuss") cdf.add_system_transition("greet", "topic", "hello") cdf.add_user_transition("topic", ("one", "X"), "$animal={catfish, dog}") cdf.add_user_transition("topic", ("two", "X"), "$item={alaska, bark, down}") cdf.add_user_transition(("one", "A"), ("SYSTEM", "topic_err"), "back") cdf.user_turn("hello") assert cdf.system_turn() == "hello" cdf.user_turn("bark") assert cdf.controller_name() == "two" assert cdf.system_turn().strip() == "what do you want to discuss" cdf.user_turn("catfish") assert cdf.controller_name() == "one"
from emora_stdm import DialogueFlow, CompositeDialogueFlow A = DialogueFlow("start") A.load_transitions({ "state": "start", "`Let's talk about books!`": { "error": { "`What's your favorite book?`": { "error": { "`Cool!`": "end", "`Okay.`": "movies:movie_question" } } } }, }) B = DialogueFlow("start") B.load_transitions({ "`Let's talk about movies!`": { "state": "start", "error": { "state": "movie_question", "`What is your favorite movie?`": { "error": { "`That's a good one!`": {} } }, }, } })
from emora_stdm import DialogueFlow chatbot = DialogueFlow('start') transitions = { 'state': 'start', '"Hello. How are you?"': { '[{good, okay, fine}]': { '"Good. I am doing well too."': { 'error': { '"See you later!"': 'end' } } }, 'error': { '"Well I hope your day gets better!"': { 'error': { '"Bye!"': 'end' } } } } } chatbot.load_transitions(transitions) chatbot = DialogueFlow('start') transitions = { '"Hello."': { '#INT(Hi! How are you?)': { '"Good. How are you?"': { '[{good, great, okay}]': {
knowledge = KnowledgeBase() knowledge.load_json(ontology) df = DialogueFlow(State.S0, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={ "syn_det": syn_det(), "fave_games": fave_games(), "SPECIFIC1a": SPECIFIC1a(), "SPECIFIC2a": SPECIFIC2a(), "SPECIFIC2b": SPECIFIC2b(), "SPECIFIC3a": SPECIFIC3a(), "SPECIFIC3b": SPECIFIC3b(), "GENRE_OPINION": GENRE_OPINION(), "GENRE_RECOMMENDER": GENRE_RECOMMENDER(), "like_macro": like_macro(), "dislike_macro": dislike_macro(), "game_desc": game_desc(), "game_catcher": game_catcher(), "game_catcher_parttwo": game_catcher_parttwo(), "list_items_one": list_items_one(), "list_items_two": list_items_two(), "explain_response": explain_response(), "genre_pivot": genre_pivot(), "genre_pivot_learning": genre_pivot_learning(), "list_items_two": list_items_two(), "explain_response": explain_response(), "genre_pivot": genre_pivot(), "metaComp": metaComp() }) ### Main Prompt - Do you play video games?
from emora_stdm import DialogueFlow, CompositeDialogueFlow A = DialogueFlow('start') A.load_transitions({ 'state': 'start', '`Let\'s talk about books!`': { 'error': { '`What\'s your favorite book?`': { 'error': { '`Cool!`': 'end', '`Okay.`': 'movies:movie_question' } } } } }) B = DialogueFlow('start') B.load_transitions({ '`Let\'s talk about movies!`': { 'state': 'start', 'error': { 'state': 'movie_question', '`What is your favorite movie?`': { 'error': { '`That\'s a good one!`': {} } } } } })
from emora_stdm import DialogueFlow system = DialogueFlow("start", end_state="end", initial_speaker=DialogueFlow.Speaker.USER) system.load_transitions({ "state": "start", "[{hi, hello}]": { "`Hi!`": { "score": 3.0, "error": { "`Bye.`": "end" } } }, "error": { "`Bye`": "end" }, }) system.load_update_rules({ "[news]": "`Coronavirus, argh!` (4.0)", "[{movie, movies}]": "`Avengers is a good one.` (4.0)", "/.*/ (0.1)": "`I'm not sure I understand.` (2.0)", }) if __name__ == "__main__": system.run(debugging=True)
ASK_CELEB = auto() REC_CELEB_ANS = auto() COMMENT_CELEB = auto() UNKNOWN_CELEB = auto() UNKNOWN_LOC = auto() CELEB_LOCATION = auto() ACK = auto() ACT = auto() REC_ACT = auto() UNKNOWN_ACT = auto() DESC = auto() REC_DESC = auto() UNKNOWN_DESC = auto() df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM) df.add_system_transition(State.START, State.ASK_CELEB, '"Who is your favorite celebrity?"') # NER to find people names that are mentioned df.add_user_transition(State.ASK_CELEB, State.REC_CELEB_ANS, '[$fave_celeb=#NER(person)]') df.set_error_successor(State.ASK_CELEB, State.UNKNOWN_CELEB) df.add_system_transition( State.REC_CELEB_ANS, State.CELEB_LOCATION, '[!"I really like" $fave_celeb "too! Where do you think they live?"]') df.add_system_transition(
from emora_stdm import DialogueFlow df = DialogueFlow('root', initial_speaker=DialogueFlow.Speaker.SYSTEM) flow = { 'state': 'root', 'hello': { '[hi]': { 'have you seen a good movie recently':{ '[yes]': { 'cool what is it':{ 'error': 'root' } }, '[no]':{ 'ok then': { 'error': 'root' } } }, 'how are you': { '[good]': { 'thats good': { 'error': 'root' } }, '[bad]': { 'sorry to hear that':{
return "They actually control 7% of the global market, but they are very concentrated in China. " \ "Even then, they can't compare to Amazon's 47% of global market share" elif args[0] == "salesforce" or args[0] == "oracle" or args[ 0] == "cisco": return "They aren't that big, but they still provide some services, especially internally. Amazon, however, is the big player of the" \ "cloud market with 47% of market share" else: return "" knowledge = KnowledgeBase() knowledge.load_json(ontology) df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={ 'appCheck': appCheck(), 'providerInfo': providerInfo() }) # System (1) df.add_system_transition( State.START, State.Knowledge, r'[!"Hi, do you know anything about cloud computing?"]') # transition for no or kinda: User (1) df.add_user_transition(State.Knowledge, State.Knowledge_No, "[#ONT(disagree)]") df.add_user_transition(State.Knowledge, State.Knowledge_Kinda, "[#ONT(kinda)]") # System (2) df.add_system_transition( State.Knowledge_No, State.Explain, r'[! "Oh thats okay. Cloud computing just means that the storage, ' r'management, and processing of your app data happens offsite"]')
in the natex returning a set of strings replaces macro with a disjunction returning a boolean will replace the macro with wildcards (True) or an unmatchable character sequence (False) returning an arbitrary object is only used to pass data to other macros """ temp = ont_dict["ontology"] return random.choice(temp[args[0]]) # In[713]: knowledge = KnowledgeBase() knowledge.load_json(ont_dict) df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={'MyMacro': MyMacro(1)}) # Function to add user transition states that uses "yes" regex yes_add() no_add() df.add_system_transition( State.START, State.START_REPLY, '"hi! my name is roko. i love playing video games, and its kind of the only thing i do. do you like games?"' ) # df.add_user_transition(State.START_REPLY, State.LIKE_GAME_Y, "<$response=/(?:^|\s)(yea|ya|ye|yes|yeah|i do|i like)(?:\s|,|\.|$)/>") # df.add_user_transition(State.START_REPLY, State.LIKE_GAME_N, "<$response={no, nope, nah, no way, i dont}>") df.set_error_successor(State.START_REPLY, State.ERR) df.add_system_transition(State.ERR, State.START_REPLY, '"Hmm.. i only like video games"')
################################ # Modify ont_dict for Quiz2 Task 3 ################################ ont_dict = { "ontology": { "ontamphibian": ["frog", "salamander"], "ontyes": ["yea", "yeah"] } } ################################ knowledge = KnowledgeBase() knowledge.load_json(ont_dict) df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={"VERSION": VERSION()}) df.add_system_transition(State.START, State.PROMPT, '"Enter an animal"') #df.add_user_transition(State.PROMPT, State.MAMMAL, '[$reason=/.*/]') df.add_user_transition(State.PROMPT, State.MAMMAL, time_natex) df.add_system_transition(State.MAMMAL, State.BIRD, r'[!oh are you using #VERSION"?"]') df.add_system_transition(State.MAMMAL, State.PROMPT, '[! $animal " is a mammal, enter another animal"]') df.add_system_transition(State.BIRD, State.PROMPT, '[! $animal "is a bird, enter another animal"]')
if 'industry' in vars: for key, value in industry_company.items(): if key in vars['industry']: return value class posSkill(Macro): def run(self, ngrams, vars, args): if 'pos' in vars: for key, value in pos_skill.items(): if key in vars['pos']: return value knowledge = KnowledgeBase() knowledge.load_json(ind_pos) knowledge.load_json(ind_comp) df = DialogueFlow(State.S1, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={"placeInd": placeInd(),"indComp":indComp(),"posSkill":posSkill()}) df.add_system_transition(State.S1, State.U1, '"Where do you want to work?"') df.add_user_transition(State.U1, State.S2a, '[$loc={new york,ny,la,los angeles,chicago,dallas,washington dc,dc,west,east,bay,san francisco,sf,houston,boston,bos,atl,atlanta,seattle,sea,san jose}]', score=1) df.add_user_transition(State.U1, State.S2b, '[$loc={new york,ny,la,los angeles,chicago,dallas,washington dc,dc,west,east,bay,san francisco,sf,houston,boston,bos,atl,atlanta,seattle,sea,san jose}]') df.add_user_transition(State.U1, State.S2c, '[$comp=#ONT(ontfinanc)]', score = 2) df.add_user_transition(State.U1, State.S2d, '[$comp=#ONT(ontconsultin)]', score = 2) df.add_user_transition(State.U1, State.S2e, '[$comp=#ONT(onttechnolog)]', score = 2) df.add_user_transition(State.U1, State.S2f, '[$comp=#NER(org)]', score = 1) df.add_user_transition(State.U1, State.S2g, '[{dont know,do not know,unsure,[not,{sure,certain,considered,consider,thought}],hard to say,no idea,uncertain,[!no {opinion,opinions,idea,ideas,thought,thoughts,knowledge}]}]') df.set_error_successor(State.U1, error_successor=State.ERR1) df.add_system_transition(State.S2a, State.U2a, '[!Sure"." $loc is a great place to work"!" There are a lot of #placeInd companies there"." What industry are you interested in"?"]') df.add_system_transition(State.S2b, State.U2a, '[!I also think $loc is a great place to work"!" There are a lot of #placeInd companies there"." What industry are you interested in"?"]') df.add_system_transition(State.S2g, State.U2a, '"Oh it is fine that you have not decide where to work at. Do you have an industry that you are interested in?"') df.add_system_transition(State.S2c, State.U3a, '[!$comp is a great bank"." What position in $comp are you interested in"?"]')
from emora_stdm import DialogueFlow import json df = DialogueFlow('start') df.knowledge_base().load_json_file('ontology_example.json') df.load_transitions({ 'state': 'start', '`What is your favorite animal?`': { '[#ONT(mammal)]': { '`I think mammals are cool too!`': 'start' }, '[#ONT(reptile)]': { '`Reptiles are cool.`': 'start' }, '[$animal=#ONT(animal)]': { 'score': 0.5, '`I like` $animal `too.`': 'start' }, 'error': { '`I\'ve never heard of that animal.`': 'start' } } }) if __name__ == '__main__': df.run()
from emora_stdm import DialogueFlow df = DialogueFlow("root", initial_speaker=DialogueFlow.Speaker.SYSTEM) flow = { "state": "root", "hello": { "[hi]": { "have you seen a good movie recently": { "[yes]": { "cool what is it": { "error": "root" } }, "[no]": { "ok then": { "error": "root" } }, }, "how are you": { "[good]": { "thats good": { "error": "root" } }, "[bad]": { "sorry to hear that": { "error": "root" } },
"thriller": [ "creepy", "spooky", "scary", "exhilarating", "horror", ] } } knowledge = KnowledgeBase() knowledge.load_json(ontology) df = DialogueFlow(State.S0, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={ "SPECIFIC": SPECIFIC(), "TVorMovie": TVorMovie(), "REC": REC() }) # NaTex netflix_prime = r"[!-{[#ONT(hulu)], [#ONT(disney plus)], " \ r"[#ONT(negative)]}, {[$stream=#ONT(netflix)], [$stream=#ONT(amazon prime)]}]" hulu = r"[!-{[#ONT(amazon prime)], [#ONT(disney plus)], [#ONT(netflix)], [#ONT(negative)]}, [$stream=#ONT(hulu)]]" dplus = r"[!-{[#ONT(amazon prime)], [#ONT(hulu)], [#ONT(netflix)], [#ONT(negative)]}, [$stream=#ONT(disney plus)]]" affirm = r"[!-[#ONT(negative)],[#ONT(positive)]]" deny = r"[!-[#ONT(positive)],[#ONT(negative)]]" pirate_own = r"[!-[#ONT(rentLibs)], [#ONT(ownTvPirate)]]" rent = r"[!-[#ONT(ownTVPirate)], [#ONT(rentLibs)]]"
from emora_stdm import DialogueFlow system = DialogueFlow('start', end_state='end', initial_speaker=DialogueFlow.Speaker.USER) system.load_transitions({ 'state': 'start', '[{hi, hello}]': { '`Hi!`':{ 'score': 3.0, 'error': { '`Bye.`': 'end' } } }, 'error': { '`Bye`': 'end' } }) system.load_update_rules({ '[news]': '`Coronavirus, argh!` (4.0)', '[{movie, movies}]': '`Avengers is a good one.` (4.0)', '/.*/ (0.1)': '`I\'m not sure I understand.` (2.0)', }) if __name__ == '__main__': system.run(debugging=True)
query_first_result = requester.search_for_artist(fav_artist_name)[0] artist_id = query_first_result['id'] artist_features = requester.get_artist_avg_features(artist_id) # these next two lines are for testing. Remove once macro is up and running for key, val in artist_features: print(""+key+""+val) # TODO: build a way to turn artist feature metrics into qualitative descriptives # TODO: create the ontology as needed ontology = json.loads(open('ontology.json').read()) knowledge = KnowledgeBase() knowledge.load_json(ontology) df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={"ARTIST_QUALITIES": ARTIST_QUALITIES(), "ARTIST_GENRE": ARTIST_GENRE()}) df.add_system_transition(State.START, State.RES, '"Do you listen to music?"') df.add_user_transition(State.RES, State.YES, '[#ONT(yes)]') df.add_user_transition(State.RES, State.NO, '[#ONT(no)]') # Error df.set_error_successor(State.RES, State.RES_ERROR) df.add_system_transition(State.RES_ERROR, State.RES2, '"Sorry, I didn\'t catch that. Do you listen to music?"') df.add_user_transition(State.RES2, State.YES, '[#ONT(yes)]') df.add_user_transition(State.RES2, State.NO, '[#ONT(no)]') df.set_error_successor(State.RES2, State.RES_ERROR2) df.add_system_transition(State.RES_ERROR2, State.ERR, '"Sorry, I still didn\'t catch that. Let\'s start over."')
from emora_stdm import DialogueFlow system = DialogueFlow('start', initial_speaker=DialogueFlow.Speaker.USER) system.load_transitions({'state': 'start', 'error': {'` `': {'score': -1, 'state': 'start'}}}) system.load_update_rules({ '[news]': '`Coronavirus, argh!` (1)', '[{movie, movies}]': '`Avengers is a good one.` (1)', '/.*/ (0.1)': '`I\'m not sure I understand.` (1)', }) if __name__ == '__main__': system.run()
"dislike_adj": ["superficial", "fake", "vain", "basic", "unoriginal"], "time": [ "wastes time", "waste of time", "time", "hours", "all day", "addictive" ], "likable": ["apps", "fads", "technology", "socializing", "social media"] } } knowledge = KnowledgeBase() knowledge.load_json(ontology) df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={ "NUMBERCOMP": NUMBERCOMP(), "HOURSCOMP": HOURSCOMP() }) #start df.add_system_transition(State.START, State.PROMPT, '"Do you like Instagram?"') #if user says yes (likes Instagram) df.add_user_transition(State.PROMPT, State.YES, "[#ONT(ontaffirmative)]") df.add_system_transition(State.YES, State.WHYLIKE, 'What features do you like"?"') # error handler for first prompt df.set_error_successor(State.PROMPT, State.ERR_PROMPT) df.add_system_transition(State.ERR_PROMPT, State.IMPROVE_Q,
from emora_stdm import DialogueFlow system = DialogueFlow("start", initial_speaker=DialogueFlow.Speaker.USER) system.load_transitions({ "state": "start", "error": { "` `": { "score": -1, "state": "start" } } }) system.load_update_rules({ "[news]": "`Coronavirus, argh!` (1)", "[{movie, movies}]": "`Avengers is a good one.` (1)", "/.*/ (0.1)": "`I'm not sure I understand.` (1)", }) if __name__ == "__main__": system.run()
], "outgoing": ["outgoing", "extraverted", "sociable", "social", "friendly", "warm"], "shy": ["shy", "intraverted", "guarded", "loner"], "polite": ["polite", "manners", "decent"], "conceited": [ "conceited", "overconfident", "arrogant", "full of", "narcissistic", "egotistic", "egotistical", "selfish" ], "beautiful": ["gorgeous", "pretty", "hot", "sexy"] } } kb = KnowledgeBase() kb.load_json(kb_dict) df = DialogueFlow(initial_state="root", kb=kb) root = 'root' end = 'end' df.add_state(root, error_successor=root, memory=0) df.add_state(end, error_successor=end) df.add_system_transition(root, end, 'I have no nonrepetitive options', score=0) # S: Who do you live with? root = 'root' df.add_state('opening live with', error_successor=root) df.add_system_transition(root, 'opening live with', '[!#GATE() "So, who do you live with?"]') df.add_user_transition( 'opening live with', root,
str += "I just don't see how he would suddenly get better." if (player('2019-20').minutes_played / player('2019-20').games_played < 12 or player('2019-20').minutes_played == None): str += "Besides, who is this player anyways because I've never heard of him." return str knowledge = KnowledgeBase() knowledge.load_json_file("teams.json") df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={ 'news': news(), 'newsPlayer': newsPlayer(), 'newsTeam': newsTeam(), 'teamStats': teamStats(), 'playerRating': playerRating(), 'goodBadTrade': goodBadTrade(), 'tradeNews': tradeNews() }) ######################### # THIS DOCUMENT IS THE SOURCE OF TRUTH FOR WHAT WE ARE DOING: https://docs.google.com/document/d/15N6Xo60IipqOknUGHxXt-A17JFOXOhMCZSMcOAyUEzo/edit ########################## # natex expressions dont_know = '[{' \ 'dont know,do not know,unsure,maybe,[not,{sure,certain}],hard to say,no idea,uncertain,i guess,[!no {opinion,opinions,idea,ideas,thought,thoughts,knowledge}],' \ '[{dont,do not}, have, {opinion,opinions,idea,ideas,thought,thoughts,knowledge}],' \ '[!{cant,cannot,dont} {think,remember,recall}]' \
class COMPCHAR(Macro): def run(self, ngrams, vars, args): if 'notchosen' in vars: a = "" for key in comp_char_dict: if key in vars['notchosen']: a = comp_char_dict[key] return a df = DialogueFlow(State.S1, initial_speaker=DialogueFlow.Speaker.SYSTEM, macros={ "elabCon": elabCon(), "elabPro": elabPro(), "EXPLfield": EXPLfield(), "YEAR": YEAR(), "company": company(), "choosecomp": chooseComp(), "COMPCHAR": COMPCHAR() }) pro = r"[$pro={secure,security,safe,safety, [{accident,accidents}, /reduce[sd]?|decrease[sd]?/], [{few,fewer,reduce,reduces,reduced}, {accident,accidents}], /disable[d]?|disability/, traffic,traffics, environment,environmental,free,attention,attentions}]" con = "[$con={</more|increase[d]?|increasing|/, /car[s]?|people/>,hack,hacked,hacker,crash,crashed,crashing,moral,morality,immoral,immorality,ethic, expensive,price,job,jobs, /like[s]?\sdriving/, /regulate[s]?|regulation|law[s]?|act[s]?/,insecure,insecurity,danger,dangerous,not secure,not safe}]" con1 = r'[{no, not really, nah}, [$con={danger, not safe}]]' procon = "{[$pro={/economic[s]?|economy\s?(benefit[s]?)?/, /secure|security/, [/accident[s]?/, /reduce[d]?|decrease[sd]?|cut\sdown/], [/few|fewer/, /accident[s]?/], /disable[d]?|disability/, </traffic|traffics/, /quick|quicker|fast|faster|better|good|improve[d]?|solve[d]?/>, /environment|environmental/, free}], $con={</more|increase[d]?|increasing|/, /car[s]?|people/>, {hack,hacked,hacker,crash,crashed,crashing}, {moral,morality,immoral,immorality}, {expensive,price}, {job,jobs}, /like[s]?\sdriving/, /regulate[s]?|regulation|law[s]?|act[s]?/}]}" df.add_system_transition(State.S1, State.U1, r'"Do you drive?"') df.add_user_transition(State.U1, State.S2a, r'[{yes, yeah, yep, yea, ye, of course}]')
"quesadilla", "enchilada", "fajita", "gordita", "pozole", "kmchi", "bulgogi", "japchae", "bibimbap", "ddukbokki", "samgyeopsal", "jjajangmyeon", "kimbap", "doenjang jjigae" ], "sour": ["gelato", "sweet and sour pork", "caldo de queso", "kimchi"] } } knowledge = KnowledgeBase() knowledge.load_json(ontology) df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge, macros={ "RANDCUISINE": RANDCUISINE(), "CHECK": CHECK(), "INFLUENCE": INFLUENCE(), "REASON": REASON(), 'DISHES': DISHES(), 'RANDFOOD': RANDFOOD() }) # S0 df.add_system_transition(State.START, State.U0, '"What kind of cuisine do you like?"') df.add_user_transition(State.U0, State.S1, '$cuisine=[#ONT(ontCuisines)]') df.set_error_successor(State.U0, State.S0ERR) df.add_system_transition(State.S0ERR, State.U1, '#RANDCUISINE') # S1 df.add_system_transition(
# ontology ontology = { "ontology": { "non_home_locations": [ "work", "office", "lab", "class", "lecture", "meeting", "travel", "school" ] } } # start knowledge = KnowledgeBase() knowledge.load_json(ontology) df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge) # desktop or laptop df.add_system_transition( State.START, State.NAME_Q, '"hello, I am Emily, a virtual chatbot, what is your name? (Please simply type your name.)"' ) df.add_user_transition(State.NAME_Q, State.NAME_R, '[$name=/.*/]') df.add_system_transition(State.NAME_R, State.COM_Q, '[!"Hi"$name", do you have a computer?"]') df.add_user_transition(State.COM_Q, State.COM_NO, '[{No,no,not,nah,Nah,N,n}]') df.add_system_transition( State.COM_NO, State.COM_Q, '"Well, you should get a computer.' '\n Here are some websites where you can buy a comptuer:' '\n www.bestbuy.com'
from emora_stdm import DialogueFlow chatbot = DialogueFlow("start") transitions = { "state": "start", '"Hello. How are you?"': { "[{good, okay, fine}]": { '"Good. I am doing well too."': { "error": { '"See you later!"': "end" } } }, "error": { '"Well I hope your day gets better!"': { "error": { '"Bye!"': "end" } } }, }, } chatbot.load_transitions(transitions) chatbot = DialogueFlow("start") transitions = { '"Hello."': { "#INT(Hi! How are you?)": { '"Good. How are you?"': { "[{good, great, okay}]": { '"That\'s great!" Bye!': "end"