-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebate_map_node.go
198 lines (168 loc) · 7.45 KB
/
debate_map_node.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package main
import (
"time"
"github.com/google/uuid"
)
const NODE_TYPE_CATEGORY int = 10
const NODE_TYPE_PACKAGE int = 20
const NODE_TYPE_QUESTION = 30
const NODE_TYPE_CLAIM int = 40
const NODE_TYPE_ARGUMENT int = 50
const ARGUMENT_POLARITY_PRO int = 10
const ARGUMENT_POLARITY_CON int = 20
const ARGUMENT_TYPE_ANY int = 10
const ARGUMENT_TYPE_ANY_TWO int = 15
const ARGUMENT_TYPE_ALL int = 20
type DebateMapRoot struct {
Maps []DebateMapMap `json:"maps"`
Nodes []DebateMapNode `json:"nodes"`
NodeRevisions []NodeRevision `json:"nodeRevisions"`
}
type DebateMapNode struct {
ID string `json:"_key"`
CreatedAt int64 `json:"createdAt"`
Creator string `json:"creator"`
Type int `json:"type"`
CurrentRevision string `json:"currentRevision"`
Current Current `json:"current"`
Note string `json:"note"`
Polarity int `json:"polarity"`
MultiPremise bool `json:"multiPremiseArgument"`
Parents map[string]interface{} `json:"parents"`
Children map[string]interface{} `json:"children"`
ChildrenOrder []string `json:"childrenOrder"`
}
type DebateMapMap struct {
ID string `json:"_key"`
CreatedAt int64 `json:"createdAt"`
Creator string `json:"creator"`
Type int `json:"type"`
Name string `json:"name"`
RootNode string `json:"rootNode"`
}
func (node DebateMapNode) CreatedTime() time.Time {
return time.Unix(0, node.CreatedAt*1000000)
}
func (node DebateMapNode) IsPro() bool {
return node.Polarity == ARGUMENT_POLARITY_PRO
}
func (node DebateMapNode) ChildOrder(childId string) int {
for i, id := range node.ChildrenOrder {
if childId == id {
return i + 1
}
}
return 0
}
// Creates a new MP Claim node,
// And changes current node to point to it as its base claim
func (node DebateMapNode) ConvertToMPClaim() (newArg, newClaim DebateMapNode) {
argChildren := map[string]interface{}{}
claimChildren := map[string]interface{}{}
for key, childInt := range node.Children {
if child := NewChildFromData(key, childInt); child != nil {
if child.Polarity > 0 {
argChildren[child.ID] = *child
} else {
claimChildren[child.ID] = *child
}
}
}
newArg = DebateMapNode{
ID: node.ID,
CreatedAt: node.CreatedAt,
Creator: node.Creator,
Type: NODE_TYPE_ARGUMENT,
Polarity: node.Polarity,
MultiPremise: false,
Parents: node.Parents,
Children: argChildren,
}
newClaim = DebateMapNode{
ID: uuid.New().String(),
CreatedAt: node.CreatedAt,
Creator: node.Creator,
Type: NODE_TYPE_CLAIM,
Current: node.Current,
Note: node.Note,
Parents: map[string]interface{}{newArg.ID: newArg},
Children: claimChildren,
MultiPremise: true,
ChildrenOrder: node.ChildrenOrder,
}
newArg.Children[newClaim.ID] = Child{ID: newClaim.ID}
return
}
// Converts one of the other node types to a Claim and an Argument to preserve the structure in the CD
// If the node is a root node, then the "argument" will be nil
func (node DebateMapNode) ConvertToClaimAndArg() (newArg *DebateMapNode, newClaim DebateMapNode) {
newClaim = DebateMapNode{
ID: uuid.New().String(),
CreatedAt: node.CreatedAt,
Creator: node.Creator,
Type: NODE_TYPE_CLAIM,
Current: node.Current,
Note: node.Note,
Parents: node.Parents,
Children: node.Children,
MultiPremise: false,
ChildrenOrder: node.ChildrenOrder,
}
if len(node.Parents) > 0 {
newArg = &DebateMapNode{
ID: node.ID,
CreatedAt: node.CreatedAt,
Creator: node.Creator,
Type: NODE_TYPE_ARGUMENT,
Polarity: ARGUMENT_POLARITY_PRO,
MultiPremise: false,
Parents: node.Parents,
Children: map[string]interface{}{},
}
newClaim.Parents = map[string]interface{}{newArg.ID: newArg}
newArg.Children[newClaim.ID] = Child{ID: newClaim.ID}
}
return
}
type Current struct {
ID string `json:"node"`
Title TitleSet `json:"titles"`
ArgumentType int `json:"argumentType"`
}
type NodeRevision struct {
ID string `json:"_key"`
Title TitleSet `json:"titles"`
}
type TitleSet struct {
Base string `json:"base"`
Negation string `json:"negation"`
Question string `json:"yesNoQuestion"`
}
type Child struct {
ID string `json:"_key"`
Polarity int `json:"polarity"`
}
func (child Child) IsPro() bool {
return child.Polarity == ARGUMENT_POLARITY_PRO
}
func NewChildFromData(key string, data interface{}) *Child {
if m, ok := data.(map[string]interface{}); ok {
child := Child{ID: key}
if polarity, kk := m["polarity"].(float64); kk {
child.Polarity = int(polarity)
}
return &child
} else if ch, ok := data.(Child); ok {
return &ch
}
return nil
}
/* Claim
+map[_key:zsrQ9ZRGSg2y1QDg0y_Xxg children:map[Kp8pR1UyRpC-5SI6sdd_VA:map[_:true _key:Kp8pR1UyRpC-5SI6sdd_VA polarity:10] _key:children] createdAt:1.542072143141e+12 creator:fG4HB6nP5baRQwZZ6BjrLuSOjjD2 current:map[_key:8RJXTx1ZT0yrnAp_bZqzJw accessLevel:10 createdAt:1.542072143305e+12 creator:fG4HB6nP5baRQwZZ6BjrLuSOjjD2 node:zsrQ9ZRGSg2y1QDg0y_Xxg titles:map[_key:titles allTerms:map[_key:allTerms change:true climate:true far:true fighting:true has:true impact:true in:true investment:true little:true roi:true shown:true so:true the:true very:true] base:The investment in fighting climate change so far has shown very little impact (ROI).]] currentRevision:8RJXTx1ZT0yrnAp_bZqzJw parents:map[_key:parents wvwbFY_1Rx2qqEL819X0aw:true] type:40]
*/
/* Multi-premise Argument
{"children":{"1Pl8F_cmT-W84XrF1rvgaA":{"_":true,"form":10,"_key":"1Pl8F_cmT-W84XrF1rvgaA"},"wTVYg4c-QLmI7QjLjcjckw":{"_":true,"_key":"wTVYg4c-QLmI7QjLjcjckw"},"_key":"children"},"childrenOrder":["wTVYg4c-QLmI7QjLjcjckw","1Pl8F_cmT-W84XrF1rvgaA"],"createdAt":1551183882923,"creator":"fG4HB6nP5baRQwZZ6BjrLuSOjjD2","currentRevision":"zSGFJw44Sm2M6zFNP8ti2g","multiPremiseArgument":true,"parents":{"kwsLLiNFSTmbokQ1_nO-bA":{"_":true,"_key":"kwsLLiNFSTmbokQ1_nO-bA"},"_key":"parents"},"type":50,"_key":"Ikan0wFzSXm7GYSPvglJ3A","current":{"accessLevel":10,"argumentType":20,"createdAt":1551386119594,"creator":"fG4HB6nP5baRQwZZ6BjrLuSOjjD2","node":"Ikan0wFzSXm7GYSPvglJ3A","titles":{"allTerms":{"a":true,"brasil":true,"deveria":true,"dos":true,"esperar":true,"executivo":true,"fazer":true,"governo":true,"militares":true,"n":true,"o":true,"object":true,"para":true,"protecionista":true,"quando":true,"reforma":true,"respeito":true,"tiver":true,"um":true,"_key":"allTerms"},"base":"O Brasil deveria esperar para fazer a reforma para quando não tiver um governo executivo protecionista a respeito dos militares.","_key":"titles"},"_key":"zSGFJw44Sm2M6zFNP8ti2g"}}
*/
/* Argument
{"children":{"0IuVkaiSSqeDIUYoqJmHgg":{"_":true,"_key":"0IuVkaiSSqeDIUYoqJmHgg"},"_key":"children"},"childrenOrder":["0IuVkaiSSqeDIUYoqJmHgg"],"createdAt":1552339936133,"creator":"VoJg7aKCtgWj3SR4Ailk4VWxcYv2","currentRevision":"lVt1SFoiQTCjXl6_adEy0Q","parents":{"unqeHLthRwuFuVrwP3PeRQ":{"_":true,"_key":"unqeHLthRwuFuVrwP3PeRQ"},"_key":"parents"},"type":50,"_key":"m5TYIVrtQqicm0AsuEnn7Q","current":{"accessLevel":10,"argumentType":20,"createdAt":1552339936134,"creator":"VoJg7aKCtgWj3SR4Ailk4VWxcYv2","node":"m5TYIVrtQqicm0AsuEnn7Q","titles":{"allTerms":{"_key":"allTerms"},"base":"","_key":"titles"},"_key":"lVt1SFoiQTCjXl6_adEy0Q"}}
*/