func (s *Suggestion) PrintSubOrig(fromK string, toK string) { inOrder := func(k treemap.Key, v interface{}) { kw := string(k.(treemap.StrKey)) item := v.(Item) log.Println(kw, ":", item.Score, item.Info) } s.origSuggestionMap.DoSubTree(treemap.StrKey(fromK), treemap.StrKey(toK), inOrder) }
func (s *Suggestion) buildOrigSuggestionMap(items []Item) { s.origSuggestionMap = treemap.New() for _, item := range items { s.origSuggestionMap.Replace(treemap.StrKey(item.Keyword), item) } return }
func (s *Suggestion) buildAbbrSuggestionMap(items []Item) { s.abbrSuggestionMap = treemap.New() for _, item := range items { abbrStr := s.pinyin.WordStr2abbrString(item.Keyword) s.abbrSuggestionMap.Replace(treemap.StrKey(abbrStr), item) } return }
func (s *Suggestion) buildPinyinSuggestionMap(items []Item) { s.pinyinSuggestionMap = treemap.New() for _, item := range items { pinyinStr := s.pinyin.WordStr2pinyinStr(item.Keyword) s.pinyinSuggestionMap.Replace(treemap.StrKey(pinyinStr), item) } return }
func (s *Suggestion) Suggest(input string) (items []Item) { origInput := input pinyinInput := s.pinyin.WordStr2pinyinStr(input) fetchItem := func(k treemap.Key, v interface{}) { items = append(items, v.(Item)) } s.origSuggestionMap.DoSubTree(treemap.StrKey(origInput), treemap.StrKey(origInput+string(unicode.MaxRune)), fetchItem) s.pinyinSuggestionMap.DoSubTree(treemap.StrKey(pinyinInput), treemap.StrKey(pinyinInput+string(unicode.MaxRune)), fetchItem) s.abbrSuggestionMap.DoSubTree(treemap.StrKey(origInput), treemap.StrKey(origInput+string(unicode.MaxRune)), fetchItem) return }