-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredictTags.py
56 lines (43 loc) · 1.21 KB
/
predictTags.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pymysql
from nltk.corpus import stopwords
conn=pymysql.connect(host='127.0.0.1',user='root', passwd='root',port=8889,db='AlgebraNationWall')
a = conn.cursor()
sql = 'SELECT id, postGroup FROM TopicTags;'
a.execute(sql)
#countrow = a.execute(sql)
#print ("Number of rows :",countrow)
#data = a.fetchall()
b = conn.cursor()
c = conn.cursor()
try:
for row in a:
stop = set(stopwords.words('english'))
threadText = row[1]
threadtokens = [i for i in threadText.lower().split() if i not in stop]
sql2 = "Select * from ConceptBag"
tag = "Non-math"
matchcount = 0
matchStore = []
b.execute(sql2)
for conceptrow in b:
ConceptBagRaw = conceptrow[2]
concepttokens = [i for i in ConceptBagRaw.lower().split() if i not in stop]
matches = list(set(threadtokens).intersection(set(concepttokens)))
if len(matches)>matchcount:
matchcount = len(matches)
tag = conceptrow[1]
matchStore = matches
matchWords = str(matchStore)
sql2 = "UPDATE TopicTags SET matchedConceptWords = %s, predictedTag = %s where id ="+str(row[0])+";"
flag = c.execute(sql2, (matchWords, tag))
print flag
except Exception as e:
raise
print(e)
else:
pass
finally:
pass
conn.commit()
#print (a)
#print(data)