blob: 78ba0a5408bcabc985a79cd190164925fec6b575 [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package compare implements comparators which can be used to score similarity
// between various build attributes.
package compare
import (
"github.com/texttheater/golang-levenshtein/levenshtein"
)
// TextComparator is an interface which can score similarity between two
// strings.
type TextComparator interface {
Compare(s1, s2 string) float64
}
// LevenshteinComparator implements the TextComparator interface, and scores
// similarity between two strings as their Levenshtein ratio.
type LevenshteinComparator struct {
Opts levenshtein.Options
}
func (c LevenshteinComparator) Compare(s1, s2 string) float64 {
return levenshtein.RatioForStrings([]rune(s1), []rune(s2), c.Opts)
}