-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalizers.go
72 lines (58 loc) · 1.2 KB
/
normalizers.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
package sammy
import (
"fmt"
"github.com/kayex/sammy/text"
)
type Normalizer func(string) string
func NormalizeAccidentals(s string) string {
replacements := make(map[string]string)
for _, a := range flats {
m := flatMirror[a]
replacements[a] = m
replacements[major(a)] = major(m)
replacements[minor(a)] = minor(m)
}
for search, replace := range replacements {
q := &text.ReplaceQuery{
Search: text.CaseInsensitiveWord{
Word: text.Word{
W: search,
Delimiter: text.FilenameComponentDelimiter,
},
},
Replacement: replace,
}
s = q.Apply(s)
}
return s
}
func ExtendMajor(s string) string {
for _, k := range keys() {
q := &text.ReplaceQuery{
Search: text.CaseInsensitiveWord{
Word: text.Word{
W: k,
Delimiter: text.FilenameComponentDelimiter,
},
},
Replacement: major(k),
}
s = q.Apply(s)
}
return s
}
func ExtendMinor(s string) string {
for _, k := range keys() {
q := &text.ReplaceQuery{
Search: text.CaseInsensitiveWord{
Word: text.Word{
W: fmt.Sprintf("%sm", k),
Delimiter: text.FilenameComponentDelimiter,
},
},
Replacement: minor(k),
}
s = q.Apply(s)
}
return s
}