-
Notifications
You must be signed in to change notification settings - Fork 0
/
headline.go
46 lines (35 loc) · 958 Bytes
/
headline.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
package main
import (
"log"
"gopkg.in/yaml.v2"
"io/ioutil"
"math/rand"
"time"
"regexp"
)
type Content map[string][]string
func parseFile(location string) Content {
var content Content
// Get all the content
raw, err := ioutil.ReadFile(location)
if err != nil {
panic(err)
}
// Parse content
yaml.Unmarshal(raw, &content)
return content
}
func generateHeadline(content Content) string {
object_reg, err := regexp.Compile("%{object}")
if err != nil {
log.Fatal(err)
}
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
subject := content["subject"][r.Intn(len(content["subject"]))]
object := content["object"][r.Intn(len(content["object"]))]
action := content["action"][r.Intn(len(content["action"]))]
adverbial := content["adverbial"][r.Intn(len(content["adverbial"]))]
full_action := object_reg.ReplaceAllString(action, object)
return subject + " " + full_action + " " + adverbial
}