优化敏感字查询
This commit is contained in:
parent
9685db79be
commit
78a8114871
@ -43,6 +43,7 @@ class TextFilter(object):
|
|||||||
|
|
||||||
# Singleton
|
# Singleton
|
||||||
_instance = None
|
_instance = None
|
||||||
|
root = None
|
||||||
|
|
||||||
def __new__(cls, *args, **kw):
|
def __new__(cls, *args, **kw):
|
||||||
"""单例模式"""
|
"""单例模式"""
|
||||||
@ -51,11 +52,12 @@ class TextFilter(object):
|
|||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.root = Node()
|
if self.root == None:
|
||||||
self.sensitive_word = SensitiveWords().sensitive_word_dict
|
self.root = Node()
|
||||||
for word_type in self.sensitive_word.keys():
|
self.sensitive_word = SensitiveWords().sensitive_word_dict
|
||||||
for word in self.sensitive_word[word_type]:
|
for word_type in self.sensitive_word.keys():
|
||||||
self.add_word(word, word_type)
|
for word in self.sensitive_word[word_type]:
|
||||||
|
self.add_word(word, word_type)
|
||||||
|
|
||||||
def add_word(self, word, word_type=u'common'):
|
def add_word(self, word, word_type=u'common'):
|
||||||
"""向字典树里添加敏感词汇及敏感词类型"""
|
"""向字典树里添加敏感词汇及敏感词类型"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user