forked from situx/SemanticDictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuneistrokestats.html
145 lines (135 loc) · 5.28 KB
/
cuneistrokestats.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
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
<script src="js/paleocode.js"></script>
<script>
var edges=[]
var nodes=[]
var nodemap=[]
var graphml=""
function levenshteinDistance (s, t) {
if (!s.length) return t.length;
if (!t.length) return s.length;
return Math.min(
levenshteinDistance(s.substr(1), t) + 1,
levenshteinDistance(t.substr(1), s) + 1,
levenshteinDistance(s.substr(1), t.substr(1)) + (s[0] !== t[0] ? 1 : 0)
) + 1;
}
function editdistancegraph(){
var remembermap={}
var i=1;
for(let js of paleocode){
alert(i)
alert(JSON.stringify(remembermap))
i++;
for(let js2 of paleocode){
if(!(js2["paleocode"] in remembermap)){
remembermap[js["paleocode"]]=js2["paleocode"]
//remembermap[js2["paleocode"]]=js["paleocode"]
var lev = levenshteinDistance(js["paleocode"], js2["paleocode"]);
console.log(js["paleocode"]+" - "+js2["paleocode"]+" - "+lev)
//console.log("[ "+js["paleocode"]+" ] is in [ "+js2["paleocode"]+" ]");
nodemap[js["paleocode"]]=js["translit"]+"("+js["cunei"]+")\n"+js["paleocode"]
nodemap[js2["paleocode"]]=js2["translit"]+"("+js2["cunei"]+")\n"+js2["paleocode"]
edges.push({from:js["paleocode"], to:js2["paleocode"],label:lev})
//}
}
}
for(var node in nodemap){
nodes.push({id: node, label: nodemap[node]})
}
}}
function graphToGraphML(){
graphml='<?xml version="1.0" encoding="UTF-8"?>\n<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">\n<key id="d0" for="node" yfiles.type="nodegraphics"/><key id="d1" for="edge" yfiles.type="edgegraphics"/> <graph id="G" edgedefault="undirected">\n'
for(var node in nodes){
console.log(node)
graphml+="<node id=\""+nodes[node]["id"].trim()+"\"/>\n"
}
for(var edge in edges){
console.log(edge)
graphml+="<edge id=\"e"+edge+"\" from=\""+edges[edge]["from"].trim()+"\" to=\""+edges[edge]["to"].trim()+"\"/>\n"
}
graphml+="</graph>\n</graphml>"
}
function substringgraph(){
var similar={}
//´graph.addLink(1, 2);
for(let js of paleocode){
for(let js2 of paleocode){
if(js2["paleocode"]!=js["paleocode"] && js2["paleocode"].includes(js["paleocode"])){
//console.log("[ "+js["paleocode"]+" ] is in [ "+js2["paleocode"]+" ]");
if(similar[js["paleocode"]]==undefined){
similar[js["paleocode"]]=""
}
similar[js["paleocode"]]+=js2["cunei"]+" "
if(similar[js["paleocode"]]!=undefined){
nodemap[js["paleocode"]]=js["translit"]+"("+js["cunei"]+")\n"+js["paleocode"]+"\n["+similar[js["paleocode"]]+"]"
}else{
nodemap[js["paleocode"]]=js["translit"]+"("+js["cunei"]+")\n"+js["paleocode"]
}
if(similar[js2["paleocode"]]!=undefined){
nodemap[js2["paleocode"]]=js2["translit"]+"("+js2["cunei"]+")\n"+js2["paleocode"]+"\n["+similar[js2["paleocode"]]+"]"
}else{
nodemap[js2["paleocode"]]=js2["translit"]+"("+js2["cunei"]+")\n"+js2["paleocode"]
}
edges.push({from:js["paleocode"], to:js2["paleocode"]})
/*graph.addNode(js["paleocode"],js["translit"])
graph.addNode(js2["paleocode"],js2["translit"])
graph.addLink(js["paleocode"],js2["paleocode"])*/
}
}
}
for(var node in nodemap){
nodes.push({id: node, label: nodemap[node]})
}
graphToGraphML()
}
function exportGraphML(){
saveTextAsFile(graphml,"graphml","export");
}
function saveTextAsFile(tosave,fileext,filename)
{
var a = document.createElement('a');
a.style = "display: none";
var blob= new Blob([tosave], {type:'text/plain'});
var url = window.URL.createObjectURL(blob);
var filename = filename+fileext;
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function(){
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 1000);
}
</script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css">
</head>
<body>
<div id="mynetwork"></div>
<script>
$(function() {
substringgraph();
//editdistancegraph();
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = { physics:false,interaction:{dragNodes:true,hover:true,navigationButtons: true, keyboard: {
enabled: true,
bindToWindow: false
},
navigationButtons: true,zoomView:true}, layout: { improvedLayout:true,hierarchical:{enabled:true, levelSeparation:50, nodeSpacing:300,sortMethod:"hubsize",direction:"UD",edgeMinimization:true,parentCentralization:true,blockShifting:true}}};
var network = new vis.Network(container, data, options);
});
</script>
<button id="exportGraphML" onClick="exportGraphML()">Export GraphML</button>
</body>
</html>