def get_feedback(query): feedback_query = "UPDATE user_query SET correct = %s ORDER BY time_asked DESC LIMIT 1;" query = query.lower().strip('.') if query == "yes" or query == "correct" or query == "right" or query == "good bot": connection = make_connection() try: with connection.cursor() as cursor: cursor.execute(feedback_query, True) connection.commit() finally: connection.close() return "Thanks for the feedback." if query == "no" or query == "false" or query == "wrong" or query == "bad bot": connection = make_connection() try: with connection.cursor() as cursor: cursor.execute(feedback_query, False) connection.commit() finally: connection.close() return "Ops. Sorry about that. I will try to do better in the future. Thanks for the feedback."
def get_variable_values(variable): """ Returns the possible values of a variable in the variables table""" connection = make_connection() try: with connection.cursor() as cursor: cursor.execute( "SELECT table_name, field_name FROM variable WHERE name = {};". format(variable)) result = cursor.fetchone() cursor.execute( "SELECT {table_name} FROM {field_name};".format(**result)) return [row[result['field_name']] for row in cursor.fetchall()] finally: connection.close()
def get_questions(): """ Gets the questions and answers for each question in the questions table """ connection = make_connection() try: with connection.cursor() as cursor: cursor.execute("SELECT question_text, response FROM question;") return [(row['question_text'], row['response']) for row in cursor.fetchall()] except: print( "Warning, could not load questions from database.", "If the database hasn't be initialized please do so with python main.py --init", file=stderr) return [] finally: connection.close()
def ingest_cs_minors(data): connection = make_connection() try: with connection.cursor() as cursor: cursor.execute('TRUNCATE TABLE cs_minor_info;') cursor.execute( '''INSERT INTO cs_minor_info (division_units, minor_general_requirements, minor_flowchart_link,required_courses,steps,minimum_gpa,prerequisites,application_link,required_units,approved_elective_units) VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s");''', (data['division-units'], data['minor-general-requirements'], data['minor-flowchart-link'], data['required-minor-courses'], ", ".join(data['minor-steps']), data['minimum-gpa-minor'], data['minor-prerequisites'], data['minor-application-link'], data['minor-required-units'], data['minor-approved-elective-units'])) connection.commit() finally: connection.close()
def answer_query(query, save=True): start_time = time.time() matched_question, matched_answer, score, vars = rd.most_relevant_query( query) start_time = time.time() if save: connection = make_connection() try: with connection.cursor() as cursor: cursor.execute( """INSERT INTO user_query (query_text, matched_question) SELECT %s AS query_text, question.id AS matched_question FROM question WHERE question.question_text = %s;""", (query, matched_question)) connection.commit() finally: connection.close() #print("Saved query in", time.time() - start_time) return qs.answer_question(query, matched_answer)
from src.query_scanner import QueryScanner from src.database_connection import make_connection import sys qs = QueryScanner() response_variables_queries = qs.response_variables_queries connection = make_connection() values = { 'course-units': 2, 'major': 'CSC', 'season': 'Sp', 'elective-type': 'Required Course', 'year-range': '2019 - 2020', 'minor': 'Data Science minor', 'class-level': 'junior', 'division-level': 'upper', 'ge-area': 'A', 'num-units': 4 } def test_all_queries(verbose=False): try: with connection.cursor() as cursor: for variable in response_variables_queries: query = response_variables_queries[variable] if query != "": query = query.replace('[', '{')