This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnaminglanguage.go
93 lines (76 loc) · 2.25 KB
/
naminglanguage.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
87
88
89
90
91
92
93
package naminglanguage
import (
"fmt"
"strings"
)
// Word is a word
type Word struct {
Word string
Meaning string
Part string
}
// Language contains a dictionary of words and a word order
type Language struct {
Dictionary []Word
WordOrder []string
}
// Person is a representation of a person.
type Person struct {
FirstName string `json:",omitempty"`
LastName string `json:",omitempty"`
FirstNameMeaning string `json:",omitempty"`
LastNameMeaning string `json:",omitempty"`
}
// String returns the string version of Person
func (p *Person) String() string {
var fields []string
if p.FirstName != "" {
fields = append(fields, p.FirstName)
}
if p.LastName != "" {
fields = append(fields, p.LastName)
}
if p.FirstNameMeaning != "" {
fields = append(fields, fmt.Sprintf("(%s, %s)", p.FirstNameMeaning, p.LastNameMeaning))
}
return strings.Join(fields, " ")
}
// Place is representation of a place.
type Place struct {
Name string
// FIXME: unsure how to implement this, it was in the original issue for json though.
// Meaning string
}
// GeneratePerson generates a random name for a person.
func GeneratePerson() *Person {
language := GenerateLanguage()
firstName := randomNoun(language)
firstPartOfLastName := randomVerb(language)
secondPartOfLastName := randomNoun(language)
return &Person{
FirstName: strings.Title(firstName.Word),
LastName: strings.Title(firstPartOfLastName.Word + secondPartOfLastName.Word),
FirstNameMeaning: strings.Title(firstName.Meaning),
LastNameMeaning: strings.Title(nounFromVerb(firstPartOfLastName.Meaning) + " of " + pluralizeNoun(secondPartOfLastName.Meaning)),
}
}
// GeneratePlace generates a random name for a place.
func GeneratePlace() *Place {
language := GenerateLanguage()
firstPart := randomAdjective(language)
secondPart := randomNoun(language)
return &Place{
Name: firstPart.Word + secondPart.Word,
}
}
// GenerateLanguage generates a language
func GenerateLanguage() Language {
syllables := generateSyllables()
words := generateWords(syllables)
wordOrder := randomWordOrder()
language := Language{words, wordOrder}
return language
}
// TODO:
// GeneratePersonFromLanguage(lang *Language) *Person
// GeneratePlaceFromLanguage(lang *Language) *Place