-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyper.go
57 lines (48 loc) · 1023 Bytes
/
hyper.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
package main
import(
"fmt"
)
type Node struct {
label string
neighbors []*Node
}
// Just for fmt.printf :)
func (n *Node) String() string {
return n.label
}
// If the Node is a Part Of Speech
type PartOfSpeech interface {
Label() string
Arity() int
}
func (n *Node) Label() string {
return n.label
}
func (n *Node) Arity() int {
return len(n.neighbors)
}
// If it's a term
type Term interface {
Label() string
Definition() string
}
func (n *Node) Definition() string {
def := ""
if len(n.neighbors) == 0 {
def = "Null"
} else {
for _, neighbor := range n.neighbors {
def += neighbor.Label()
def += " "
}
}
return def
}
// Noodle around with them
func main() {
node1 := &Node{ label: "foo" }
node2 := &Node{ label: "bar" }
node3 := &Node{ label: "baz", neighbors: []*Node{node1,node2} }
fmt.Printf("Node 1: %s\tDefinition: %s\t Arity: %d\n", node1, node1.Definition(), node1.Arity())
fmt.Printf("Node 3: %s\tDefinition: %s\t Arity: %d\n", node3, node3.Definition(), node3.Arity())
}