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
|
package names
import (
"airlines/pkg/model"
"strings"
"unicode"
)
func normalizeTitle(x string) string {
x = strings.ToLower(x)
// strip punctuation
x = strings.ReplaceAll(x, ".", "")
x = strings.ReplaceAll(x, "'", "")
x = strings.ReplaceAll(x, "’", "")
x = strings.ReplaceAll(x, "-", "")
return x
}
func GenderFromTitle(s string) model.Sex {
if s == "" {
return model.SexUnknown
}
cut := func(r rune) bool { return unicode.IsSpace(r) || r == ',' || r == '/' || r == '&' }
first := strings.FieldsFunc(s, cut)
if len(first) == 0 {
return model.SexUnknown
}
t := normalizeTitle(first[0])
// male
switch t {
case "mr", "sir", "lord", "monsieur", "m", "don", "senor", "sr":
return model.SexMale
}
// female
switch t {
case "mrs", "miss", "ms", "madam", "madame", "mademoiselle", "mlle",
"lady", "dame", "senora", "sra", "señora", "srta", "srita", "dona":
return model.SexFemale
}
// flying helicopter
return model.SexUnknown
}
|