-
Notifications
You must be signed in to change notification settings - Fork 0
/
awards.go
102 lines (91 loc) · 2.37 KB
/
awards.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
package entities
import (
"errors"
"fmt"
)
var _ = fmt.Println // remove after test
func makeAwardTypeSet() map[string]struct{} {
a := map[string]struct{}{}
a["PhD"] = struct{}{}
a["Masters"] = struct{}{}
a["Bachelors"] = struct{}{}
a["Associate"] = struct{}{}
a["HonorSociety"] = struct{}{}
a["TeachingAward"] = struct{}{}
a["ServiceAward"] = struct{}{}
a["ResearchAward"] = struct{}{}
a["SportsAward"] = struct{}{}
return a
}
var AwardTypeSet = makeAwardTypeSet()
type Award struct {
Key *Key
AwardType string
Title string
AwardingOrganization *Organization
Awardee *Person
AwardDate *Date
}
func NewAward(t string, d string) (*Award,error) {
p := new(Award)
p.Key = makeKey("Award")
_,ok := AwardTypeSet[t]
if !ok {
err := errors.New("Unknown award type: "+t)
return nil,err
}
p.AwardType = t
p.Title = d
return p, nil
}
func (a *Award) Triples () [][3]string {
var t [][3]string
t = append(t, makeTriple(Triple{(*a).Key,"hasType","Award",nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasAwardType",(*a).AwardType,nil}))
if (*a).AwardingOrganization != nil { t=append(t, makeTriple(Triple{(*a).Key,"hasAwardingOrganization","",(*a.AwardingOrganization).Key}))}
if (*a).Awardee != nil { t=append(t, makeTriple(Triple{(*a).Key,"hasAwardee","",(*a.Awardee).Key}))}
if (*a).AwardDate != nil { t=append(t, makeTriple(Triple{(*a).Key,"hasAwardDate","",(*a.AwardDate).Key}))}
return t
}
func (a *Award) Row() []string {
var t []string
t = append(t, a.Key.s)
t = append(t, a.AwardType)
t = append(t, a.Title)
if (*a).AwardingOrganization != nil { t=append(t, a.AwardingOrganization.Key.s)}
if (*a).Awardee != nil { t=append(t, a.Awardee.Key.s)}
if (*a).AwardDate != nil { t=append(t, a.AwardingOrganization.Key.s)}
return t
}
func FindAwardKey (kf *Key) int {
for i,a := range Awards {
if kf.s == a.Key.s {
return i
}
}
return -1
}
func AddAwardFact(a []string) {
key := new(Key)
key.s = a[0]
i := FindAwardKey(key)
switch a[1] {
case "AwardType":
Awards[i].AwardType = a[2]
case "Title":
Awards[i].Title = a[2]
case "AwardingOrganization":
key.s = a[2]
j := FindOrganizationKey(key)
Awards[i].AwardingOrganization = Organizations[j]
case "Awardee":
key.s = a[2]
j := FindPersonKey(key)
Awards[i].Awardee = People[j]
case "AwardDate":
key.s = a[2]
j := FindDateKey(key)
Awards[i].AwardDate = Dates[j]
}
}
var Awards []*Award