コード例 #1
0
 def __init__(self, *json_files):
     DialogueFlow.__init__(self,
                           'sr',
                           initial_speaker=DialogueFlow.Speaker.SYSTEM)
     self.add_state('sr', system_multi_hop=True)
     #self.add_state('shortcut', system_multi_hop=True)
     self.add_state('ur', 'ur_error', user_multi_hop=True)
     self.add_state('ur_error', 'ur_error_statement', user_multi_hop=True)
     self.add_user_transition('ur_error', 'ur_error_question',
                              natexes.question)
     self.add_state('ur_error_statement')
     self.add_system_transition(
         'ur_error_statement',
         'sr',
         '{"Yeah." "For sure." "Yep." "Right." "Sure." "Gotcha."}',
         score=1.0)
     #self.add_system_transition('ur_error_statement', 'shortcut', '#TOKLIMIT(2)', score=2.0)
     #self.add_system_transition('shortcut', 'sr', '""')
     self.add_system_transition(
         'ur_error_question', 'sr',
         '{"I\'m not sure about that." "That\'s a tough one." "I\'m not sure actually." "Huh, I don\'t know."}'
     )
     self.add_state('dinit', system_multi_hop=True)
     self.add_system_transition('dinit', 'sr', '')
     for json_file in json_files:
         DialogueFlow.knowledge_base(self).load_json_file(json_file)
コード例 #2
0
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()
コード例 #3
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))
コード例 #4
0
import os
print(os.getcwd())

from emora_stdm import DialogueFlow

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))