-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganizations.go
131 lines (118 loc) · 4.3 KB
/
organizations.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
package entities
import (
"errors"
"fmt"
)
var _ = fmt.Println // remove after test
func makeOrganizationTypeSet() map[string]struct{} {
a := map[string]struct{}{}
a["Company"] = struct{}{}
a["University"] = struct{}{}
a["College"] = struct{}{}
a["Department"] = struct{}{}
a["Office"] = struct{}{}
a["Nonprofit"] = struct{}{}
a["Research"] = struct{}{}
a["Education"] = struct{}{}
a["Religious"] = struct{}{}
a["Military"] = struct{}{}
a["Government"] = struct{}{}
a["Professional"] = struct{}{}
a["Governance"] = struct{}{}
a["Club"] = struct{}{}
a["NGO"] = struct{}{}
return a
}
var OrganizationTypeSet = makeOrganizationTypeSet()
type Organization struct {
Key *Key
OrganizationType string
Name string
ChildOrganization *Organization
ParentOrganization *Organization
Logo *Image
Homepage *URL
Resources []*Resource
}
func NewOrganization(t string, n string) (*Organization,error) {
p := new(Organization)
p.Key = makeKey("Organization")
_,ok := OrganizationTypeSet[t]
if !ok {
err := errors.New("Unknown organization type: "+t)
return nil, err
}
p.OrganizationType = t
p.Name = n
return p, nil
}
func NewCompany(n string) (*Organization,error) {return NewOrganization("Company", n)}
func NewUniversity(n string) (*Organization,error) {return NewOrganization("University", n)}
func NewCollege(n string) (*Organization,error) {return NewOrganization("College", n)}
func NewDepartment(n string) (*Organization,error) {return NewOrganization("Department", n)}
func NewOffice(n string) (*Organization,error) {return NewOrganization("Office", n)}
func NewNonprofit(n string) (*Organization,error) {return NewOrganization("Nonprofit", n)}
func NewInstitute(n string) (*Organization,error) {return NewOrganization("Research", n)}
func NewSchool(n string) (*Organization,error) {return NewOrganization("Education", n)}
func NewChurch(n string) (*Organization,error) {return NewOrganization("Religious", n)}
func NewMilitary(n string) (*Organization,error) {return NewOrganization("Military", n)}
func NewGovernanment(n string) (*Organization,error) {return NewOrganization("Government", n)}
func NewAssociation(n string) (*Organization,error) {return NewOrganization("Professional", n)}
func NewGovernance(n string) (*Organization,error) {return NewOrganization("Governance", n)}
func NewClub(n string) (*Organization,error) {return NewOrganization("Club", n)}
func NewNGO(n string) (*Organization,error) {return NewOrganization("NGO", n)}
func (a *Organization) Triples () [][3]string {
var t [][3]string
t = append(t, makeTriple(Triple{(*a).Key,"hasType","Organization",nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasOrganizationType",(*a).OrganizationType,nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasName",(*a).Name,nil}))
if (*a).ChildOrganization != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasChildOrganization","",(*a.ChildOrganization).Key}))}
if (*a).ParentOrganization != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasParentOrganization","",(*a.ParentOrganization).Key}))}
if (*a).Logo != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasLogo","",(*a.Logo).Key}))}
if (*a).Homepage != nil {t = append(t, makeTriple(Triple{(*a).Key,"hasHomepage","",(*a.Homepage).Key}))}
for _,cptr := range (*a).Resources {
t = append(t, makeTriple(Triple{(*a).Key,"hasResource","",cptr.Key}))
}
return t
}
func FindOrganizationKey (kf *Key) int {
for i,a := range Organizations {
if kf.s == a.Key.s {
return i
}
}
return -1
}
func AddOrganizationFact(a []string) {
key := new(Key)
key.s = a[0]
i := FindOrganizationKey(key)
switch a[1] {
case "OrganizationType":
Organizations[i].OrganizationType = a[2]
case "Name":
Organizations[i].Name = a[2]
case "ChildOrganization":
key.s = a[2]
j := FindOrganizationKey(key)
Organizations[i].ChildOrganization = Organizations[j]
case "ParentOrganization":
key.s = a[2]
j := FindOrganizationKey(key)
Organizations[i].ParentOrganization = Organizations[j]
case "Logo":
key.s = a[2]
j := FindImageKey(key)
Organizations[i].Logo= Images[j]
case "Homepage":
key.s = a[2]
j := FindURLKey(key)
Organizations[i].Homepage = URLs[j]
case "Resource":
key.s = a[2]
j := FindResourceKey(key)
fmt.Println(j,key,a)
Organizations[i].Resources = append(Organizations[i].Resources,Resources[j])
}
}
var Organizations []*Organization