1
0
mirror of https://github.com/fumiama/jieba.git synced 2026-06-12 05:00:24 +08:00

added tests for dictionary.go, fixed a small bug

This commit is contained in:
Wang Bin
2015-04-30 11:02:01 +08:00
parent 0124ebadce
commit ae54d82c68
2 changed files with 51 additions and 0 deletions

View File

@@ -16,6 +16,10 @@ type Dictionary struct {
sync.RWMutex
}
func New() *Dictionary {
return &Dictionary{freqMap: make(map[string]float64)}
}
func (d *Dictionary) addToken(token Token) {
d.freqMap[token.text] = token.frequency
d.total += token.frequency
@@ -84,6 +88,8 @@ func (d *Dictionary) loadDictionary(fileName string, isUserDictionary bool) erro
if !isUserDictionary && len(d.freqMap) > 0 {
d.freqMap = make(map[string]float64)
d.total = 0.0
d.logTotal = 0.0
}
for scanner.Scan() {
line = scanner.Text()