-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcepts.go
68 lines (59 loc) · 1.38 KB
/
concepts.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
package entities
import (
"fmt"
)
var _ = fmt.Println // remove after test
type Concept struct {
Key *Key
Name string
Broader *Concept
Narrower *Concept
}
func NewConcept(d string) *Concept {
p := new(Concept)
p.Key = makeKey("Concept")
p.Name = d
return p
}
func (a *Concept) Triples () [][3]string {
var t [][3]string
t = append(t, makeTriple(Triple{(*a).Key,"hasType","Concept",nil}))
t = append(t, makeTriple(Triple{(*a).Key,"hasName",(*a).Name,nil}))
if (*a).Broader != nil { t=append(t, makeTriple(Triple{(*a).Key,"hasBroader","",(*a.Broader).Key}))}
if (*a).Narrower != nil { t=append(t, makeTriple(Triple{(*a).Key,"hasNarrower","",(*a.Narrower).Key}))}
return t
}
func (a *Concept) Row() []string {
var t []string
t = append(t, a.Key.s)
t = append(t, a.Name)
if (*a).Broader != nil { t=append(t, a.Broader.Key.s) }
if (*a).Narrower != nil { t=append(t, a.Narrower.Key.s) }
return t
}
func FindConceptKey (kf *Key) int {
for i,a := range Concepts {
if kf.s == a.Key.s {
return i
}
}
return -1
}
func AddConceptFact(a []string) {
key := new(Key)
key.s = a[0]
i := FindConceptKey(key)
switch a[1] {
case "Name":
Concepts[i].Name = a[2]
case "Broader":
key.s = a[2]
j := FindConceptKey(key)
Concepts[i].Broader = Concepts[j]
case "Narrower":
key.s = a[2]
j := FindConceptKey(key)
Concepts[i].Narrower = Concepts[j]
}
}
var Concepts []*Concept