Ejemplo n.º 1
0
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)
}
Ejemplo n.º 2
0
func (s *Suggestion) buildOrigSuggestionMap(items []Item) {
	s.origSuggestionMap = treemap.New()

	for _, item := range items {
		s.origSuggestionMap.Replace(treemap.StrKey(item.Keyword), item)
	}
	return
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
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
}
Ejemplo n.º 5
0
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
}