-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
434 lines (370 loc) · 18 KB
/
index.html
File metadata and controls
434 lines (370 loc) · 18 KB
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<!DOCUMENT html>
<html>
<head>
<meta charse="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Graph Language Analyzer - Wojciech Kasperski</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="container">
<div class="jumbotron">
<div class="container">
<h1 class="display-3">Graph Language Analyzer</h1>
<p class="lead">Developed by Wojciech Kasperski <a href="mailto:wojciech.kaserski97@gmail.com"><wojciech.kasperski97@gmail.com></a></p>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12">
<div class="alert alert-primary" role="alert">
<h5><b>Instruction:</b></h5>
<p>Enter some text below to make a graph of language. When you click on "Click to Analyze!" your text will be automatically cleared form any special chars. If you want analyze text with special chars or language like morse alphabet choose
second option.</p>
</div>
</div>
<div class="col-12">
<form id="analyzingText">
<div class="form-group">
<label for="toAnalyze">Enter language text for analyze below</label>
<textarea class="form-control" id="toAnalyze" rows="4"></textarea>
<button id="analyzeIt" class="btn btn-dark m-2">Click to Analyze!</button>
<button id="analyzeCrap" class="btn btn-dark m-2">Click to Analyze Without Input Cleaning!</button>
</div>
</form>
</div>
<div class="col-12">
<div id="cy"></div>
</div>
<div class="col-12">
<form id="analyzeSylabs">
<div class="form-group">
<label for="analyzeSylabsTextbox">Input just two chars to search for sylab:</label>
<textarea class="form-control" id="analyzeSylabsTextbox" rows="1"></textarea>
<button id="analyzeEnteredSylabs" class="btn btn-dark m-2">Click to search for sylabs!</button>
<button id="analyzeEnteredSylabsSpecial" class="btn btn-dark m-2">Click to search for sylabs based on special chars (for ex. if you are using Morse Alphabet)!</button>
</div>
</form>
</div>
<div class="col-12 mt-3">
<div class="alert alert-primary" role="alert">
<h5><b>Legend:</b></h5>
<img src="assets/img/start.png" class="height-50"> - a start point, which connects all first letters of words,<br>
<img src="assets/img/begin.png" class="height-50 width-36"> - first letter of word,<br>
<img src="assets/img/node.png" class="height-50 width-36"> - letter of the word on which word can't end,<br>
<img src="assets/img/end.png" class="height-50 width-36"> - letter of the word where reading can end. When it's connected to start it means that your grammar has single chars also. In short it can start and end on that node in some
cases.
<br>
</div>
</div>
</div>
</div>
<script sync>
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
function cleanInput(text) { //--- Cleanse Input Data
text = text.replace(/[&\/\\#,+()$~%.'":|!@;*?<>{}\-\.]/g, '').toLowerCase();
text = text.replace(/\ {2,}/g, " ");
text = text.replace(/\n/g, " ");
return text;
}
function generateGraph(cy, text) {
var data = text.split(" ");
data.forEach(function(word, index, arr) {
if (word === "" || word == " ")
arr.splice(index, 1);
});
data = data.filter(onlyUnique);
data.forEach(function(word, index, arr) {
arr[index] = word.split('')
});
//console.log(data);
//--- Generate Graph
cy.elements().remove();
var previous = {
letter: '$',
l_index: '$',
index: '$',
check: false
};
var check = false;
var firstLetter = true;
var filtering_saves = new Array();
cy.add({
group: 'nodes',
data: {
id: "start",
tag: "start"
}
})
data.forEach(function(word, index, arr) {
previousRepeat = true;
filtering_saves = new Array();
word.forEach(function(letter, l_index, letters) {
if (l_index > 0)
var filtered = cy.$('node[tag = "' + letter + '"][l_index = ' + l_index + '][start = "' + letters[0] + '"][left = "' + letters[l_index - 1] + '"]')
else
var filtered = cy.$('node[tag = "' + letter + '"][l_index = ' + l_index + '][start = "' + letters[0] + '"]')
var filtering_saves_new = new Array();
var end = new Boolean;
//console.log("How long: " + letters.length + " " + l_index);
l_index == letters.length - 1 ? end = 1 : end = 0;
//console.log("END:" + end)
//Checking if searched node exist and adding nodes to searched
if (filtered[0] != undefined && l_index != 0 && previousRepeat) {
filtered.forEach(function(element, i, collected) {
filtering_saves_new.push(element);
//console.log(element.data('id') + " " + element.data('index'));
});
// var same = new Array();
// for (var i = 0; i < filtering_saves.length; i++) {
// var item1 = filtering_saves[i],
// found = false;
// for (var j = 0; j < filtering_saves_new.length && ! found; j++) {
// found = (item1.data('index') === filtering_saves_new[j].data('index') && item1.data('tag') === filtering_saves_new[j].data('left'));
// }
// if (found === true) { // isUnion is coerced to boolean
// same.push(item1);
// }
// }
//filtering_saves = same;
// console.log("Same");
// console.log(same);
//console.log("Data:" ,filtering_saves_new, filtering_saves)
//Edge value incrementation
var inc_edge = cy.edges('[id = "' +
filtering_saves[0].data('tag') +
"_" + letter +
"_" + filtering_saves_new[0].data('index') +
"_" + l_index +
'"]');
if (inc_edge[0] != undefined) {
var data_value = inc_edge[0].data('tag');
inc_edge[0].data('tag', data_value + 1);
}
//console.log(inc_edge);
filtering_saves = filtering_saves_new;
} else if (filtered[0] != undefined && l_index == 0 && previousRepeat) {
filtered.forEach(function(element, i, collected) {
filtering_saves_new.push(element);
});
filtering_saves = filtering_saves_new;
//Edge value incrementation
var inc_edge = cy.edges('[id = "' + letter + '_start"]');
var data_value = inc_edge[0].data('tag');
inc_edge[0].data('tag', data_value + 1);
//console.log(inc_edge);
} else {
filtering_saves = [];
previousRepeat = false;
}
if (check = filtered.length != cy.collection().length &&
previousRepeat == true) {
previous.letter = filtering_saves[0].data('tag')
previous.l_index = filtering_saves[0].data('l_index')
previous.index = filtering_saves[0].data('index')
previous.check = check
//console.log("Previous", previous)
if (end == 1) filtering_saves[0].data('end', 1);
} else {
previousRepeat = false;
cy.add({
group: 'nodes',
data: {
id: letter + '_' + index + '_' + l_index,
tag: letter,
l_index: l_index,
index: index,
left: previous.letter,
right: letter,
start: letters[0],
end: end,
search: 0
}
});
if (l_index > 0) {
//console.log("Edge: ", previous, { letter, l_index, index, check })
cy.add({
group: 'edges',
data: {
id: previous.letter + '_' + letter +
'_' + index + '_' + l_index,
left: previous.letter,
right: letter,
tag: 1,
source: previous.letter + '_' +
previous.index +
'_' + previous.l_index,
target: letter + '_' + index + '_' +
l_index,
search: 0
}
});
} else if (l_index == 0) {
cy.add({
group: 'edges',
data: {
id: letter + "_start",
left: "start",
right: letter,
tag: 1,
source: "start",
target: letter + '_' + index + '_' +
l_index,
search: 0
}
});
}
previous = {
letter,
l_index,
index,
check
};
}
});
});
cy.layout({
//name: 'cose'
name: 'cose-bilkent'
//name: 'grid'
//name: 'breadthfirst', avoidOverlap: true,
//name: 'concentric'
//name: 'random'
}).run();
}
function searchSubGraphSylabs(cy, text) {
if (text.length > 0)
var serached = cy.nodes('[tag = "' + text[0] + '"]');
//console.log(serached);
serached.forEach(function(ele, i, eles) {
second = ele.neighborhood('[tag = "' + text[1] + '"][left = "' + text[0] + '"][l_index = ' + (ele.data('l_index') + 1) + ']');
//console.log(second);
if (second.length > 0) {
second.forEach(function(ele1, i1, eles1) {
console.log(ele, ele1);
//Changing first and second element
ele.data('search', 1);
ele1.data('search', 1);
search_edge = ele.edgesWith(ele1);
search_edge.data('search', 1);
//console.log(search_edge);
});
}
});
}
$(function() {
var cy = cytoscape({
container: document.getElementById('cy'),
wheelSensitivity: 1,
style: [{
selector: 'node',
style: {
shape: 'ellipse',
'background-color': 'grey',
label: 'data(tag)'
}
}, {
selector: 'edge',
style: {
'label': 'data(tag)', // maps to data.label
'line-color': 'aqua',
'width': 2,
'curve-style': 'bezier',
'target-arrow-shape': 'vee',
'target-arrow-color': 'aqua'
}
}, {
selector: "node[l_index = 0]",
style: {
shape: 'hexagon',
'background-color': 'red',
label: 'data(tag)'
}
}, {
selector: "node[end = 1]",
style: {
shape: 'tag',
'background-color': 'blue',
label: 'data(tag)'
}
}, {
selector: 'node[id = "start"]',
style: {
shape: 'star',
'background-color': 'green',
label: 'data(tag)'
}
}, {
selector: 'node[search = 1]',
style: {
'background-color': 'black',
}
}, {
selector: 'edge[search = 1]',
style: {
'line-color': 'purple',
'target-arrow-color': 'purple'
}
}]
});
//cy.layout({name: 'cose'}).run();
$("form").submit(function(e) {
e.preventDefault();
});
$("#analyzeIt").on("click", function() {
var text = $("#toAnalyze").val();
//--- Cleaning Data
text = cleanInput(text);
generateGraph(cy, text);
//comment this - it's auto search for "sd"
//var searchFor = "sd";
//searchSubGraphSylabs(cy, searchFor);
});
$("#analyzeCrap").on("click", function() {
var text = $("#toAnalyze").val();
//--- Cleaning Data
generateGraph(cy, text);
});
$("#analyzeEnteredSylabs").on("click", function() {
var text = $("#analyzeSylabsTextbox").val();
//----------------------------------------START Refreshing to fecator
var ref = $("#toAnalyze").val();
//--- Cleaning Data
ref = cleanInput(ref);
generateGraph(cy, ref);
//----------------------------------------END Refreshing to fecator
//--- Cleaning Data
searchFor = cleanInput(text);
searchSubGraphSylabs(cy, searchFor);
});
$("#analyzeEnteredSylabsSpecial").on("click", function() {
var text = $("#analyzeSylabsTextbox").val();
//----------------------------------------START Refreshing to fecator
var ref = $("#toAnalyze").val();
generateGraph(cy, ref);
//----------------------------------------END Refreshing to fecator
//--- Cleaning Data
searchFor = cleanInput(text);
searchSubGraphSylabs(cy, searchFor);
});
cy.on('tap', function(event) {
// target holds a reference to the originator
// of the event (core or element)
var evtTarget = event.target;
console.log("Clicked:", evtTarget);
});
});
</script>
<script type="text/javascript" src="assets/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/cytoscape.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cytoscape-cose-bilkent@4.0.0/cytoscape-cose-bilkent.min.js"></script>
<script type="text/javascript" scr="/assets/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.bundle.min.js.map"></script>
<script type="text/javascript" src="/assets/js/bootstrap.min.js.map"></script>
</body>
</html>