-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourses.go
117 lines (101 loc) · 2.78 KB
/
courses.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
package entities
import (
"errors"
"fmt"
)
var _ = fmt.Println // remove after test
func makeCourseTypeSet() map[string]struct{} {
a := map[string]struct{}{}
a["ShortCourse"] = struct{}{}
a["AcademicCourse"] = struct{}{}
a["Seminar"] = struct{}{}
a["ThesisAdvising"] = struct{}{}
return a
}
var CourseTypeSet = makeCourseTypeSet()
type Course struct {
Key *Key
CourseType string
CourseNumber string
CourseTitle string
CourseDescription string
CourseOrganization *Organization
}
func NewCourse(nt string, nu string, nm string) (*Course,error) {
p := new(Course)
p.Key = makeKey("Course")
_, ok := CourseTypeSet[nt]
if ok {
p.CourseType = nt
p.CourseNumber = nu
p.CourseTitle = nm
return p, nil
} else {
err := errors.New("Unknown course type: " + nt)
return nil, err
}
}
func NewAcademicCourse(nu string, nm string) (*Course,error) {
p,e := NewCourse("AcademicCourse",nu,nm)
return p,e
}
func NewShortCourse(nu string, nm string) (*Course,error) {
p,e := NewCourse("ShortCourse",nu,nm)
return p,e
}
func NewSeminar(nu string, nm string) (*Course,error) {
p,e := NewCourse("Seminar",nu,nm)
return p,e
}
func NewThesisAdvising(nu string, nm string) (*Course,error) {
p,e := NewCourse("ThesisAdvising",nu,nm)
return p,e
}
func (a *Course) Triples () [][3]string {
var t [][3]string
t = append(t, makeTriple(Triple{(*a).Key,"hasType","Course",nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasCourseType",(*a).CourseType,nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasCourseNumber",(*a).CourseNumber,nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasCourseTitle",(*a).CourseTitle,nil}))
if (*a).CourseDescription != "" {t = append(t, makeTriple(Triple{(*a).Key,"hasCourseDescription",(*a).CourseDescription,nil}))}
if (*a).CourseOrganization != nil { t=append(t, makeTriple(Triple{(*a).Key,"hasCourseOrganization","",(*a.CourseOrganization).Key}))}
return t
}
func (a *Course) Row() []string {
var t []string
t = append(t, a.Key.s)
t = append(t, a.CourseType)
t = append(t, a.CourseNumber)
t = append(t, a.CourseTitle)
if a.CourseDescription != "" { t=append(t, a.CourseDescription) }
if a.CourseOrganization != nil { t=append(t, a.CourseOrganization.Key.s) }
return t
}
func FindCourseKey (kf *Key) int {
for i,a := range Courses {
if kf.s == a.Key.s {
return i
}
}
return -1
}
func AddCourseFact(a []string) {
key := new(Key)
key.s = a[0]
i := FindCourseKey(key)
switch a[1] {
case "CourseType":
Courses[i].CourseType = a[2]
case "CourseNumber":
Courses[i].CourseNumber = a[2]
case "CourseTitle":
Courses[i].CourseTitle = a[2]
case "CourseDescription":
Courses[i].CourseDescription = a[2]
case "CourseOrganization":
key.s = a[2]
j := FindOrganizationKey(key)
Courses[i].CourseOrganization = Organizations[j]
}
}
var Courses []*Course