-
Notifications
You must be signed in to change notification settings - Fork 0
/
lisp_ling.go
86 lines (69 loc) · 3.11 KB
/
lisp_ling.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
82
83
84
85
86
package z3s5
import (
ling "github.com/jamesturk/go-jellyfish"
"github.com/nukata/goarith"
)
func (interp *Interp) Define_Ling() {
// register this module
reflect, ok := interp.GetGlobalVar(ReflectSym)
if !ok {
reflect = Nil
}
interp.SetGlobalVar(ReflectSym, &Cell{NewSym("ling"), reflect})
// (ling.soundex s) => str compute the soundex representation of s
interp.Def("ling.soundex", 1, func(a []any) any {
return ling.Soundex(a[0].(string))
})
// (ling.metaphone s) => str compute the metaphone representation of s
interp.Def("ling.metaphone", 1, func(a []any) any {
return ling.Metaphone(a[0].(string))
})
// (ling.nysiis s) => str compute the nysiis representation of s
interp.Def("ling.nysiis", 1, func(a []any) any {
return ling.Nysiis(a[0].(string))
})
// (ling.porter s) => str compute the stem of s using the Porter stemming algorithm
interp.Def("ling.porter", 1, func(a []any) any {
return ling.Porter(a[0].(string))
})
// (ling.match-rating-codex s) => str compute the match-rating codex of s
interp.Def("ling.match-rating-codex", 1, func(a []any) any {
return ling.MatchRatingCodex(a[0].(string))
})
// (ling.damerau-levenshtein s1 s2) => num compute the Damerau-Levenshtein distance between s1 and s2
interp.Def("ling.damerau-levenshtein", 2, func(a []any) any {
return goarith.AsNumber(ling.DamerauLevenshtein(a[0].(string), a[1].(string)))
})
// (ling.hamming s1 s2) => num compute the Hamming distance between s1 and s2
interp.Def("ling.hamming", 2, func(a []any) any {
return goarith.AsNumber(ling.Hamming(a[0].(string), a[1].(string)))
})
// (ling.jaro s1 s2) => num compute the Jaro distance between s1 and s2
interp.Def("ling.jaro", 2, func(a []any) any {
return goarith.AsNumber(ling.Jaro(a[0].(string), a[1].(string)))
})
// (ling.jaro-winkler s1 s2) => num compute the Jaro-Winkler distance between s1 and s2
interp.Def("ling.jaro-winkler", 2, func(a []any) any {
return goarith.AsNumber(ling.JaroWinkler(a[0].(string), a[1].(string)))
})
// (ling.levenshtein s1 s2) => num compute the Levenshtein distance between s1 and s2
interp.Def("ling.levenshtein", 2, func(a []any) any {
return goarith.AsNumber(ling.Levenshtein(a[0].(string), a[1].(string)))
})
// (ling.match-rating-compare s1 s2) => bool return true if s1 and s2 are equal according to the Match-Rating algorithm, nil otherwise.
interp.Def("ling.match-rating-compare", 2, func(a []any) any {
return AsLispBool(ling.MatchRatingComparison(a[0].(string), a[1].(string)))
})
}
/*
Copyright (c) 2019-2022 Erich Rast
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/