예제 #1
0
df.add_user_transition(State.U9, State.S10B, no_natex)
df.add_system_transition(
    State.S10B, State.U10,
    r'[!AR and VR may seem not as impressive just yet, but as more people start to invest in these products, '
    r'the more content that will be created by developers "!" AR and VR are the futures of gaming and'
    r' entertainment, but they also have many commercial and educational uses.'
    r' The next stage of this technology will be Mixed Reality, where virtual and mutatable objects can be placed in '
    r'an augmented world. The future is very exciting and all of this is coming much quicker than we expect "!" '
    r'I hope you will invest in AR and VR products in the future "!"]')

df.add_user_transition(State.U10, State.END, "/.*/")
df.add_system_transition(
    State.END, State.END,
    r'[!Thank you for the wonderful conversation, have a nice rest of your day "!"]'
)

#ERROR STATES
df.add_system_transition(State.ERR, State.ERR, r"[!Oops...I Broke]")
df.set_error_successor(State.U0, error_successor=State.S1B)
df.set_error_successor(State.U1, error_successor=State.S2_google)
df.set_error_successor(State.U2, error_successor=State.S3A)
df.set_error_successor(State.U3A, error_successor=State.S4C)
df.set_error_successor(State.U3B, error_successor=State.S4C)
df.set_error_successor(State.U4, error_successor=State.S5B)
df.set_error_successor(State.U5, error_successor=State.S6_ugly)
df.set_error_successor(State.U6, error_successor=State.S7A)
df.set_error_successor(State.U7, error_successor=State.S8A)
df.set_error_successor(State.U8, error_successor=State.S9)
df.set_error_successor(State.U9, error_successor=State.S10B)

df.run(debugging=False)
예제 #2
0
                  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,
                         '"I see. How do you think Instagram can improve?"')

##4 different states depending on what part of speech the feature is
df.add_user_transition(State.WHYLIKE, State.FEATN,
                       "[$feat=#ONT(feature_noun)]")
df.add_system_transition(
    State.FEATN, State.YN,
    'Do you like the [! $feat "feature more than on Facebook?"]')

df.add_user_transition(State.WHYLIKE, State.FEATV, "[$feat=#ONT(feature_ing)]")
df.add_system_transition(
    State.FEATV, State.YN,
    'Do you like [! $feat "on Instagram more than on Facebook?"]')
예제 #3
0
    r'[!I also think $chosen is the pioneer in Autonomous Vehicles since it has an experienced self driving system that lets its autonomous cars learn from the world"’"s longest and toughest driving test including millions of miles on public roads and billions of miles in simulation.]'
)
df.add_system_transition(
    State.S11b, State.U11b,
    r'[!I know $notchosen is #COMPCHAR"." However I think Waymo"/"Google is the most successful firm in this field because it has an experienced self driving system that lets its autonomous cars learn from the world"’"s longest and toughest driving test including millions of miles on public roads and billions of miles in simulation.]'
)
df.add_system_transition(
    State.S11c, State.U11c,
    r'[!I am not very familiar with $userchosen"," could you tell me more about it"?"]'
)

df.add_user_transition(State.U11a, State.END, "/.*/")
df.add_user_transition(State.U11b, State.END, "/.*/")
df.add_user_transition(State.U11c, State.END, "/.*/")

df.set_error_successor(State.U1, error_successor=State.ERR1)
df.add_system_transition(
    State.ERR1, State.U3a,
    r'"I do not understand. But would you like to have cars to drive themselves and take you to the destination?"'
)
df.set_error_successor(State.U2a, error_successor=State.ERR2)
df.add_system_transition(
    State.ERR2, State.U3a,
    r'"I do not understand. But would you like to have cars to drive themselves and take you to the destination?"'
)
df.set_error_successor(State.U2b, error_successor=State.ERR3)
df.add_system_transition(
    State.ERR3, State.U3a,
    r'"I do not understand. But would you like to have cars to drive themselves and take you to the destination?"'
)
df.set_error_successor(State.U3a, error_successor=State.S4a)
예제 #4
0
                  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(
    State.S1, State.U1,
    '[! I think $cuisine food is quite tasty as "well." Do you have any $cuisine food that you "like?"]'
)
df.add_user_transition(State.U1, State.S2, '[$dish=#ONT(#DISHES)]')
df.set_error_successor(State.U1, State.S1ERR)
df.add_system_transition(State.S1ERR, State.U2, '#RANDFOOD')

# S2
df.add_system_transition(
    State.S2, State.U2,
    '[!Oh yeah, I have heard of $dish "before." Do you know any history behind the "food?"]'
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)]]"

cheap = r"[!-[#ONT(variety)], [#ONT(cheap)]]"
variety = r"[!-[#ONT(cheap)], [#ONT(variety)]]"

tv_movie = r"[!-[#ONT(conjunction)], {[$mediaType=#ONT(tv show)], [$mediaType=#ONT(movie)]}]"

# End State
df.add_system_transition(State.ENDF, State.ENDF, 'Conversation Ended')
df.set_error_successor(State.ENDF, error_successor=State.ENDF)

# Turn 0
df.add_system_transition(State.S0, State.S1,
                         '"Do you use any movie streaming services?"')
df.add_user_transition(
    State.S1, State.U1a,
    '[!-{[#ONT(streamServices)], [#ONT(multiple)], [#ONT(negative)]}, [#ONT(positive)]]'
)
df.add_user_transition(State.S1, State.U1b, netflix_prime)
df.add_user_transition(
    State.S1, State.U1c,
    '[!-{[#ONT(streamServices)], [#ONT(negative)]}, <[#ONT(multiple)], #ONT(positive)>]'
)
df.add_user_transition(State.S1, State.U1e, hulu)
df.add_user_transition(State.S1, State.U1f, dplus)
예제 #6
0
    }
}

knowledge = KnowledgeBase()
knowledge.load_json(ontology)
df = DialogueFlow(State.START,
                  initial_speaker=DialogueFlow.Speaker.SYSTEM,
                  kb=knowledge)

df.add_system_transition(
    State.START, State.t0,
    '"Would you like to hear some suggestions of fun activities to try?"')

df.add_user_transition(State.t0, State.t1, r"[#ONT(yes)]")
df.add_user_transition(State.t0, State.a0, r"[#ONT(no)]")
df.set_error_successor(State.t0, State.a1)

df.add_system_transition(
    State.t1, State.t2,
    '"You should try making some focaccia bread! I recommend topping it with '
    'roasted red pepper and garlic. Would you like to hear another '
    'suggestion?"')
df.add_system_transition(
    State.a0, State.a2,
    '"One and done, huh? I hope you do bake! Baking helps me calm down, \n'
    'what are some things that help calm you down?"')
df.add_system_transition(
    State.a1, State.a3,
    '"I won\'t keep throwing these at you, but I hope you try it! \n'
    'Baking keeps me calm. '
    'What are some activities that help calm you down?"')
예제 #7
0
df.add_system_transition(State.IOWN, State.OTHER_DEVICE, natex_device_age)
df.add_user_transition(State.OTHER_DEVICE, State.BRAND, "[$brand=#ONT(ontbrand)]", score=2)
df.add_user_transition(State.OTHER_DEVICE, State.USED_OTHER_DEVICE, "[$response=#ONT(ontyes)]", score=1)
df.add_user_transition(State.OTHER_DEVICE, State.NOMORE_OTHER_DEVICE, "[$response=#ONT(ontno)]", score=1)

df.add_system_transition(State.USED_OTHER_DEVICE, State.PLATFORM_GAME_PROMPT, '"Wow! You\'re an experienced VR user. What other brand have you tried?"')
df.add_system_transition(State.NOMORE_OTHER_DEVICE, State.END, '"No worries! Thanks for chatting today, goodbye!"')



## Error handling!

df.add_system_transition(State.NO_VG, State.END, '"Sorry to hear that. That\'s all I know about. Goodbye!"')
df.add_system_transition(State.END, State.END, '"That\'s all for now, goodbye!!"')
df.set_error_successor(State.END, State.END)

df.add_system_transition(State.USED_PROMPT_ERR, State.USED_PROMPT, '"Not sure what you said, have you used VR before?"')
df.set_error_successor(State.USED_PROMPT, State.USED_PROMPT_ERR)

df.add_system_transition(State.UNFAMILIAR_ERR, State.UNFAMILIAR, '"I didn\'t catch that, do you play video games?"')
df.set_error_successor(State.UNFAMILIAR, State.UNFAMILIAR_ERR)

df.add_system_transition(State.FAVE_GAME_NOVR_ERR, State.END, '"That\'s a great game! Consider checking out VR if you enjoy video games. Bye for now!"')
df.set_error_successor(State.FAVE_GAME_NOVR, State.FAVE_GAME_NOVR_ERR)

df.add_system_transition(State.GAME_PROMPT_ERR, State.LIKE_GAME_UNKNOWN, '"I don\'t know that game, but it sounds interesting. Did you like it?"')
df.set_error_successor(State.GAME_PROMPT, State.GAME_PROMPT_ERR)

df.add_system_transition(State.PLATFORM_GAME_PROMPT_ERR, State.DEVICE, '"I don\'t know that brand, what device did you use?"')
df.set_error_successor(State.PLATFORM_GAME_PROMPT, State.PLATFORM_GAME_PROMPT_ERR)
예제 #8
0
파일: CALYPSO.py 프로젝트: simonmarty/emory
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.VERB,
    '"Hmm, well I love listening to music because it makes me less stressed. When do you listen to music?"'
)

#USER DOESNT LISTEN TO MUSIC
df.add_system_transition(State.NO, State.NO_ANS,
                         '"That\'s a shame. Why do you not listen to music?"')
예제 #9
0
# 1: First stage
# (ask user about preferred streaming services)
############################################################

##############################
# 1a: User picks
# streaming site
##############################
# *** USER CAN RESPOND EITHER YES/NO OR IMMEDIATELY PROVIDE THEIR PREFERENCE
df.add_user_transition(State.PROMPT, State.PICK_NETFLIX, netflix_natex)
df.add_user_transition(State.PROMPT, State.PICK_YOUTUBE, youtube_natex)
df.add_user_transition(State.PROMPT, State.PICK_GENERAL_STREAMING_SITE,
                       gen_natex)
df.add_user_transition(State.PROMPT, State.USES_STREAMING_SITE, yes_natex)
df.add_user_transition(State.PROMPT, State.NOT_USES_STREAMING_SITE, no_natex)
df.set_error_successor(State.PROMPT, State.ERR)

df.add_system_transition(State.NOT_USES_STREAMING_SITE,
                         State.ASK_GENERAL_MOVIES_OR_TV,
                         '"Oh, well do you like '
                         'movies or TV?"')

##############################
# 1b: User answers whether
# they like movies or TV
##############################
# *** USER CAN RESPOND EITHER YES/NO OR IMMEDIATELY PROVIDE THEIR PREFERENCE
df.add_user_transition(State.ASK_GENERAL_MOVIES_OR_TV,
                       State.PICK_NETFLIX_MOVIES, movie_natex)
df.add_user_transition(State.ASK_GENERAL_MOVIES_OR_TV, State.PICK_NETFLIX_TV,
                       tv_natex)
예제 #10
0
df.add_system_transition(State.PYRAMID_ENGINEERING_OTHER, State.PYRAMID_ENGINEERING_OTHER_OPTIONS, '"Umm, I do not know about that. There are mainly two theories about how the Ancient Egyptians used engineering to build the pyramids. The ramp theory and the physics theory. Which sounds more probable to you?"')

df.add_user_transition(State.PYRAMID_ENGINEERING_OTHER_OPTIONS, State.PYRAMID_ENGINEERING_RAMP_DETAIL_1, '[{ramp, transport, transportation, travel, smooth}]')
df.add_user_transition(State.PYRAMID_ENGINEERING_OTHER_OPTIONS, State.PYRAMID_ENGINEERING_PHYSICS_DETAIL_1, '[{physics, science, engineering, tools}]')

df.add_system_transition(State.PYRAMID_ENGINEERING_RAMP_DETAIL_1, State.PYRAMID_ENGINEERING_RAMP_DETAIL, '"I agree with you. Ramp theory sounds more probable to me personally. Why do you think they built the pyramids?"')
df.add_system_transition(State.PYRAMID_ENGINEERING_PHYSICS_DETAIL_1, State.PYRAMID_ENGINEERING_PHYSICS_DETAIL, '"I agree with you. Physics sounds more probable to me personally. Why do you think they built the pyramids?"')

# PYRAMID WHY BUILD - USER #
df.add_user_transition(State.PYRAMID_ALIEN_TIMETRAVEL_DETAIL, State.PYRAMID_ALIEN_WHY_1, '[$user_1=#ONT(PYRAMID_FEATURE)]')
df.add_user_transition(State.PYRAMID_ALIEN_OTHER_DETAIL, State.PYRAMID_ALIEN_WHY_1, '[$user_1=#ONT(PYRAMID_FEATURE)]')

df.add_user_transition(State.PYRAMID_ALIEN_TIMETRAVEL_DETAIL, State.PYRAMID_ALIEN_WHY_2, '[$user_1=#POS(noun)]')
df.add_user_transition(State.PYRAMID_ALIEN_OTHER_DETAIL, State.PYRAMID_ALIEN_WHY_2, '[$user_1=#POS(noun)]')

df.set_error_successor(State.PYRAMID_ALIEN_TIMETRAVEL_DETAIL, State.PYRAMID_ALIEN_WHY_3)
df.set_error_successor(State.PYRAMID_ALIEN_OTHER_DETAIL, State.PYRAMID_ALIEN_WHY_3)

df.add_user_transition(State.PYRAMID_WATER_TRANSPORT_DETAIL, State.PYRAMID_GENERIC_WHY_1, '[$user_1=#ONT(PYRAMID_FEATURE)]')
df.add_user_transition(State.PYRAMID_WATER_OTHER_DETAIL, State.PYRAMID_GENERIC_WHY_1, '[$user_1=#ONT(PYRAMID_FEATURE)]')

df.add_user_transition(State.PYRAMID_WATER_TRANSPORT_DETAIL, State.PYRAMID_GENERIC_WHY_2, '[$user_1=#POS(noun)]')
df.add_user_transition(State.PYRAMID_WATER_OTHER_DETAIL, State.PYRAMID_GENERIC_WHY_2, '[$user_1=#POS(noun)]')

df.set_error_successor(State.PYRAMID_WATER_TRANSPORT_DETAIL, State.PYRAMID_GENERIC_WHY_3)
df.set_error_successor(State.PYRAMID_WATER_OTHER_DETAIL, State.PYRAMID_GENERIC_WHY_3)

df.add_user_transition(State.PYRAMID_ENGINEERING_RAMP_DETAIL, State.PYRAMID_GENERIC_WHY_1, '[$user_1=#ONT(PYRAMID_FEATURE)]')
df.add_user_transition(State.PYRAMID_ENGINEERING_PHYSICS_DETAIL, State.PYRAMID_GENERIC_WHY_1, '[$user_1=#ONT(PYRAMID_FEATURE)]')

df.add_user_transition(State.PYRAMID_ENGINEERING_RAMP_DETAIL, State.PYRAMID_GENERIC_WHY_2, '[$user_1=#POS(noun)]')
예제 #11
0
    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(
    State.UNKNOWN_CELEB, State.CELEB_LOCATION,
    '"Hmm... I do not know them. Where do you think they live?"')

# NER to find locations that are mentioned
df.add_user_transition(State.CELEB_LOCATION, State.ACK, '[$loc=#NER(gpe)]')

df.set_error_successor(State.CELEB_LOCATION, State.UNKNOWN_LOC)

df.add_system_transition(
예제 #12
0
from emora_stdm import DialogueFlow

df = DialogueFlow("root", initial_speaker=DialogueFlow.Speaker.USER)

df.add_user_transition("root", "initiation_state",
                       "[I, {saw, watched} $movie=#MOVIELOOKUP()]")
df.add_system_transition(
    "initiation_state",
    "response_state",
    "I've seen $movie too. {Did you like it?, You liked it, right?}",
)
df.add_user_transition("initiation_state", "like_state",
                       "{#SENT(positive), [yes]}")
df.add_user_transition("initiation_state", "dislike_state",
                       "{#SENT(negative), [no]}")
df.set_error_successor("initiation_state", "error_state")
df.add_system_transition("error_state", "response_state",
                         "Sorry, I didn't catch that. Did you like $movie?")

df.run()
예제 #13
0
        "light": [
            'Acer swift', 'Lenovo ideapad', 'Apple macbook air', 'Dell xps',
            'HP spectre'
        ]
    }
}

knowledge = KnowledgeBase()
knowledge.load_json(ontology)
df = DialogueFlow(State.START,
                  initial_speaker=DialogueFlow.Speaker.SYSTEM,
                  kb=knowledge)

df.add_system_transition(State.START, State.PROMPT,
                         '"Hi, just wondering what laptop are you using?"')
df.set_error_successor(State.PROMPT, State.PROMPT0ERR)
# TODO: create your own dialogue manager
df.add_user_transition(State.PROMPT, State.SCHOOL, "[{$model=#ONT(school)}]")
df.add_user_transition(State.PROMPT, State.APPLE, "[{$model=#ONT(Apple)}]")
df.add_user_transition(State.PROMPT, State.GAME, "[{$model=#ONT(gaming)}]")
df.add_user_transition(State.ERR0, State.Unknown, '$model={/.*/}')

df.add_system_transition(
    State.SCHOOL, State.PROMPT1,
    '"Okay let me guess...you are a sad, depressed and stressed college student that cant wait until spring break?"'
)
df.add_system_transition(
    State.APPLE, State.PROMPT1,
    '"Okay let me guess...you have an iphone, ipad, iwatch, ipod, and i...something right?"'
)
df.add_system_transition(
예제 #14
0
import os
from emora_stdm import DialogueFlow

print(os.getcwd())

df = DialogueFlow("start")
df.add_user_transition("start", "success", "/.*/")
df.set_error_successor("start", "fail")
df.add_system_transition("success", "start", "success")
df.add_system_transition("fail", "start", "fail")

df.knowledge_base().load_json_file("_common.json")

if __name__ == "__main__":
    while True:
        i = input(">> ")
        if "natex " in i[:len("natex ")]:
            df.set_transition_natex("start", "success",
                                    DialogueFlow.Speaker.USER,
                                    i[len("natex "):])
        else:
            df.set_speaker(DialogueFlow.Speaker.USER)
            df.user_turn(i, debugging=True)
            df.set_speaker(DialogueFlow.Speaker.SYSTEM)
            print(df.system_turn(debugging=False))
예제 #15
0
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."')


#USER DOESNT LISTEN TO MUSIC
df.add_system_transition(State.NO, State.NO_ANS, '"That\'s a shame. Why do you not listen to music?"')

df.add_user_transition(State.NO_ANS, State.YES, '[{-not,-dont}, like, music]')
df.set_error_successor(State.NO_ANS, State.MUSIC_GOOD)

df.add_system_transition(State.MUSIC_GOOD, State.MUSIC_OPINION, "Scientists have actually found many benefits to listening "
                                                        "to music. Research shows music makes you happier, "
예제 #16
0
    State.ERR2, State.FREQUENCY,
    r'[!hm, Im confused. Can you use different words please"?"]')

#Turn 2b1 - UNINFORMED
cost_natex = r"[$answer={[cost], [fare], [money], [cheap], [inexpensive], [expensive], [cheaper], [costs], [credit], [wallet], [dollar], [dollars], [spend]}]"
safety_natex = r"[$answer={[safe], [safer], [safely], [danger], [dangerous], [safest], [scared], [trust], [dark], [night]}]"
efficiency_natex = r"[$answer={[easy], [convenient], [efficient], [useful], [handy], [easier], [intuitive]}]"

df.add_system_transition(
    State.UNINFORMED, State.INFOQUESTION,
    '"Two of the most common ridesharing apps are Uber and Lyft. Uber started about 10 years ago and Lyft started about 7 years ago. What other information would you like to know?"'
)
df.add_user_transition(State.INFOQUESTION, State.COST1, cost_natex)
df.add_user_transition(State.INFOQUESTION, State.SAFETY1, safety_natex)
df.add_user_transition(State.INFOQUESTION, State.EFFICIENCY1, efficiency_natex)
df.set_error_successor(State.INFOQUESTION, State.AMBIGUOUS1)

#Turn 2b2 - INFOQUESTION
df.add_system_transition(State.INFOQUESTION1, State.INFOQUESTION,
                         '"What is another question you have?"')

#Turn 3a - NEVER
df.add_system_transition(State.NEVER, State.EXCUSE, '"Why not?"')
df.add_user_transition(State.EXCUSE, State.READY1, "/.*/")

#Turn 3b - INFREQUENT
df.add_system_transition(State.INFREQUENT, State.OCCASION,
                         '"For what occasions do you use it?"')
df.add_user_transition(State.OCCASION, State.READY2, "/.*/")

#Turn 3c - FREQUENT
예제 #17
0
    r'[!"Hi I’m NBA chatbot. I heard that " {#tradeNews()} "this season. Do you want to talk about this trade?"]'
)
df.add_user_transition(State.TURNTRADE1U, State.TURNTRADE2S, '[#ONT(agree)]')
df.add_user_transition(
    State.TURNTRADE1U, State.TURNTRADE1AS,
    '[#ONT(disagree)]')  #goes to talk about a different trade
df.add_system_transition(
    State.TURNTRADE1AS, State.TURNTRADE1U,
    r'[! {[! "How about this:"],I found this other trade article.,[! "What about this trade? I heard that"]} {#tradeNews()}]'
)
df.add_user_transition(State.TURNTRADE1U, State.END,
                       end)  #terminates conversation
#df.add_system_transition(State.TURNTRADE1BS, State.TURNTRADE1BU, r'[! "We can also talk about playoffs or stop talking. Which would you prefer?"]')
#df.add_user_transition(State.TURNTRADE1BU, State.TURNPF1S, playoffs)
#df.add_user_transition(State.TURNTRADE1BU, State.END, '[/[a-z A-Z]+/]')
df.set_error_successor(State.TURNTRADE1U, State.TURNTRADE1ERR)
df.add_system_transition(
    State.TURNTRADE1ERR, State.TURNTRADE2U,
    r'[! "Okay, I mean this trade would be interesting to talk about. " #playerRating() " What do you think about him?"]'
)

#turn 2

df.add_system_transition(
    State.TURNTRADE2S, State.TURNTRADE2U,
    r'[! "Lets talk about " $player ", " #playerRating() " What is your opinon about " $player "?"]'
)
df.add_user_transition(State.TURNTRADE2U, State.TURNTRADE3S1,
                       "[$response2=#POS(adj)]")
df.add_user_transition(
    State.TURNTRADE2U, State.TURNTRADE3S2,
예제 #18
0
df.add_system_transition(State.BAD_DAY, State.MOVIE_PROMPT, natex_bad_day_nq)
df.add_system_transition(State.GOOD_DAY_Q, State.MOVIE_PROMPT,
                         natex_good_day_movie)
df.add_system_transition(State.BAD_DAY_Q, State.MOVIE_PROMPT,
                         natex_bad_day_movie)

# topic transitions
df.add_user_transition(State.TOPIC_PROMPT,
                       State.FOOD_START,
                       '[$response=#ONT(ontculinary)]',
                       rank=2)
df.add_user_transition(State.TOPIC_PROMPT,
                       State.FOOD_START_Q,
                       '<$response=#ONT(ontculinary) {what, how, have, you}>',
                       rank=1)
df.set_error_successor(State.TOPIC_PROMPT, State.MOVIE_START)

# movie conversation
df.add_system_transition(State.MOVIE_START, State.MOVIE_PROMPT,
                         '"so, have you seen any good movies lately?"')
df.add_user_transition(State.MOVIE_PROMPT,
                       State.MOVIE_N,
                       '[$response=#ONT(ontno)]',
                       rank=2)
df.add_user_transition(State.MOVIE_PROMPT,
                       State.MOVIE_N_Q,
                       '<$response=#ONT(ontno) {how, is, are, you, your}>',
                       rank=1)
df.add_user_transition(State.MOVIE_PROMPT,
                       State.MOVIE_Y,
                       '[$response=#ONT(ontyes)]',
)

df.add_user_transition(State.t21, State.t22, '/.*/')

df.add_system_transition(State.t22, State.t23,
                         '[! "It\'s been so nice talking to you! Goodbye!"]')

df.add_user_transition(State.t23, State.t24, '/.*/')

# get back to the start
df.add_system_transition(
    State.t24, State.turn_1,
    '[! "Aw! Sweet of you to stick around! Let\'s go back to phones. What phone do you have?"]'
)

df.set_error_successor(State.turn_1, State.START)
df.set_error_successor(State.turn_2a, State.iphone)
df.set_error_successor(State.turn_2b, State.samsung)
df.set_error_successor(State.turn_2c, State.android)
df.set_error_successor(State.new, State.turn_5)
df.set_error_successor(State.phone_ft, State.turn_6y)
df.set_error_successor(State.laptop, State.turn_6n)
df.set_error_successor(State.t1a, State.included)
df.set_error_successor(State.t1b, State.notincluded)
df.set_error_successor(State.t3, State.t2e)
df.set_error_successor(State.t9, State.t13)
df.set_error_successor(State.t16, State.t14)

# TODO: create your own dialogue manager

df.run(debugging=False)
예제 #20
0
df.add_system_transition(
    State.Learn_Response, State.Cloud_Provider_OV, r'[! "So heres a fun fact.'
    r' Amazon is the major player of the cloud market and they control'
    r' about 47 percent. Microsoft has about 15'
    r' percent and Google has 7 percent."]')
df.add_system_transition(
    State.Projects_Yes, State.Ask_For_Improvement,
    r'["Thats impressive. Understanding what things do and actually implementing them is completely different task'
    'It was nice talking with you. My intention was to educate users if they have no experience in cloud'
    'Maybe if you could leave some comments, I could try to better myself to have deeper conversation"]'
)
#df.add_user_transition(State.Ask_For_Improvement, State.Give_Improvement, "$improvement=/[A-Z a-z]*/")
#df.add_system_transition(State.Give_Improvement, State.Goodbye, r'[! "Thank you so much! I really appreciate your comment. This is goodbye for now, '
#r'but dont forget to check back for more updates on my knowledge about cloud!"]') # end of conversation

df.set_error_successor(State.Knowledge, State.ERR)
df.add_system_transition(
    State.ERR, State.Knowledge,
    r'[!"Sorry, couldnt understand. please give yes or no"]')
df.set_error_successor(State.Ask_About_Apps, State.ERR1)
df.add_system_transition(
    State.ERR1, State.Ask_About_Apps,
    r'[! "Sorry I couldnt understand. Also even if you dont have an app, let me know about an app that you do have"]'
)
df.set_error_successor(State.Ask_About_Cloud_Providers, State.ERR2)
df.add_system_transition(
    State.ERR2, State.Ask_About_Cloud_Providers,
    r'[! "Sorry I didnt quite get that. Do you know any cloud providers"]')
df.set_error_successor(State.Ask_Which, State.ERR3)
df.add_system_transition(
    State.ERR3, State.Ask_Which,
예제 #21
0
# Turn 1
# Natex
poet_name = r"[$fave_poet=#ONT(poets)]"
favorite = r"[$fave_poet={[Ezra Pound], [ezra pound], [pound], [Pound]}]"
none = r"[#ONT(ambiguous)]"

df.add_system_transition(
    State.START, State.INTRO,
    '"Hi, I\'m a chatbot and I\'m designed to talk about poetry '
    'with humans. \n'
    'Enough about me now though, tell me, who is your '
    'favorite poet?"')
df.add_user_transition(State.INTRO, State.POUND, favorite)
df.add_user_transition(State.INTRO, State.REC_POET, poet_name)
df.add_user_transition(State.INTRO, State.NONE, none)
df.set_error_successor(State.INTRO, State.UNREC_POET)

# Turn 2
# Natex
alienation = r"[$theme=#ONT(alienation)]"
love = r"[$theme=#ONT(love)]"
death = r"[$theme=#ONT(death)]"
time = r"[$theme=#ONT(time)]"
nature = r"[$theme=#ONT(nature)]"
happy = r"[$theme=#ONT(happy)]"
unknown = r"[#ONT(ambiguous)]"
more = r"[#ONT(more-themes)]"
identity = r"[#ONT(identity)]"

df.add_system_transition(
    State.POUND, State.THEME,
예제 #22
0
    State.PROMPT, State.SYSRESYES,
    '<{yes, yea, yup, yep, i do, yeah, sometimes, sure}, {what, whats, you, your}>'
)
df.add_system_transition(
    State.SYSRESYES, State.VERSION,
    '"I use Spotify too! do you use the free version or do you use premium?"')
df.add_user_transition(
    State.PROMPT, State.SYSRESNO,
    '<{no, nah, nope, never, not}, {what, whats, you, your}>')
df.add_system_transition(
    State.SYSRESNO, State.WHATEV,
    '"I use Spotify to stream music. What other music streaming services do you use?"'
)
df.add_system_transition(State.ERR1, State.PROMPT,
                         '"i dont understand. do you use spotify?"')
df.set_error_successor(State.PROMPT, State.ERR1)

# free or paid?
df.add_system_transition(
    State.SPOTIFY, State.VERSION,
    '"thats awesome! do you use the free version or do you use premium?"')
df.add_user_transition(State.VERSION, State.FREESPOT, '[{free, trial}]')
df.add_user_transition(State.VERSION, State.SYSVERSIONF,
                       '<{free, trial}, {what, whats, you, your}>')

df.add_user_transition(State.VERSION, State.PAID, '[{premium, paid, pay}]')
df.add_user_transition(State.VERSION, State.SYSVERSIONP,
                       '<{premium, paid, pay}, {what, whats, you, your}>')

df.add_system_transition(
    State.SYSVERSIONF, State.REASONFREE,
예제 #23
0
                         '"Do you play video games?" $empty=""')
df.add_user_transition(State.gU0, State.gS1d,
                       '[$word=#ONT(dislike), $dislike=/.*/]')
df.add_user_transition(State.gU0, State.gS1a, '[#ONT(positive)]', score=2.0)
df.add_user_transition(State.gU0,
                       State.gS1b,
                       '{[#ONT(negative), -#ONT(positive)], dontknow}',
                       score=3.0)
df.add_user_transition(State.gU0, State.gS1c,
                       '[[$word=#ONT(like), $like=/.*/], -#ONT(positive)]')
df.add_user_transition(State.gU0, State.fS1b, general, score=3.0)
df.add_user_transition(State.gU0,
                       State.fS1d,
                       '[{$specG=#ONT(specificGame)}]',
                       score=3.0)
df.set_error_successor(State.gU0, State.mS0)

### Negative Response
df.add_system_transition(
    State.gS1b, State.gU1aa,
    '"video games are great, and there are games for everyone. in general would you prefer a game you can play by yourself, or with others?"'
)
df.add_system_transition(State.gS1c, State.gU1ac,
                         '"why do you" $word #like_macro')
df.add_system_transition(State.gS1d, State.gU1ad,
                         '"why do you" $word #dislike_macro')
df.add_user_transition(State.gU1ac, State.fS1d,
                       '[{$specG=#ONT(specificGame)}]')
df.add_user_transition(State.gU1ac, State.gS2d,
                       '[-{$specG=#ONT(specificGame)} $explain=/.*/]'
                       )  # continues from why do you like
예제 #24
0
파일: rock.py 프로젝트: simonmarty/emory
sp_requester = requester()
ontology = json.loads(open('ontology.json').read())



knowledge = KnowledgeBase()
knowledge.load_json(ontology)


df = DialogueFlow(State.START, initial_speaker=DialogueFlow.Speaker.SYSTEM, kb=knowledge)

df.add_system_transition(State.START, State.GENREQUESTION, '"What\'s your favorite music genre?"')

df.add_user_transition(State.GENREQUESTION, State.ROCK, '[{rock, Rock}]')
df.set_error_successor(State.GENREQUESTION, State.ROCK_ERROR)
# Error
df.add_system_transition(State.ROCK_ERROR, State.GENREQUESTION2, '"Sorry, I didn\'t catch that. What\'s your favorite music genre?"')
df.add_user_transition(State.GENREQUESTION2, State.ROCK, '[{rock, Rock}]')
df.set_error_successor(State.GENREQUESTION2, State.ROCK_ERROR2)
df.add_system_transition(State.ROCK_ERROR2, State.ERR, '"Sorry, I still didn\'t catch that. Let\'s start over."')

# Turn 1
df.add_system_transition(State.ROCK, State.ROCKDYING, '"So you like rock music?! I don\'t know about that."'
                                                      '"I heard the genre is dying out; wouldn\'t you agree?"')
df.add_user_transition(State.ROCKDYING, State.ROCKAGREE, '[#ONT(yes)]')
df.add_user_transition(State.ROCKDYING, State.ROCKDISAGREE, '[#ONT(no)]')
# Error
df.set_error_successor(State.ROCKDYING, State.ROCK_ERROR3)
df.add_system_transition(State.ROCK_ERROR3, State.ROCKDYING2, '"Sorry, I didn\'t catch that. Don\'t you agree?"')
df.add_user_transition(State.ROCKDYING2, State.ROCKAGREE, '[#ONT(yes)]')
예제 #25
0
class DFEasyFilling:
    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 get_dialogflow(self):
        df_backup = copy.deepcopy(self.df)
        self._compile_dialogflow()
        result_df = self.df
        self.df = df_backup
        return result_df

    def add_global_user_transition(self, state_to, intent, importance=1.0):
        if not utils.check_intent(intent):
            raise Exception("Unknown intent type")
        elif state_to in self.global_user_transitions:
            raise Exception(f"{state_to} is already defined")
        else:
            self._add_states(state_to)
            self.global_user_transitions[state_to] = {
                "intent": intent,
                "importance": importance
            }

    def add_user_transition(self,
                            state_from,
                            state_to,
                            intent,
                            importance=1.0):
        if not utils.check_intent(intent):
            raise Exception("Unknown intent type")
        elif state_to in self.local_user_transitions[state_from]:
            raise Exception(f"{state_to} is already defined")
        else:
            self._add_states(state_from, state_to)
            self.local_user_transitions[state_from][state_to] = {
                "intent": intent,
                "importance": importance
            }

    def add_system_transition(self, state_from, state_to, nlg):
        self._add_states(state_from, state_to)
        if isinstance(nlg, (str, NatexNLG)):
            self.df.add_system_transition(state_from, state_to, nlg)

        elif isinstance(nlg, (set, list)):
            nlg = utils.strs2natex_nlg(nlg)
            self.df.add_system_transition(state_from, state_to, nlg)

        elif callable(nlg):  # nlg(vars=vars) -> str

            class NLGMacro(Macro):
                def run(self, ngrams, vars, args):
                    try:
                        text = nlg(vars=vars)
                        text = utils.clean_text(text)
                        return text
                    except Exception as exc:
                        sentry_sdk.capture_exception(exc)
                        logger.exception(exc)
                        return ""

            macros_name = uuid.uuid4().hex

            self.df.add_system_transition(
                state_from,
                state_to,
                NatexNLG(
                    f"#{macros_name}()",
                    macros={f"{macros_name}": NLGMacro()},
                ),
            )

        else:
            raise Exception("Unknown nlg type")

    def set_error_successor(self, state_from, state_to):
        # self._add_states(state_from, state_to)
        # self.df.set_error_successor(state_from, state_to)
        self.error_transitions[state_from] = state_to
        pass

    def add_user_serial_transitions(self,
                                    state_from,
                                    states_to,
                                    default_importance=1.0):
        # order in states_to is important
        for state_to, condition in states_to.items():
            intent, importance = ((condition[0], condition[1]) if isinstance(
                condition, (list, tuple)) else (condition, default_importance))
            self.add_user_transition(
                state_from,
                state_to,
                intent,
                importance,
            )

    def add_global_user_serial_transitions(self,
                                           states_to,
                                           default_importance=1.0):
        # order in states_to is important
        for state_to, condition in states_to.items():
            intent, importance = ((condition[0], condition[1]) if isinstance(
                condition, (list, tuple)) else (condition, default_importance))
            self.add_global_user_transition(
                state_to,
                intent,
                importance,
            )

    def _add_user_transitions(self, state_from, states_to):
        # order in states_to is important
        condition_sequence = []
        for state_to, condition in states_to.items():
            condition_sequence += [condition]
            self._add_user_transition(
                state_from,
                state_to,
                utils.create_intent_sequence(condition_sequence[:-1],
                                             condition_sequence[-1:]),
            )

    def _add_user_transition(self, state_from, state_to, intent):
        if isinstance(intent, (str, NatexNLU)):
            self.df.add_user_transition(state_from, state_to, intent)

        elif isinstance(intent, (set, list)):
            intent = utils.disjunction_natex_nlu_strs(intent)
            self.df.add_user_transition(state_from, state_to, intent)

        elif callable(intent):
            if isinstance(intent,
                          MindfulDataFileBot):  # using programy as intent

                def handler(ngrams, vars):
                    # TODO: n turns
                    return intent([ngrams.text()])

            else:
                handler = intent  # intent(ngrams=ngrams, vars=vars) -> bool

            class IntentMacro(Macro):
                def run(self, ngrams, vars, args):
                    try:
                        is_match = handler(ngrams=ngrams, vars=vars)
                    except Exception as exc:
                        sentry_sdk.capture_exception(exc)
                        logger.exception(exc)
                        is_match = False
                    if is_match:
                        return ngrams.text()
                    else:
                        return ""

            macros_name = uuid.uuid4().hex
            self.df.add_user_transition(
                state_from,
                state_to,
                NatexNLU(
                    f"#{macros_name}()",
                    macros={f"{macros_name}": IntentMacro()},
                ),
            )

        else:
            raise Exception("Unknown intent type")

    def _compile_dialogflow(self):
        transitions = {
            state_from: copy.deepcopy(self.global_user_transitions)
            for state_from in self._get_usr_states()
        }
        logger.debug(f"transitions={transitions}")
        logger.debug(f"self.states={self.states}")
        logger.debug(
            f"self.local_user_transitions={self.local_user_transitions}")
        logger.debug(f"self._get_usr_states()={self._get_usr_states()}")

        for state_from in transitions:
            user_transition_from = transitions[state_from]
            user_transition_from.update(
                self.local_user_transitions.get(state_from, {}))
            ordered_states_to = sorted(
                user_transition_from,
                key=lambda state_to: -user_transition_from[state_to].get(
                    "importance", 1.0),
            )
            state_to2intent = {
                state_to: user_transition_from[state_to]["intent"]
                for state_to in ordered_states_to
            }
            self._add_user_transitions(state_from, state_to2intent)

        for state_from, state_to in self.error_transitions.items():
            self.df.set_error_successor(state_from, state_to)

    def _add_states(self, *args):
        for state in args:
            text_state = str(state[1]) if isinstance(state,
                                                     (tuple,
                                                      list)) else str(state)
            text_prefix = "State."
            prefix_len = len(text_prefix)
            if not (text_prefix == text_state[:prefix_len]):
                raise Exception(f"state {state} has to be from State class")
            if not (text_state[prefix_len:prefix_len + 3] in [
                    "SYS",
                    "USR",
            ]):
                raise Exception(
                    f"state {state} has to contain SYS or USR in of the begining"
                )
            self.states.add(state)

    def _get_usr_states(self):
        text_prefix = "State.USR"
        prefix_len = len(text_prefix)
        sys_states = []
        for state in self.states:
            text_state = str(state[1]) if isinstance(state,
                                                     (tuple,
                                                      list)) else str(state)
            if text_state[:prefix_len] == text_prefix:
                sys_states.append(state)
        return sys_states
예제 #26
0
                    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"?"]')
df.add_system_transition(State.S2d, State.U3a, '[!$comp is a great consulting firm"." What position in $comp are you interested in"?"]')
df.add_system_transition(State.S2e, State.U3a, '[!$comp is a great technology company"." What position in $comp are you interested in"?"]')
df.add_system_transition(State.S2f, State.U3a, '[!$comp is a great company to work for"." What position in $comp are you interested in"?"]')
df.add_system_transition(State.ERR1, State.U2a, '"I am not familiar with that place. What industry do you want to work in?"')

df.add_user_transition(State.U2a, State.S3a, '[$industry={consulting,finance,tech,technology,it}]')
df.set_error_successor(State.U2a, error_successor=State.ERR2)
df.add_system_transition(State.S3a, State.U1, '[!$industry is a very promising industry to work in"." I know #indComp are famous in the $industry industry"." What company in $industry do you want to work for"?"]')
df.add_system_transition(State.ERR2, State.U3a, '"Umm...I am not very familiar with this industry. What kind of position would you like to work at?"')
예제 #27
0
df.add_user_transition(State.PROMPT, State.REPTILE,
                       "[$animal={snake,lizard,turtle,alligator}]")
df.add_user_transition(State.PROMPT, State.AMPHIBIAN,
                       "[$animal=#ONT(amphibian)]")
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"]')
df.add_system_transition(State.REPTILE, State.PROMPT,
                         '[! $animal "is a reptile, enter another animal"]')
df.add_system_transition(
    State.AMPHIBIAN, State.PROMPT,
    '[! $animal "is an amphibian, enter another animal"]')
df.add_system_transition(State.ERR, State.PROMPT,
                         '"i dont know that one, enter another animal"')
df.set_error_successor(State.PROMPT, State.ERR)

################################
# Add Quiz2 Task 1 below
################################

################################
# Add Quiz2 Task 2 below
################################

################################
# Add Quiz2 Task 3 below
# (except do not move ont_dict from line 11)
################################

df.run(debugging=False)
예제 #28
0
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"')

# df.add_system_transition(State.LIKE_GAME_Y, State.GAME_TYPE, '[!oh #MyMacro(there) how are you]')
df.add_system_transition(
    State.LIKE_GAME_Y, State.GAME_TYPE,
    '"cool beans. are you into strategy games? i love strategy games."')
df.add_system_transition(
    State.LIKE_GAME_N, State.SMART_PERSON,
    '"thats crazy! you should try playing some. maybe i can recommend some. are you a smart person?"'
)

# df.add_user_transition(State.GAME_TYPE, State.GAME_TYPE_REPLY, "<$response={/(?:^|\s)(yea|ye|ya|yes|yeah|i do|i like)(?:\s|,|\.|$)/, #ONT(game_type)}>")
# df.add_user_transition(State.GAME_TYPE, State.GAME_TYPE_REPLY_N, "<$response={/(?:^|\s)(no|not|nah|i dont like|i nope|i dislike)(?:\s|,|\.|$)/, #ONT(game_type)}>")
예제 #29
0
df.add_system_transition(
    State.HOME_OTHER, State.ALSO_LAP_Q,
    '[!"It is strange to bring a desktop to"$location"... Do you also have a laptop?"]'
)

df.add_system_transition(
    State.TYPE_LAP, State.LAP_Q,
    '"I guess you use a laptop more than at home, right? Do you use it at school or at work?"'
)
df.add_user_transition(State.LAP_Q, State.END_1_WORK_SCHOOL,
                       '[$location=#ONT(non_home_locations)]')
df.add_user_transition(State.LAP_Q, State.END_1_HOME_LAP,
                       '[/(only)?(just)?(.{2})?home/]')

# errors
df.set_error_successor(State.COM_Q, State.COM_Q_ERR)
df.set_error_successor(State.TYPE_Q, State.TYPE_ERROR)
df.set_error_successor(State.DESK_Q, State.DESK_Q_ERR)
df.set_error_successor(State.LAP_Q, State.LOCATION_UNKNOWN)
df.set_error_successor(State.ALSO_LAP_Q, State.LAP_Q_ERROR)

df.add_system_transition(
    State.LAP_Q_ERROR, State.ALSO_LAP_Q,
    '"I did not understand that...\nS: Do you also have a laptop?"')
df.add_system_transition(
    State.TYPE_ERROR, State.TYPE_Q,
    '"I did not understand that...\nS: Do you have a desktop or a laptop?"')

df.add_system_transition(State.COM_Q_ERR, State.COM_Q,
                         '"Let us try this again...do you have a computer?"')
df.add_system_transition(
예제 #30
0
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()})


### Main Prompt - Do you play video games?
df.add_system_transition(State.S0, State.gU0, '"Do you play video games?"')
df.add_user_transition(State.gU0, State.gS1a, '[#ONT(negative)]')
df.add_user_transition(State.gU0, State.gS1b, '[#ONT(positive)]')
df.add_user_transition(State.gU0, State.gS1d, '[$word=#ONT(dislike), $dislike=/.*/]')
df.add_user_transition(State.gU0, State.gS1c, '[$word=#ONT(like), $like=/.*/]')
df.set_error_successor(State.gU0, State.gS1f)


### Negative Response
df.add_system_transition(State.gS1a, State.gU1aa, '"video games are great, and there are games for everyone. in general would you prefer a game you can play by yourself, or with others?"')
df.add_system_transition(State.gS1c, State.gU1ac, '"why do you " $word #like_macro')
df.add_system_transition(State.gS1d, State.gU1ad, '"why do you " $word #dislike_macro')
df.add_user_transition(State.gU1ac, State.gS2c, '/.*/') # continues from why do you like
df.add_user_transition(State.gU1ad, State.gS2c, '/.*/') # continues from why do you dislike
df.add_system_transition(State.gS1f, State.gU2d, '"sorry im only interested in video games."')
df.add_user_transition(State.gU2d, State.gS1a, '/.*/')

#TODO: expand accepted phrases
df.add_user_transition(State.gU1aa, State.gS2a,"[$response=#ONT(alone)]") # alone
df.add_user_transition(State.gU1aa, State.gS2b, "[$response=#ONT(team)]") # with others
df.set_error_successor(State.gU1aa, State.gS2c)