-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexicon.html
156 lines (155 loc) · 4.66 KB
/
lexicon.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
<!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_ext_lexicon = [];
g_base_lexicon = [];
</script>
</head>
<body>
<span id="lexemes_stats"></span>
<br />
<h4>Lexical entry template:</h4>
<span style="margin-left: 3em;">
<b style='color: #002255;'>lemma</b>
<span style='color: #552200'>[type]</span>
<span style='color: #225500; font-size: 85%;'>⟨semantic category⟩</span>
<span style='color: #223366'>➤</span> English definition
</span>
<br /><br />
<form class="filter_form">
<input type="text" placeholder="" id="filter" style="font-size: 16px; width: 16em;">
<button type="button" style="font-size: 16px;" onclick="proceed(g_prt_lexicon, g_ext_lexicon, g_base_lexicon);">Filter</button>
</form>
<br />
<input
type="checkbox"
id="sorting_checkbox"
name="sorting_checkbox"
checked=false
onchange="proceed(g_prt_lexicon, g_ext_lexicon, g_base_lexicon);" />
<label for="sorting_checkbox">Sort by semantic category</label>
<br /><br />
<div id="content">(LEXICON NOT YET LOADED!)</div>
<br /><br />
<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(prts, exts, bases) {
shall_sort_by_semantic_tags =
document.getElementById("sorting_checkbox").checked;
sorted = (l) => l.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))
});
filter_text = document.getElementById("filter").value;
filter_func = (e) => e.morpheme.includes(filter_text) || e.eng.includes(filter_text);
prts = sorted(prts.filter(filter_func));
exts = sorted(exts.filter(filter_func));
bases = sorted(bases.filter(filter_func));
function f(l) {
s = "";
l.forEach((e, i, l) => {
switch (e.type) {
case "prt":
type = "Prt";
morpheme = e.morpheme;
break;
case "root":
type = "V";
morpheme = "-" + e.morpheme;
break;
case "ext":
type = "Ext";
morpheme = e.morpheme + "-";
break;
default: type = "?"; break;
}
tags = e.tags == "" ?
"" : "⟨" + with_escaped_html(e.tags) + "⟩ ";
s += "<b style='color: #002255'>"
+ with_escaped_html(morpheme) +"</b> "
+ "<span style='color: #552200'>["
+ with_escaped_html(type) + "<sup>"
+ with_escaped_html(e.subtype) + "</sup>]</span> "
+ "<span style='color: #225500; font-size: 85%;'>"
+ with_escaped_html(tags) + "</span> "
+ "<span style='color: #223366'>➤</span> "
+ with_escaped_html(e.eng) +"<br/>";
});
return s;
}
ps = f(prts);
es = f(exts);
bs = f(bases);
content = "<h2>Particles</h2><hr/><br/>\n" + ps
+ "<h2>Extensional prefixes</h2><hr/><br/>\n" + es
+ "<br/><br/>\n<h2>Lexical bases</h2><hr/><br/>\n"
+ bs + "\n";
document.getElementById("content").innerHTML = content;
document.getElementById('lexemes_stats').innerHTML =
"Number of lexemes: "
+ (prts.length + exts.length + bases.length)
+ " (" + prts.length + " particles, "
+ bases.length + " bases, " + exts.length
+ " extensional prefixes).";
}
d3.tsv("lexicon.tsv", (tsv) => {
g_prt_lexicon = tsv.filter(e => e.type === "prt");
g_ext_lexicon = tsv.filter(e => e.type === "ext");
g_base_lexicon = tsv.filter(e => e.type === "root");
proceed(g_prt_lexicon, g_ext_lexicon, g_base_lexicon);
});
</script>
</body>
</html>