-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
103 lines (92 loc) · 2.38 KB
/
Copy pathmain.go
File metadata and controls
103 lines (92 loc) · 2.38 KB
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
94
95
96
97
98
99
100
101
102
103
package main
import (
//"bufio"
"fmt"
"github.com/witheve/evingo/parser"
"github.com/witheve/evingo/util/color"
"github.com/witheve/evingo/value"
"io/ioutil"
"os"
"strconv"
//"strings"
)
func panicOnError(e error, msg string) {
if e != nil {
fmt.Println("ERROR: " + msg)
panic(e)
}
}
type Stringer interface {
String() string
}
func pprintCollection(list *interface{}) {
}
func doDotStuff() {
// genericize
tree := value.NewMapNode()
value.Insert(tree, []string{"a", "b", "c"}, value.NewValnode(value.NewText("d")))
value.Insert(tree, []string{"a", "b", "z"}, value.NewValnode(value.NewText("e")))
fmt.Println(value.Tree2dot(tree))
}
func main() {
args := os.Args
argsLen := len(args)
switch {
case argsLen == 1:
//print help
fmt.Printf("Welcome to %s", color.Bright("Eve!\n"))
fmt.Println("Here are the available commands:")
fmt.Printf(" - %s\n", color.Bright("dot"))
fmt.Printf(" - %s %s\n", color.Bright("parse"), color.Info("<file>"))
fmt.Printf(" - %s %s\n", color.Bright("parse"), color.Info("<file>"))
case args[1] == "dot":
doDotStuff()
case args[1] == "parse":
if argsLen > 2 {
parser.ParseFile(args[2])
} else {
fmt.Println(color.Error("Must provide a file to parse"))
}
case args[1] == "load":
fmt.Println("Loading", args[2])
if argsLen > 2 {
data, err := ioutil.ReadFile(args[2])
panicOnError(err, "Invalid JSON file '"+args[2]+"'")
var facts = ReadFactsFromJson(data)
if true {
fmt.Println("---FACTS---")
result := "[\n"
for k, item := range *facts {
result += " " + strconv.Itoa(k) + ": " + item.String() + ",\n"
}
fmt.Println(result[:len(result)-2] + "\n]")
}
var entities = FactsToEntities(facts)
if true {
fmt.Println("---ENTITIES---")
result := "[\n"
for k, item := range entities {
result += " " + strconv.Itoa(k) + ": " + item.String() + ",\n"
}
fmt.Println(result[:len(result)-2] + "\n]")
}
var tagMap = IndexEntitiesByTag(entities)
if true {
fmt.Println("---TAG MAP---")
fmt.Println(tagMap.String())
}
var query = TagMapToQueryGraph(tagMap)
if true {
fmt.Println("---QUERY GRAPH---")
fmt.Println(query.String())
}
//scanner := bufio.NewScanner(os.Stdin)
//for scanner.Scan() {
// line := scanner.Text()
// _ = strings.Split(line, " ")
//}
} else {
fmt.Println(color.Error("Must provide a file to load"))
}
}
}