Documentation ¶
Overview ¶
Package lsdp provides Weighted Levenshtein distance and its extended interface
Index ¶
- func DistanceAll(dm DistanceMeasurer, orig string, strs []string) []float64
- func Lsd(a, b string) int
- func Nearest(dm DistanceMeasurer, orig string, strs []string) (nearest string, distance float64)
- type DistanceFunc
- type DistanceMeasurer
- type EditCounts
- type EditType
- type LevenshteinParam
- type Weights
- type WeightsByRune
- func (wr *WeightsByRune) Delete(runeGroup string, delCost float64) *WeightsByRune
- func (wr *WeightsByRune) Distance(a, b string) float64
- func (wr *WeightsByRune) Insert(runeGroup string, insCost float64) *WeightsByRune
- func (wr *WeightsByRune) Replace(runeGroupSrc, runeGroupDest string, repCost float64) *WeightsByRune
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DistanceAll ¶
func DistanceAll(dm DistanceMeasurer, orig string, strs []string) []float64
DistanceAll returns slice of distance orig to each strs
Example ¶
std := lsdp.Weights{1, 1, 1} group := []string{"apple", "orange", "lemon", "water melon"} fmt.Println(lsdp.DistanceAll(std, "mon", group))
Output: [5 5 2 8]
func Nearest ¶
func Nearest(dm DistanceMeasurer, orig string, strs []string) (nearest string, distance float64)
Nearest returns the nearest string in the specified distance measurer
Example ¶
std := lsdp.Weights{1, 1, 1} group := []string{"apple", "orange", "lemon", "water melon"} fmt.Println(lsdp.Nearest(std, "mon", group))
Output: lemon 2
Types ¶
type DistanceFunc ¶ added in v1.4.0
DistanceFunc type is an adapter to allow the use of ordinary functions as DistanceMeasurer. Similar to http.HandlerFunc.
func (DistanceFunc) Distance ¶ added in v1.4.0
func (f DistanceFunc) Distance(a, b string) float64
Distance calls f(a,b)
type DistanceMeasurer ¶
DistanceMeasurer provides measurement of the distance between 2 strings
func Normalized ¶
func Normalized(dm DistanceMeasurer) DistanceMeasurer
Normalized returns what wrapped the DistanceMeasurer with nomalize by string length
type EditCounts ¶
type EditCounts [4]int
EditCounts represents aggregating by editing types
func CountEdit ¶
func CountEdit(a, b string) (int, EditCounts)
CountEdit aggregates the minimum number of edits to change from a to b
type EditType ¶
type EditType int
EditType represents authorized editing means in Levenshtein distance
type LevenshteinParam ¶
LevenshteinParam represents Levenshtein distance parameters for weighted by edit counts
func (LevenshteinParam) Distance ¶
func (p LevenshteinParam) Distance(a, b string) float64
Distance returns Levenshtein distance
type WeightsByRune ¶
type WeightsByRune struct {
// contains filtered or unexported fields
}
WeightsByRune represents weighted levenshtein distance by rune
func ByRune ¶
func ByRune(w *Weights) *WeightsByRune
ByRune returns weighted levenshtein distance by rune
Example ¶
wr := lsdp.ByRune(&lsdp.Weights{1, 1, 1}). Insert("a", 0.1). Delete("b", 0.01). Replace("c", "d", 0.001) fmt.Println(wr.Distance("bc", "ad"))
Output: 0.111
func (*WeightsByRune) Delete ¶
func (wr *WeightsByRune) Delete(runeGroup string, delCost float64) *WeightsByRune
Delete specify cost by delete rune
func (*WeightsByRune) Distance ¶
func (wr *WeightsByRune) Distance(a, b string) float64
Distance returns weighted levenshtein distance by rune
func (*WeightsByRune) Insert ¶
func (wr *WeightsByRune) Insert(runeGroup string, insCost float64) *WeightsByRune
Insert specify cost by insert rune
func (*WeightsByRune) Replace ¶
func (wr *WeightsByRune) Replace(runeGroupSrc, runeGroupDest string, repCost float64) *WeightsByRune
Replace specify cost by replace rune