Add a word to dictionary. freq and tag can be omitted, freq defaults to be a calculated value that ensures the word can be cut out.
(self, word, freq=None, tag=None)
| 416 | self.add_word(word, freq, tag) |
| 417 | |
| 418 | def add_word(self, word, freq=None, tag=None): |
| 419 | """ |
| 420 | Add a word to dictionary. |
| 421 | |
| 422 | freq and tag can be omitted, freq defaults to be a calculated value |
| 423 | that ensures the word can be cut out. |
| 424 | """ |
| 425 | self.check_initialized() |
| 426 | word = strdecode(word) |
| 427 | freq = int(freq) if freq is not None else self.suggest_freq(word, False) |
| 428 | self.FREQ[word] = freq |
| 429 | self.total += freq |
| 430 | if tag: |
| 431 | self.user_word_tag_tab[word] = tag |
| 432 | for ch in xrange(len(word)): |
| 433 | wfrag = word[:ch + 1] |
| 434 | if wfrag not in self.FREQ: |
| 435 | self.FREQ[wfrag] = 0 |
| 436 | if freq == 0: |
| 437 | finalseg.add_force_split(word) |
| 438 | |
| 439 | def del_word(self, word): |
| 440 | """ |
no test coverage detected