Exemplo n.º 1
0
def hello_world():
    if request.method == 'POST':
        data = json.loads(request.get_data().decode('utf-8'))
        print("get POST request data: ", data)

        question = data["question"]

        chatter = Chatbot.Chatbot(w2v_model_path='model/word2vec.model')

        ans = {'answer': chatter.waiting_loop(question)}

        return ans

    elif request.method == 'GET':
        return 'GET OK!'
Exemplo n.º 2
0
import Chatbot.chatbot as Chatbot

chatter = Chatbot.Chatbot()
chatter.waiting_loop()
Exemplo n.º 3
0
def question_data(request):
    global output
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        new_article = form.save()
        if form.is_valid():
            if new_article.frontId == '':
                while (1):
                    myid = random.randint(0, 99)
                    post = Post.objects.filter(iden=myid)
                    if len(post) == 0:
                        break
                    #print(output[1])
                output = chatb.listen(new_article.content)
                if output[1] is not None:
                    Post.objects.create(iden=myid,
                                        content=output[1],
                                        domain=chatb.root_domain)
                    return HttpResponse(
                        json.dumps({
                            'ID': str(myid),
                            'reply': output[0]
                        }))
                    #return render(request, 'get.html', {'form': form,'data': str(myid)+"#"+output[0]})
                #print(str(myid)+'#'+output[0])
                else:
                    return HttpResponse(json.dumps({'reply': output[0]}))
                    #return render(request, 'get.html', {'form': form,'data': output[0]})
            else:
                post = Post.objects.filter(iden=new_article.frontId)
                if len(post) == 0:
                    print('your Id have ERROR!!')
                    return HttpResponse(
                        json.dumps({'reply': 'your Id have ERROR!!'}))
                    #return render(request, 'get.html', {'form': form,'data': 'your Id have ERROR!!'})
                else:
                    data = Post.objects.get(iden=new_article.frontId).content
                    chatb.root_domain = Post.objects.get(
                        iden=new_article.frontId).domain
                    output = chatb.listen(new_article.content)
                    temp = list(output[1])
                    for i in range(0, len(temp), 1):
                        if temp[i] != data[i]:
                            if temp[i] == 't' and data[i] == 'n':
                                data[i] = temp[i]
                            if temp[i] == 'r' and data[i] == 'u':
                                data[i] = temp[i]
                            if temp[i] == 'u' and data[i] == 'l':
                                data[i] = temp[i]
                            if temp[i] == 'e' and data[i] == 'l':
                                data[i] = temp[i]
                    print("".join(data))
                    print(len(temp))
                    if output[1] is not None:
                        Post.objects.filter(iden=new_article.frontId).update(
                            content="".join(data))
                        return HttpResponse(
                            json.dumps({
                                'ID': new_article.frontId,
                                'reply': output[0]
                            }))
                        #return render(request, 'get.html', {'form': form,'data': new_article.frontId+'#'+output[0]})
                    else:
                        Post.objects.get(iden=new_article.frontId).delete()
                        return HttpResponse(
                            json.dumps({
                                'ID': new_article.frontId,
                                'reply': output[0]
                            }))
                        #return render(request, 'get.html', {'form': form,'data': output[0]})
                    #print(Post.objects.get(iden=new_article.frontId).content.split('#'))

        #	process.stdin.write(str.encode(new_article.content))
        #	stdo = process.communicate(input=(new_article.content).encode())[0]
        #	print(process.stdout.readline())
        #	process.stdout.close()
    global chatb
    form = ArticleForm()
    chatb = chatbot.Chatbot()

    #process = Popen('python C:/Users/aa/proj_DB/mysite/Chatbot-master/chatbot.py', stdin=PIPE)
    #for line in iter(process.stdout.readline,''):
    #	print("test:", line.rstrip())
    #	if line.rstrip() == b'[Console] Initialized successfully :>':
    #		print("I am break")
    #		break
    #subprocess.Popen('python C:/Users/aa/proj_DB/mysite/Chatbot-master/chatbot.py', stdin=PIPE, stderr=STDOUT,executable=None, shell=False)
    return render(request, 'create_article.html', {'form': form})
Exemplo n.º 4
0
#-*- coding:utf-8 _*-
""" 
@author:charlesXu
@file: main.py 
@desc: chatbot 入口函数
@time: 2018/07/08 
"""
'''

   Main script. See README.md for more information


'''

from Chatbot import chatbot

if __name__ == "__main__":
    chatbot = chatbot.Chatbot()
    chatbot.main()
Exemplo n.º 5
0
import Chatbot.chatbot as Chatbot

chatter = Chatbot.Chatbot(build_console=False)

print("Hello, I am Mianbot.")

while True:
    raw = input()
    if raw == "_END_": break
    reply, confidence = chatter.testQuestionAnswering(raw)

    print("%s" % (reply))