Ejemplo n.º 1
0
 def main_func(text):
     proto = Unmo('manachan')
     try:
         response = proto.dialogue(text, 1)
     except IndexError as error:
         return '{}: {}'.format(type(error).__name__, str(error)),
         '警告: 辞書が空です。(Responder: {})'.format(proto.responder_name)
     else:
         return '{response}'.format(response=response)
Ejemplo n.º 2
0
    def message(line_event):
        proto = Unmo('proto')
        text = line_event.message.text

        input_text = text.rstrip()
        response = proto.dialogue(input_text)

        line_bot_api.reply_message(line_event.reply_token,
                                   TextSendMessage(text=response))
Ejemplo n.º 3
0
def handle_message(event):
    #if event.reply_token == "00000000000000000000000000000000":
    #return
    if __name__ == '__main__':
        Lala = Unmo('Lala')
    #while True:
    #text = TextMessage
    response = Lala.dialogue(text=event.message.text)
    line_bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text=response))  #ここでオウム返しのメッセージを返します。
    gc.collect()
    Lala.save()
Ejemplo n.º 4
0
def handle_message(message):
    print('received message: ' + message, file=sys.stderr)
    send(message, broadcast=True)

    proto = Unmo('proto')

    try:
        response = proto.dialogue(message)
    except IndexError as error:
        print('{}: {}'.format(type(error).__name__, str(error)))
        print('Error: Dictionary is empty. (Responder: {})'.format(proto.responder_name))
    else:
        print('{prompt}{response}'.format(prompt=build_prompt(proto), response=response))

    print('response message: ' + response, file=sys.stderr)
    prompt_response = '{prompt}{response}'.format(prompt=build_prompt(proto), response=response)
    send(prompt_response, broadcast=True)

    proto.save()
Ejemplo n.º 5
0
# Python初心者に送る「人工知能の作り方」
# http://sandmark.hateblo.jp/entry/2017/10/07/141339
# に掲載されたコードを写経して勉強する。

from unmo import Unmo

def build_prompt(unmo):
    """
    AIインスタンスを取り、AIとResponderの名前を整形して返す
    """
    return '{name}:{responder}> '.format(name=unmo.name,
                                responder=unmo.responder_name)

if __name__=='__main__':
    print('Unmo System prototype : proto')
    proto= Unmo('proto')
    while True:
        text = input('> ')
        if not text:
            break

        response = proto.dialogue(text)
        print('{prompt}{response}'.format(prompt=build_prompt(proto),
                                         response=response))
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-

import os, sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from unmo import Unmo


def prompt(unmo):
    return f"{unmo.name}:{unmo.responder.name} > "


print('Unmo System prototype : proto')
proto = Unmo('proto')

while True:
    print('> ', end='')
    input_text = input()
    input_text = input_text.rstrip()
    if input_text == '':
        break
    response = proto.dialogue(input_text)
    print(prompt(proto) + response)

print('shutdown')
Ejemplo n.º 7
0
                print('markov training is done!')
            else:
                text = markov_tr_list[0]
                print('traiing :', text)

        if markov_training != 1:
            text = input('> ')

        if text == 'train markov':
            print('ファイル名を教えて下さい')
            path = input('path = ')
            markov_training = 1
            #pathからtxtfileを一行ずつmarkov_tr_listに格納するコード

            markov_tr_list = ['わたしはケーキが食べたいです', '機械学習を勉強しています', '朝は何を食べましたか']
            text = markov_tr_list[0]
            print('traiing :', text)

        if not text:
            break

        try:
            response = proto.dialogue(text, markov_training)
        except IndexError as error:
            print('{}: {}'.format(type(error).__name__, str(error)))
            print('警告: 辞書が空です。(Responder: {})'.format(proto.responder_name))
        else:
            print('{prompt}{response}'.format(prompt=build_prompt(proto),
                                              response=response))
    proto.save()