forked from moov-io/fed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize.go
69 lines (61 loc) · 1.82 KB
/
normalize.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
// Copyright 2022 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package fed
import (
"regexp"
"strings"
)
var (
symbolReplacer = strings.NewReplacer(
".", "",
",", "",
":", "",
"/", " ",
"(", "",
")", "",
"-", " ", // 'CITIBANK-NEW YORK' => 'CITIBANK NEW YORK'
)
wasteReplacer = strings.NewReplacer(
"N.A.", " ",
)
spaceTrimming = regexp.MustCompile(`\s{2,}`)
// Replacements for banks that have lots of similar names.
// The big banks will have '$name - Arizona' which confuses logo search tools, so just replace them with known-good names.
//
// Based on https://github.com/wealthsimple/frb-participants/blob/master/data/manually-normalized-institution-names.yml
nameReplacements = map[string]string{
"ALLY BANK": "Ally Bank",
"AMERICAN EXPRESS": "American Express",
"BANK OF AMERICA": "Bank of America",
"CAPITAL ONE": "Capital One",
"CHARLES SCHWAB BANK": "Charles Schwab",
"CITIBANK": "Citibank",
"FIDELITY BANK": "Fidelity",
"HSBC": "HSBC Bank",
"JPMORGAN CHASE": "Chase",
"PNC BANK": "PNC Bank",
"SUNTRUST": "SunTrust",
"TD BANK": "TD Bank",
"WELLS FARGO": "Wells Fargo",
"US BANK": "US Bank",
"USAA": "USAA",
}
)
func Normalize(name string) string {
for sub, answer := range nameReplacements {
if strings.Contains(name, sub) {
return answer
}
}
return RemoveDuplicatedSpaces(StripSymbols(StripWaste(name)))
}
func StripSymbols(name string) string {
return symbolReplacer.Replace(name)
}
func StripWaste(name string) string {
return wasteReplacer.Replace(name)
}
func RemoveDuplicatedSpaces(name string) string {
return spaceTrimming.ReplaceAllString(name, " ")
}