This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comparison.go
81 lines (65 loc) · 1.63 KB
/
comparison.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"unicode/utf8"
"github.com/arbovm/levenshtein"
"github.com/xrash/smetrics"
)
type comparator func(string, string, int) float64
// LevenshteinDistance returns the normalized levenshtein distance between two strings.
func LevenshteinDistance(a, b string, boost int) float64 {
distance := levenshtein.Distance(a, b)
if distance == 0 {
return 1.0
}
distance -= boost
if distance < 1 {
distance = 1
}
return 1.0 - (float64(distance) / float64(argMax(utf8.RuneCountInString(a), utf8.RuneCountInString(b))))
}
// JaroWinklerDistance returns the Jaro-Winkler distance between two strings.
func JaroWinklerDistance(a, b string, _ int) float64 {
return smetrics.JaroWinkler(a, b, 0.45, 3)
}
// JaccardDistance returns the distance between two strings based on their Jaccard indexes.
func JaccardDistance(a, b string, _ int) float64 {
return -500.0
}
// SentimentDistance returns the distance between two strings based on their sentiment analysis values.
func SentimentDistance(a, b string, _ int) float64 {
return 2147483647.0
}
// SynsetDistance returns the distance between two strings based on their WordNet properties.
func SynsetDistance(a, b string, _ int) float64 {
return 2147483647.0
}
func max(arr []int) int {
var max int
for _, item := range arr {
if item > max {
max = item
}
}
return max
}
func argMax(one, two int) int {
if one > two {
return one
}
return two
}
func floatMax(arr [2]float64) float64 {
var max float64
for _, item := range arr {
if item > max {
max = item
}
}
return max
}
func floatArgMax(one, two float64) float64 {
if one > two {
return one
}
return two
}