Пример #1
0
func SendSuggestion(suggestion model.Suggestion, c *model.WsContext) {
	if suggestion.Recommendation.Genesis == c.UserId {
		return
	}
	if _, in := SentSuggestions[c.UserId]; in {
		for _, sentSuggestion := range SentSuggestions[c.UserId] {
			distance := matchr.Levenshtein(suggestion.Recommendation.Text, sentSuggestion.Recommendation.Text)
			if distance < 10 {
				return
			}
		}
	} else {
		SentSuggestions[c.UserId] = make([]model.Suggestion, 0)
	}
	log.Info("Sending suggestion to user %v", c.UserId)
	SentSuggestions[c.UserId] = append(SentSuggestions[c.UserId], suggestion)
	SentSuggestions[suggestion.Recommendation.Genesis] = append(SentSuggestions[suggestion.Recommendation.Genesis], suggestion)
	c.SendI(suggestion)
}
Пример #2
0
//fuzzyMap uses a word-similarity algorithm to match a value to its dictionary key, then assigns it the dictionary value
func fuzzyMap(datum string, mappings []datasources.Setting) string {
	var distances []float64
	result := ""

	for _, mapping := range mappings {
		d := matchr.Levenshtein(datum, mapping.Label)
		distances = append(distances, float64(d))
	}

	minDistance, err := stats.Min(distances)
	if err != nil {
		log.Fatal("Error finding minimum: ", err)
	}

	for i, distance := range distances {
		if int(minDistance) == int(distance) {
			result = mappings[i].Value
			break
		}
	}

	return result
}