Skip to content
Snippets Groups Projects
Commit bbe37c89 authored by Muhamad Nobel Fauzan's avatar Muhamad Nobel Fauzan
Browse files

add get_close_matches

parent 49d392a8
No related merge requests found
from flask import Flask
from flask_socketio import SocketIO, send
from database import QAPair
from difflib import get_close_matches
import time
import threading
......@@ -9,10 +11,19 @@ socketio = SocketIO(app, cors_allowed_origins='*')
waiting_time = 10
last_msg = time.time() + 12
question = QAPair.query.with_entities(QAPair.question).all()
questions = [a.question for a in question]
@socketio.on('message')
def handleMessage(msg):
send("message received : " + msg, broadcast=False) #will be replaced with QA matching function
q = get_close_matches(msg, questions)
# send(q, broadcast=False)
if q:
ans = QAPair.query.filter_by(question = q[0]).first().answer
send(ans, broadcast=False)
else:
send("sorry, I don't understand the question", broadcast = False)
global last_msg
last_msg = time.time()
......
......@@ -9,10 +9,6 @@
$(document).ready(function() {
var socket = io.connect('http://127.0.0.1:5000');
socket.on('connect', function() {
socket.send('connected');
});
socket.on('message', function(msg) {
$("#messages").append('<li>'+msg+'</li>')
});
......
No preview for this file type
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment