Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Do the import here
- #
- import pymysql.cursors
- googleQueries = [] #[{relation: "...", phrase: "...", positive_search: ..., all_search:...}, ...]
- googleQueries.append({"relation":"award.award_winner.awards_won..award.award_honor.award", "phrase": "accepted the", "positive_search": 1, "all_search": 10})
- # EntryPoint of the module, only this function will be exposed
- #
- # Input: db_queries_result: output of the GoogleQuery modules as a dict arrays in python
- # Output: db_score_updated_temp: the phrases with their score updated
- #
- def UpdateScores():
- # Connect to the database
- connection = pymysql.connect(host='localhost',
- user='root',
- password='',
- db='lector',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- try:
- for element in googleQueries:
- if(float(element["positive_search"])/float(element["all_search"]) < .5):
- with connection.cursor() as cursor:
- sql = "SELECT `score` FROM `all_phrases_temp` WHERE `relation`=%s AND `phrase`=%s"
- cursor.execute(sql, (element["relation"], element["phrase"]))
- result = cursor.fetchone();
- print(result["score"] * float(element["positive_search"])/float(element["all_search"]))
- with connection.cursor() as cursor:
- sql = "UPDATE `all_phrases_temp` SET `score`=%s WHERE `relation`=%s AND `phrase`=%s"
- new_score = result["score"] * float(element["positive_search"])/float(element["all_search"])
- cursor.execute(sql, (new_score ,element["relation"], element["phrase"]))
- result = cursor.fetchone();
- print(result)
- connection.commit()
- finally:
- connection.close();
- print "Update Score works!"
- return
- UpdateScores();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement