-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
59 lines (50 loc) · 1.52 KB
/
main.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
package main
import (
"github.com/vharitonsky/iniflags"
"log"
"net/http"
"strconv"
)
var factory map[string]func(string) (AnswerProducer, error)
func init() {
factory = make(map[string]func(string) (AnswerProducer, error))
factory["indri"] = NewIndriAnswerProducer
factory["dummy"] = NewDummyAnswerProducer
factory["galago"] = NewGalagoAnswerProducer
}
func main() {
iniflags.Parse()
// Set up logging
if lw, err := NewLogWatch(); err != nil {
log.Printf("[flag -logfile] '%s' will carry on without the logfile\n", err)
} else {
http.Handle("/tail1000", lw)
}
if config.TrimQueries {
log.Printf("Testing stemming: '%s'\n", StemQuery("I like to stemming my queries"))
// This is a function rather an an init, as it relies of the results of the flags
LoadImportance()
log.Println(TrimQuery("This is a stemming queries that needs a bit of a trim dream babies"))
}
// Create a liveQA
lqa := NewLiveQA()
// Add answer producers
count := 0
for _, name := range config.Producers {
if f, ok := factory[name]; ok {
ap, err := f(name + ".json")
if err != nil {
log.Printf("[Error initialising %s] %s\n", name, err)
} else {
lqa.AddProducer(ap)
log.Printf("Initialised '%s' answer producer\n", name)
count++
}
} else {
log.Printf("[Error initialising %s] Unrecognised answer producer '%s'\n", name, name)
}
}
log.Printf("Initialised %d of %d total answer producers\n", count, len(config.Producers))
http.Handle("/", lqa)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(config.Port), nil))
}