Ejemplo n.º 1
0
def what_word(turn: DialogTurn):
    word = turn.user_object.get('word')
    if word:
        turn.response_text = f'Вы говорили о слове {word}'
        turn.next_stage = 'word'
    else:
        turn.response_text = 'Вы ещё не искали синонимы'
Ejemplo n.º 2
0
def repeat(turn: DialogTurn):
    prev = turn.user_object.get('prev')
    if not prev:
        turn.response_text = 'Не поняла, что повторять'
    else:
        turn.response_text = f"<text>{prev['text']}</text><voice>{prev['voice']}</voice>"
        turn.suggests = prev['suggests']
        turn.next_stage = prev['stage']
Ejemplo n.º 3
0
def make_synonym_response(turn: DialogTurn, word=None):
    if not word:
        word = turn.text
    if not word:
        return
    syns = find_synonyms(word)
    all_synonyms = sorted({
        text
        for ss in syns for text in ss
        if word.upper() not in text.upper().split()
    })
    if not all_synonyms:
        turn.response_text = f'Простите, не нашла синонимов к слову "{word}".'
        return
    turn.response_text = f'Синонимы к слову "{word}":'
    for syn in all_synonyms[:-1]:
        turn.response_text += '\n' + syn + ';'
    turn.response_text += '\n' + all_synonyms[-1] + '.'

    turn.user_object['word'] = word
Ejemplo n.º 4
0
def hello(turn: DialogTurn):
    turn.response_text = 'Hello! This is the only conditional phrase I have.'
Ejemplo n.º 5
0
def fallback(turn: DialogTurn):
    turn.response_text = 'Hi! Sorry, I do not understand you.'
    turn.suggests.append('hello')
Ejemplo n.º 6
0
 def fallback(turn: DialogTurn):
     turn.response_text = 'hi'
Ejemplo n.º 7
0
 def fallback(turn: DialogTurn):
     turn.response_text = 'shalom my friend'
Ejemplo n.º 8
0
def t3(turn: DialogTurn):
    turn.response_text = '2'
Ejemplo n.º 9
0
def do_help(turn: DialogTurn):
    turn.response_text = 'Привет! Вы в навыке "Синоним к слову". ' \
                         'Скажите любое слово, а я найду синонимы к нему.' \
                         '\nЧтобы выйти, скажите "хватит".'
    turn.suggests.append('выход')
Ejemplo n.º 10
0
def hello(turn: DialogTurn):
    turn.response_text = 'Привет! Вы в навыке "Синоним к слову". ' \
                         'Скажите любое слово, а я найду синонимы к нему.'
    turn.suggests.append('выход')
Ejemplo n.º 11
0
def t0(turn: DialogTurn):
    turn.response_text = '0'
Ejemplo n.º 12
0
def test_postprocess():
    turn = DialogTurn(make_context(text='kek'), text='kek')
    turn.response_text = 'The weather is cool.'
    # without agenda, no postprocessors are called
    turn.release_control()
    csc.postprocess(turn)
    assert turn.response_text.endswith('cool.')
    # without control, no postprocessors are called
    turn.take_control()
    turn.add_agenda('ask_for_tea')
    csc.postprocess(turn)
    assert turn.response_text.endswith('cool.')
    # with control and agenda, postprocessors are called
    turn.release_control()
    csc.postprocess(turn)
    assert turn.response_text.endswith('tea?')
    # after postprocessing, agenda goes away
    assert not turn.agenda
Ejemplo n.º 13
0
def test_ranking_stage():
    ctx = Context(message_text='kek', user_object={'stage': 's1'}, metadata=None)
    turn = DialogTurn(ctx, text='kek', intents={'i3': 1})
    assert turn.old_user_object == {'stage': 's1'}
    assert turn.stage == 's1'
    assert csc(turn) == 't4'
Ejemplo n.º 14
0
def test_ranking(intents, result):
    turn = DialogTurn(make_context(text='kek'), text='kek', intents=intents)
    assert csc(turn) == result
Ejemplo n.º 15
0
def t4(turn: DialogTurn):
    turn.response_text = 'stage 1'
Ejemplo n.º 16
0
def total_exit(turn: DialogTurn):
    turn.response_text = 'Было приятно пообщаться! ' \
                         'Чтобы обратиться ко мне снова, ' \
                         'запустите навык "Синоним к слову".'
    turn.commands.append(COMMANDS.EXIT)
Ejemplo n.º 17
0
def try_forms(turn: DialogTurn):
    for dm in form_dms:
        form_response = dm.try_to_respond(turn.ctx)
        if form_response:
            turn.response = form_response
            return
Ejemplo n.º 18
0
def t1(turn: DialogTurn):
    turn.response_text = '1'