-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
139 lines (127 loc) · 3.62 KB
/
events.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package entities
import (
"errors"
"fmt"
"strings"
)
var _ = fmt.Println // remove after test
func makeEventTypeSet() map[string]struct{} {
a := map[string]struct{}{}
a["Conference"] = struct{}{}
a["Symposium"] = struct{}{}
a["Workshop"] = struct{}{}
a["Fundraiser"] = struct{}{}
a["Meeting"] = struct{}{}
return a
}
var EventTypeSet = makeEventTypeSet()
type Event struct {
Key *Key
EventType string
Name string
Organizer *Organization
Location *Location
StartDate *Date
EndDate *Date
Sponsors []*Organization
Attendees []*Person
}
func NewEvent(t string, n string) (*Event, error) {
p := new(Event)
p.Key = makeKey("Event")
_,ok := EventTypeSet[t]
if !ok {
err := errors.New("Unknown Event type: " + t)
return nil, err
}
p.EventType = t
p.Name = n
return p,nil
}
func NewConference(n string) (*Event,error) { return NewEvent("Conference", n) }
func NewSymposium(n string) (*Event,error) { return NewEvent("Symposium", n) }
func NewWorkshop(n string) (*Event,error) { return NewEvent("Workshop", n) }
func NewFundraiser(n string) (*Event,error) { return NewEvent("Fundraiser", n) }
func NewMeeting(n string) (*Event,error) { return NewEvent("Meeting", n) }
func (a *Event) Triples () [][3]string {
var t [][3]string
t = append(t, makeTriple(Triple{(*a).Key,"hasType","Event",nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasEventType",(*a).EventType,nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasName",(*a).Name,nil}))
if (*a).Organizer != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasOrganizer","",(*a.Organizer).Key}))}
if (*a).Location != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasLocation","",(*a.Location).Key}))}
if (*a).StartDate != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasStartDate","",(*a.StartDate).Key}))}
if (*a).EndDate != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasEndDate","",(*a.EndDate).Key}))}
for _,cptr := range (*a).Sponsors {
t = append(t, makeTriple(Triple{(*a).Key,"hasSponsor","",cptr.Key}))
}
for _,cptr := range (*a).Attendees {
t = append(t, makeTriple(Triple{(*a).Key,"hasAttendee","",cptr.Key}))
}
return t
}
func (a *Event) Row() []string {
var t []string
var sp []string
var at []string
t = append(t, a.Key.s)
t = append(t, a.EventType)
t = append(t, a.Name)
if a.Organizer != nil { t=append(t, a.Organizer.Key.s)}
if a.Location != nil { t=append(t, a.Location.Key.s)}
if a.StartDate != nil { t=append(t, a.StartDate.Key.s)}
if a.EndDate != nil { t=append(t, a.EndDate.Key.s)}
for _,cptr := range (*a).Sponsors {
sp = append(sp, cptr.Key.s)
}
t = append(t,strings.Join(sp,","))
for _,cptr := range (*a).Attendees {
at = append(at, cptr.Key.s)
}
t = append(t,strings.Join(at,","))
return t
}
func FindEventKey (kf *Key) int {
for i,a := range Events {
if kf.s == a.Key.s {
return i
}
}
return -1
}
func AddEventFact(a []string) {
key := new(Key)
key.s = a[0]
i := FindEventKey(key)
switch a[1] {
case "EventType":
Events[i].EventType = a[2]
case "Name":
Events[i].Name = a[2]
case "Organizer":
key.s = a[2]
j := FindOrganizationKey(key)
Events[i].Organizer = Organizations[j]
case "Location":
key.s = a[2]
j := FindLocationKey(key)
Events[i].Location = Locations[j]
case "StartDate":
key.s = a[2]
j := FindDateKey(key)
Events[i].StartDate = Dates[j]
case "EndDate":
key.s = a[2]
j := FindDateKey(key)
Events[i].EndDate = Dates[j]
case "Sponsor":
key.s = a[2]
j := FindOrganizationKey(key)
Events[i].Sponsors = append(Events[i].Sponsors,Organizations[j])
case "Attendee":
key.s = a[2]
j := FindPersonKey(key)
Events[i].Attendees = append(Events[i].Attendees,People[j])
}
}
var Events []*Event