-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSfAnalysis.py
More file actions
43 lines (34 loc) · 975 Bytes
/
Copy pathSfAnalysis.py
File metadata and controls
43 lines (34 loc) · 975 Bytes
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
import pynlpir
import sys
import pymysql
conn = pymysql.connect(host='127.0.0.1', user='root',
passwd='root', db='mysql', charset='utf8')
cur = conn.cursor()
cur.execute("use sf")
TF = {}
def Analysis(s):
print(s)
if s == None:
return
pynlpir.open()
try:
segments = pynlpir.segment(s)
except Exception as ee:
return
for segment in segments:
try:
TF[segment[0]]
except Exception as e:
TF[segment[0]] = 1
break
TF[segment[0]] = TF[segment[0]] + 1
pynlpir.close()
if __name__ == '__main__':
for id in range(1, 45106):
cur.execute("select introduce from `novel` where id = " + id.__str__())
data = cur.fetchone()
Analysis(data[0])
for x in TF.items():
print(x[0]+str(x[1]))
cur.execute("insert into ana (keyy, countt) values (%s, %s)", (x[0], str(x[1])))
cur.connection.commit()