-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
410 lines (373 loc) · 14.1 KB
/
index.html
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.parseXML demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body oncontextmenu="return false;">
<button id="loadXml">Load xml data</button>
<button id="loadTxt">Load txt data</button>
<button id="exportJson">Export JSON</button>
<button id="importJson">Import JSON</button>
<button id="showTransitionCounts">Show counts of transition states</button>
<button id="colorTfIdf">Show TfIdf</button>
<br/>
<br/>
<input id="teamNameInput" type="text" name="teamName" placeholder="team name">
<input id="phaseInput" type="text" name="phase" placeholder="phase">
<button id="exportCSV">Export CSV</button>
<br/>
<br/>
<input type="number" name="moveNumber" min="1" max="1" value="1">
<button id="hideMoves">Hide moves</button>
<button id="showMoves">Show all moves</button>
<a id="downloadAnchorElem" style="display:none"></a>
<div id="content"></div>
<script>
var d3Color = d3.scale.category10();
var bracketsRegExp = new RegExp('^\\(.*\\)$');
$("#exportJson").on("click", function() {
var sentenceArray = [];
$("#content p").each(function(i, paragraph) {
var sentenceObject = {};
var sentenceString = "";
var backCenters = [];
var referencedObjects = [];
var implicit = false;
var transition = $(paragraph).find("select")[0].value;
var moveRef = -1;
var moveNumber = $(paragraph).text().split("|")[0].trim() || -1;
$(paragraph).children(".word").each(function(i, word) {
var wordString = $(word).html();
var spanRegExp = new RegExp('<span .* </span>');
wordString = wordString.replace(spanRegExp,"");
sentenceString += wordString;
if ($(word).hasClass("center")){
backCenters.push(i);
if ($(word).hasClass("implicit")){
implicit = true;
if (this.className.match(new RegExp('moveRef.*')) !== null) {
moveRef = Number.parseInt(this.className.match(new RegExp('moveRef.*'))[0].replace("moveRef-",""));
}
}
}
if ($(word).hasClass("reference")){
referencedObjects.push(i);
}
})
sentenceObject.sentence = sentenceString.trim();
sentenceObject.backCenter = backCenters;
sentenceObject.referencedObject = referencedObjects;
sentenceObject.implicit = implicit;
sentenceObject.transition = transition;
sentenceObject.moveRef = moveRef;
sentenceObject.moveNumber = moveNumber;
sentenceArray.push(sentenceObject);
});
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(sentenceArray));
var dlAnchorElem = document.getElementById('downloadAnchorElem');
dlAnchorElem.setAttribute("href", dataStr );
dlAnchorElem.setAttribute("download", "export.json");
dlAnchorElem.click();
});
$("#exportCSV").on("click", function() {
var sentenceArray = [];
var teamName = $("#teamNameInput").val();
var phase = $("#phaseInput").val();
var paragraphs = $("#content p");
//var beginning = getBeginning(paragraphs);
//var end = getEnd(paragraphs);
var end = paragraphs[paragraphs.length-1].getAttribute("data-move-number");
for (var i = 1; i <= end; i++) {
var sentenceCSV = [];
var el = $('*[data-move-number="' + i + '"]');
var transition = "c_";
if (el.length > 0) {
transition = $('*[data-move-number="' + i + '"]').find("select")[0].value;
if (transition === "confirmation") {
transition = "y"
}
else {
transition = transition[0]
}
}
sentenceCSV.push( i );
sentenceCSV.push( teamName );
sentenceCSV.push( phase );
sentenceCSV.push( transition );
sentenceArray.push(sentenceCSV);
}
var csvContent = "data:text/csv;charset=utf-8,";
sentenceArray.forEach(function(infoArray, index){
dataString = infoArray.join(",");
csvContent += index < csvContent.length ? dataString+ "\n" : dataString;
});
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "export.csv");
link.click();
});
var getBeginning = function(paragraphs) {
for (var i = 0; i < paragraphs.length; i++) {
if ($(paragraphs[i]).find(".center").length !== 0 || $(paragraphs[i]).find(".reference").length !== 0) {
return i;
}
}
};
var getEnd = function(paragraphs) {
for (var i = paragraphs.length; i >= 0; i--) {
if ($(paragraphs[i]).find(".center").length !== 0 || $(paragraphs[i]).find(".reference").length !== 0) {
return i;
}
}
};
var addToPage = function(utterance, index) {
/*if (utterance.match(bracketsRegExp)) {
return;
}*/
var splitUtterance = utterance.split(/\s+/);
var elementString = "<p data-move-number=" + index + ">" + index + " | ";
elementString += '<select name="transition"> <option value="continuation">continuation</option> <option value="drift">drift</option> <option value="integration">integration</option> <option value="jump">jump</option> <option value="meta">meta</option> <option value="confirmation">confirmation</option> <option value="none">none</option> </select> ';
for (var i = 0; i < splitUtterance.length; i++) {
//if (!splitUtterance[i].match(bracketsRegExp)) {
elementString += "<span class='word'>" + splitUtterance[i] + " </span>";
//}
}
elementString += "</p>";
$("#content").append(elementString);
if (utterance.match(bracketsRegExp)) {
$("#content").children().last().find("select[name='transition']")[0].value="none";
}
}
$("#importJson").on("click", function(){
$("#content").empty();
$.get('export.json', function(array){
for (var j = 0; j < array.length; j++) {
var d = array[j];
/*if (d.sentence.match(bracketsRegExp)) {
return;
}*/
var splitUtterance = d.sentence.split(/\s+/);
var elementString = "<p data-move-number=" + d.moveNumber + ">" + d.moveNumber + " | ";
elementString += '<select name="transition"> <option value="continuation">continuation</option> <option value="drift">drift</option> <option value="integration">integration</option> <option value="jump">jump</option> <option value="meta">meta</option> <option value="confirmation">confirmation</option> <option value="none">none</option> </select> ';
if (d.moveRef !== -1) {
elementString += "<span class='moveArrow'> [=>" + d.moveRef + "] </span>";
}
for (var i = 0; i < splitUtterance.length; i++) {
//if (!splitUtterance[i].match(bracketsRegExp)) {
var classString = "";
var styleString = "";
var additionalString = "";
if (d.backCenter.indexOf(i) !== -1) {
if (d.implicit) {
if (d.moveRef != -1) {
classString += " moveRef-"+d.moveRef;
}
classString += " center implicit";
styleString += " color: blue;"
additionalString += '<span class="explicity implicit-yes"> i </span> <span class="close"> x </span>'
}
else {
classString += " center explicit";
styleString += " color: red;"
additionalString += '<span class="explicity explicity-yes"> e </span> <span class="close"> x </span>'
}
}
if (d.referencedObject.indexOf(i) !== -1) {
classString += " reference";
styleString += " text-decoration: underline;"
}
elementString += "<span class='word" + classString + " ' style=' " + styleString + "'>" + splitUtterance[i] + additionalString + " </span>";
//}
}
elementString += "</p>";
var appended = $("#content").append(elementString);
$("#content").children().last().find("select[name='transition']")[0].value=d.transition;
};
initMouseInteraction();
$(".close").on("mouseup", function(d) {
var word = $($(d.target)[0]).parent();
word.find(".close").remove();
word.find(".explicity").remove();
word.css("color","");
$(word[0]).removeClass("center explicit implicit");
})
});
});
$("#loadXml").on("click", function() {
loadXml();
});
$("#loadTxt").on("click", function() {
$("#content").empty();
$.get('import.txt', function(d){
d.split("\n").forEach(function(el, index, ary){
addToPage(el,index+1)
})
})
initMouseInteraction();
});
$("#colorTfIdf").on("click", function() {
colorTfIdfWords();
});
var loadXml = function() {
$("#content").empty();
$.get('Team_R_KeyEpisode_12_05_15_Day_3_Transcript.xml', function(d){
rows = $(d).find( "Row" );
for (var i = 1; i < rows.length; i++) {
var utteranceAlreadyFound = false;
cells = $(rows[i]).find("Cell");
// sometimes rows are misformed (e.g. have a gap) so we check every cell, if it has an element with index 4
for (var j = 0; j < cells.length; j++) {
if ( $(cells[j]).attr("ss:Index") == "4" && $($(cells[j]).children()[0]).attr("ss:Type") == "String") {
var utterance = $(cells[j]).children()[0].innerHTML;
addToPage(utterance, i);
utteranceAlreadyFound = true;
break;
}
}
// for normal rows we look for the starting index to figure out where the text is
if (!utteranceAlreadyFound) {
var utteranceIndex = 3;
if ( $(cells[0]).attr("ss:Index") != undefined ) {
utteranceIndex -= ($(cells[0]).attr("ss:Index") - 1);
}
if ($($(cells[utteranceIndex]).children()[0]).attr("ss:Type") == "String") {
var utterance = $(cells[utteranceIndex]).children()[0].innerHTML;
addToPage(utterance, i);
}
}
}
$("input[name='moveNumber']")[0].max = $("#content p:last").data("moveNumber");
});
initMouseInteraction();
}
function colorTfIdfWords() {
var ary = [ ["social","society","relationship"],["professionalism","strategies","ethics"],["dignity", "motivation"],["negative","positive","signals"],["pov","persona","insight","vision","assumption"],["streets","homeless","person","peer"]]
$("#content p").each(
function(){
$(this).children("span").each(
function(){
var that = this;
ary.forEach(function(element, index, array) {
element.forEach(function(el, i, ar) {
if (that.innerHTML.replace(/\./g," ").replace(/,/g," ").replace(/\?/g," ").replace(/!/g," ").trim() === el) {
$(that).css("color",d3Color(index))
$(that).css("font-weight","900")
}
})
})
})
})
}
var initMouseInteraction = function() {
$("#content").on("mousedown", ".word", function(e) {
var word = $(this);
// left mouse button -> center
if (e.button == 0) {
if (word.find(".explicity").length == 0) {
$(word[0]).css("color", "red");
$(word[0]).addClass("center explicit");
word.append("<span class='explicity explicit-yes'> e </span>");
word.find(".explicity").on("mouseup", function(d) {
if ($(this).hasClass("explicit-yes")) {
$(this).removeClass("explicit-yes");
$(this).addClass("implicit-yes");
$(this).html(" i ");
$(word[0]).css("color", "blue");
$(word[0]).addClass("implicit");
$(word[0]).removeClass("explicit");
var moveReference = prompt("Which move does the implicit center reference? (can be left empty)");
if (moveReference) {
$(word[0]).addClass("moveRef-"+moveReference);
$(word[0]).parent().find("select")[0].value = "integration";
$("<span class='moveArrow'> [=>" + moveReference + "] </span>").insertAfter($(word[0]).parent().find("select"));
}
else {
$(word[0]).parent().find("select")[0].value = "jump";
}
}
else {
$(this).removeClass("implicit-yes");
$(this).addClass("explicit-yes");
$(this).html(" e ");
$(word[0]).css("color", "red");
$(word[0]).removeClass("implicit");
$(word[0]).removeClass (function (index, css) {
return (css.match (new RegExp('moveRef.*')) || []).join(' ');
});
$(word[0]).addClass("explicit");
}
})
}
if (word.find(".close").length == 0) {
word.append("<span class='close'> x </span>");
word.find(".close").on("mouseup", function(d) {
word.find(".close").remove();
word.find(".explicity").remove();
word.css("color","");
$(word[0]).removeClass("center explicit implicit");
$(word[0]).removeClass (function (index, css) {
if (css.match (new RegExp('moveRef.*'))) {
$(word[0]).parent().find(".moveArrow").remove();
}
return (css.match (new RegExp('moveRef.*')) || []).join(' ');
});
})
}
}
// right mouse button -> referenced object
else if (e.button == 2) {
if ($(word[0]).css('text-decoration')==="underline") {
$(word[0]).css('text-decoration', '');
$(word[0]).removeClass("reference");
}
else {
$(word[0]).parent().find(".reference").each(function(i, d) {
$(d).removeClass("reference");
$(d).css('text-decoration', '');
})
$(word[0]).css('text-decoration', 'underline');
$(word[0]).addClass("reference");
var sentenceIndex = $($(word[0]).parent()[0]).index();
if (!$(word[0]).hasClass("center")) {
$($("#content").children()[sentenceIndex+1]).find("select")[0].value = "drift";
}
else {
$($("#content").children()[sentenceIndex+1]).find("select")[0].value = "continuation";
}
}
}
});
};
$("#hideMoves").on("click", function() {
$("#content p").each(function(i,d){
if (Number.parseInt(d.getAttribute("data-move-number")) < Number.parseInt($("input[name='moveNumber']")[0].value)) {
d.hidden = true;
}
});
});
$("#showMoves").on("click", function() {
$("#content p:hidden").each(function(i,d){
d.hidden = false;
});
});
$("#showTransitionCounts").on("click", function() {
var paragraphs = $("#content p");
var beginning = getBeginning(paragraphs);
var end = getEnd(paragraphs);
var transitionCounts = {};
for (var i = beginning; i <= end; i++) {
var transition = $(paragraphs[i]).find("select")[0].value;
if (!(transition in transitionCounts)) {
transitionCounts[transition] = 0;
}
transitionCounts[transition]++;
}
window.alert(JSON.stringify(transitionCounts));
});
</script>
</body>
</html>