-
Notifications
You must be signed in to change notification settings - Fork 1
/
gokativ.go
53 lines (46 loc) · 939 Bytes
/
gokativ.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
package gokativ
import "strings"
func Vokativ(name string) string {
lname := strings.ToLower(name)
if IsFem(lname) {
_, LastFirst := getMatchingSuffix(lname, wfvls)
if LastFirst == "l" {
return name
} else {
return vokativWomanFirstName(name)
}
}
return vokativMan(name)
}
func vokativMan(n string) string {
sfx, vsfx := getMatchingSuffix(n, ms)
sfxl := len(sfx)
nl := len(n)
if nl != 0 {
n = n[0 : nl-sfxl]
}
return n + vsfx
}
func vokativWomanFirstName(n string) string {
nl := len(n)
if n[nl-1] == 'a' {
return n[0:nl-1] + "o"
}
return n
}
func IsFem(name string) bool {
lname := strings.ToLower(name)
_, sx := getMatchingSuffix(lname, mvws)
return sx == "w"
}
func getMatchingSuffix(name string, suffices map[string]string) (string, string) {
ln := len(name)
for i := 0; i < ln; i++ {
sfx := name[i:ln]
v, ok := suffices[sfx]
if ok {
return sfx, v
}
}
return "", suffices[""]
}