MCPcopy Create free account
hub / github.com/MachineLP/TextMatch / init

Method init

textmatch/models/text_embedding/bow_sklearn.py:45–66  ·  view source on GitHub ↗
(self, words_list=None, update=True)

Source from the content-addressed store, hash-verified

43
44 # init
45 def init(self, words_list=None, update=True):
46 if (~os.path.exists(self.dic_path) or ~os.path.exists(self.bow_model_path) or ~os.path.exists(self.bow_index_path) or update) and (words_list!=None):
47 word_list = self._seg_word(words_list)
48
49 if os.path.exists(self.dic_path) and update==False:
50 with open(self.dic_path, 'rb') as f:
51 self.vectorizer = pickle.load(f)
52 else:
53 try:
54 logging.info('[Bow] start build tfidf model.')
55 if words_list==None:
56 logging.error( '[Bow] words_list is None' )
57 self._gen_model(word_list)
58 logging.info('[Bow] build tfidf model success.')
59 except Exception as e:
60 logging.error( '[Bow] build tfidf model error,error info: {} '.format(e) )
61 if words_list!=None:
62 self.words_list_pre = []
63 for per_word in words_list:
64 self.words_list_pre.append( self._normalize( self._predict(per_word) )[0] )
65 self.words_list_pre = np.array(self.words_list_pre)
66 return self
67 '''
68 # seg word
69 def _seg_word(self, words_list, jieba_flag=True, del_stopword=False):

Callers

nothing calls this directly

Calls 4

_seg_wordMethod · 0.95
_gen_modelMethod · 0.95
_predictMethod · 0.95
_normalizeMethod · 0.45

Tested by

no test coverage detected