forked from shibing624/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_rule.py
More file actions
53 lines (44 loc) · 1.26 KB
/
check_rule.py
File metadata and controls
53 lines (44 loc) · 1.26 KB
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
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description:
"""
def load_word_set(save_path):
words = set()
with open(save_path, 'r', encoding='utf-8') as f:
for line in f:
if line.startswith("#"):
continue
words.add(line.strip())
return words
def load_query_set(save_path):
words = set()
with open(save_path, 'r', encoding='utf-8') as f:
for line in f:
if line.startswith("#"):
continue
words.add(line.strip())
return words
class Risk(object):
def __init__(self, risk_words_path=""):
self.risk_words = load_word_set(risk_words_path)
print("risk words size: %d" % len(self.risk_words))
def check(self, query):
# query is empty , return None
if not query.strip():
return
for w in self.risk_words:
if w in query:
return w
return None
if __name__ == "__main__":
risk = Risk(risk_words_path="medical_tech.txt")
input_queries = load_query_set("medical_tech_remark.txt")
stat = []
num = 0
for i in input_queries:
ret = risk.check(i)
if ret:
num += 1
stat.append([ret, i[:10], num])
print(stat)