Advertisement
Guest User

Untitled

a guest
Dec 27th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. # Do the import here
  2. #
  3. import pymysql.cursors
  4.  
  5.  
  6. googleQueries = [] #[{relation: "...", phrase: "...", positive_search: ..., all_search:...}, ...]
  7.  
  8.  
  9. googleQueries.append({"relation":"award.award_winner.awards_won..award.award_honor.award", "phrase": "accepted the", "positive_search": 1, "all_search": 10})
  10. # EntryPoint of the module, only this function will be exposed
  11. #
  12. # Input: db_queries_result: output of the GoogleQuery modules as a dict arrays in python
  13. # Output: db_score_updated_temp: the phrases with their score updated
  14. #
  15. def UpdateScores():
  16. # Connect to the database
  17. connection = pymysql.connect(host='localhost',
  18. user='root',
  19. password='',
  20. db='lector',
  21. charset='utf8mb4',
  22. cursorclass=pymysql.cursors.DictCursor)
  23. try:
  24. for element in googleQueries:
  25. if(float(element["positive_search"])/float(element["all_search"]) < .5):
  26. with connection.cursor() as cursor:
  27. sql = "SELECT `score` FROM `all_phrases_temp` WHERE `relation`=%s AND `phrase`=%s"
  28. cursor.execute(sql, (element["relation"], element["phrase"]))
  29. result = cursor.fetchone();
  30. print(result["score"] * float(element["positive_search"])/float(element["all_search"]))
  31. with connection.cursor() as cursor:
  32. sql = "UPDATE `all_phrases_temp` SET `score`=%s WHERE `relation`=%s AND `phrase`=%s"
  33. new_score = result["score"] * float(element["positive_search"])/float(element["all_search"])
  34. cursor.execute(sql, (new_score ,element["relation"], element["phrase"]))
  35. result = cursor.fetchone();
  36. print(result)
  37. connection.commit()
  38. finally:
  39. connection.close();
  40. print "Update Score works!"
  41. return
  42.  
  43. UpdateScores();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement