-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexicon-grid.html
107 lines (107 loc) · 2.95 KB
/
lexicon-grid.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Nahaıwa lexicon</title>
<style type="text/css">
table {
border-collapse: collapse;
border: 1px solid black;
}
td {
border: 1px solid black;
padding: 3px;
}
</style>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.2/d3.js">
</script>
<script type="text/javascript">
function is_array(v) {
return Object.prototype.toString.call(v) === '[object Array]';
}
function is_undefined(v) {
return Object.prototype.toString.call(v) ===
'[object Undefined]';
}
g_lexicon = [];
</script>
</head>
<body>
<input
type="checkbox"
id="sorting_checkbox"
name="sorting_checkbox"
checked=false
onchange="proceed(g_lexicon);" />
<label for="sorting_checkbox">Sort by semantic category</label>
<br /><br />
<span id="lexemes_stats"></span>
<br /><br />
<div id="content">(LEXICON NOT YET LOADED!)</div>
<script type="text/javascript">
function with_escaped_html(text) {
return text.replace(/[&<>"']/g, function(ch) {
switch (ch) {
case '&': return '&';
case '<': return '<';
case '>': return '>';
case '"': return '"';
default: return ''';
/* ''' in another option in HTML5, but is absent from
HTML4. */
}
});
}
function compare(a, b) {
if(a === "") {
return 1;
} else if(b === "") {
return -1;
} else {
return a < b ? -1 : a > b ? 1 : 0;
}
}
function proceed(lexicon) {
shall_sort_by_semantic_tags =
document.getElementById("sorting_checkbox").checked;
lexicon = lexicon.sort((a, b) => {
if (shall_sort_by_semantic_tags)
return (
a.type.localeCompare(b.type)
|| compare(a.tags, b.tags)
|| compare(a.morpheme, b.morpheme))
else
return (
a.type.localeCompare(b.type)
|| compare(a.morpheme, b.morpheme))
});
s = "";
lexicon.forEach((e, i, l) => {
entries = [
e.morpheme, e.type, e.subtype, e.eng, e.tags, e.predilex_id];
entries = entries.map(
ε => "<td>" + with_escaped_html(ε) + "</td>\n");
s += "<tr>\n" + entries.join("") + "</tr>\n";
});
content =
"<table cellspacing='2px'>\n<thead>\n<td>Morpheme</td>" +
"<td>Type</td><td>Subtype</td><td>Meaning</td>" +
"<td>Tags</td><td>Predilex ID</td>\n</thead>\n<tbody>\n";
content += (s + "\n</tbody>\n</table>\n");
document.getElementById("content").innerHTML = content;
n_roots = lexicon.filter(e => e.type === "root").length;
n_extensions = lexicon.filter(e => e.type === "ext").length;
document.getElementById('lexemes_stats').innerHTML =
"Number of lexemes: " + (n_roots + n_extensions) +
" (" + n_roots + " bases, " + n_extensions +
" extensional prefixes).";
}
d3.tsv("lexicon.tsv", (tsv) => {
g_lexicon = tsv;
proceed(tsv);
});
</script>
</body>
</html>