-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (50 loc) · 1.17 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
60
61
package main
import (
"io/ioutil"
"log"
"os"
"path"
"strings"
"github.com/Tibart/socialanalogizer/analogizer"
"github.com/Tibart/socialanalogizer/graph"
)
func main() {
// Collect all vertices and correcpomding markdown documents
folder := "./data"
suffix := ".md"
files, err := ioutil.ReadDir(folder)
if err != nil {
log.Fatalf("could not read directory: %s", err)
}
allVertices := []string{}
for _, f := range files {
if strings.HasSuffix(f.Name(), suffix) {
vertex := strings.TrimSuffix(f.Name(), suffix)
allVertices = append(allVertices, vertex)
}
}
// Create graph instance
g := graph.NewGraph()
// Create Analogizer instance
a, _ := analogizer.NewAnalogizer(g, allVertices)
// Update vertex adjacents and amend corresponding markdown document
for _, vertex := range allVertices {
// Open file`
doc, err := os.OpenFile(path.Join(folder, vertex+suffix), os.O_RDWR, 0644)
if err != nil {
panic(err)
}
defer doc.Close()
// Amend new verteces
b, err := a.Amend(vertex, doc)
if err != nil {
panic(err)
}
// Write amended document
if _, err := doc.WriteAt(b, 0); err != nil {
panic(err)
}
}
// Print graph
a.Print()
}