Exemplo n.º 1
0
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)
                },
                '[bad]': {
                    'sorry to hear that':{
                        'error': 'root'
                    }
                }
            }
        },
        '[how, you]': {
            'good': {
                'error': 'root'
            }
        }
    }
}
df.load_transitions(flow, DialogueFlow.Speaker.SYSTEM)

df.state_settings('root').update(system_multi_hop=True)
df.add_state('recovery_question', global_nlu='[!{do, who, what, when, where, why, how, is, can, should}, /.*/]')
df.add_system_transition('recovery_question', 'root', '"Hmm.. I\'m not sure."')

df.add_user_transition('x', 'y', '#ANY($myvar=something, $other=somethingelse) [hello]')

while True:
    df.system_turn()
    v = input()
    var, val = v.split('=')
    df.vars().update({var: val})
    df.user_turn(input())

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)
Exemplo n.º 4
0
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!`": {}
                }
            },
        },
    }
})
Exemplo n.º 5
0
            '"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'
                },
                '{[bad, horrible, awful]}': {
                    '"Oh no! Bye!"': 'end'
                },
                'error': {
                    '"I do not understand! Bye!"': 'end'
                }
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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!`': {}
                }
            }
        }
    }
})
Exemplo n.º 8
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()
Exemplo n.º 9
0
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()
Exemplo n.º 10
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()
Exemplo n.º 11
0
from emora_stdm import DialogueFlow

system = DialogueFlow('start', initial_speaker=DialogueFlow.Speaker.USER)
system.load_transitions({'state': 'start'})

system.load_update_rules({
    '[my, {husband, wife, kids}]': '#SET($is_adult=True)',
    '{[i, work]}': '#SET($is_adult=True)',
    '#IF($is_adult=True)': '`How is you job going?` (2.0)',
    '/.*/ (0.1)': '`I\'m not sure I understand.` (1)',
})

if __name__ == '__main__':
    system.run()
Exemplo n.º 12
0
from emora_stdm import DialogueFlow


system = DialogueFlow("start", initial_speaker=DialogueFlow.Speaker.USER)
system.load_transitions({"state": "start"})

system.load_update_rules(
    {
        "[my, {husband, wife, kids}]": "#SET($is_adult=True)",
        "{[i, work]}": "#SET($is_adult=True)",
        "#IF($is_adult=True)": "`How is you job going?` (2.0)",
        "/.*/ (0.1)": "`I'm not sure I understand.` (1)",
    }
)

if __name__ == "__main__":
    system.run()