|
|
@ -21,6 +21,7 @@ from csv import DictWriter, DictReader
|
|
|
|
import io
|
|
|
|
import io
|
|
|
|
from sqlalchemy.inspection import inspect
|
|
|
|
from sqlalchemy.inspection import inspect
|
|
|
|
import autocomplete
|
|
|
|
import autocomplete
|
|
|
|
|
|
|
|
from autocomplete import models
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
@ -399,7 +400,7 @@ def show_instances():
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/books', methods= ['POST','GET'])
|
|
|
|
@app.route('/books', methods= ['POST','GET'])
|
|
|
|
def show_books():
|
|
|
|
def show_books():
|
|
|
|
autocomplete.load() #Train markov model once, for autocomplete in search
|
|
|
|
#autocomplete.load() #Train markov model once, for autocomplete in search
|
|
|
|
|
|
|
|
|
|
|
|
books = db.session.query(Book).all()
|
|
|
|
books = db.session.query(Book).all()
|
|
|
|
search = SearchForm(request.form)
|
|
|
|
search = SearchForm(request.form)
|
|
|
@ -439,14 +440,15 @@ autocomplete_suggestions = []
|
|
|
|
autocomplete.load() #Train markov model once, for autocomplete in search
|
|
|
|
autocomplete.load() #Train markov model once, for autocomplete in search
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
|
|
|
|
@app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
|
|
|
|
def test1():
|
|
|
|
def autocomplete_search():
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
query = request.form['search']
|
|
|
|
query = request.form['search']
|
|
|
|
query_tokenized = query.lower().split()
|
|
|
|
query_tokenized = query.lower().split()
|
|
|
|
print(query_tokenized)
|
|
|
|
print(query_tokenized)
|
|
|
|
word_1 = query_tokenized[-2]
|
|
|
|
word_1 = query_tokenized[-2]
|
|
|
|
word_2 = query_tokenized[-1]
|
|
|
|
word_2 = query_tokenized[-1]
|
|
|
|
#print(word_1)
|
|
|
|
print(word_1)
|
|
|
|
|
|
|
|
print(word_2)
|
|
|
|
autocomplete_output = autocomplete.predict(word_1 , word_2)
|
|
|
|
autocomplete_output = autocomplete.predict(word_1 , word_2)
|
|
|
|
autocomplete_suggestions.clear()
|
|
|
|
autocomplete_suggestions.clear()
|
|
|
|
for suggestion, score in autocomplete_output:
|
|
|
|
for suggestion, score in autocomplete_output:
|
|
|
|