-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathword.php
297 lines (246 loc) · 11.6 KB
/
word.php
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
<?php
/*
* Author: Edwin Ko eddersko.com
* This script is free software.
*/
$_SESSION['word']= $_GET[ 'word'];
$word= $_SESSION['word'];
$xmlDoc= new DOMDocument();
$xmlDoc->load("dictionary.xml");
$xpath = new DOMXPath($xmlDoc);
if ($_GET['lang'] == "source") {
$result = $xpath->query("/dictionary/entry/form[orth=\"$word\"]/..");
} else {
$result = $xpath->query("/dictionary/entry/sense/cit[usg=\"".$word."\"]/../..");
}
$table = "";
// for each entry, get relevant fields to display
// you may adjust to add/remove fields to display
foreach($result as $entry) {
$id = $entry->getAttribute('id');
$hyper = $entry->childNodes->item(3)->childNodes->item(1)->childNodes->item(1)->nodeValue;
$source = $entry->childNodes->item(1)->childNodes->item(1)->nodeValue;
$eng = $entry->childNodes->item(3)->childNodes->item(1)->childNodes->item(3)->nodeValue;
$pos = $entry->childNodes->item(5)->childNodes->item(1)->nodeValue;
$note = $entry->childNodes->item(7)->nodeValue;
$media = $entry->childNodes->item(9)->getAttribute('url');
// This is where you add annotation layers.
// $extraAnno1 = $entry->childNodes->item(13)->nodeValue;
// $extraAnno2 = $entry->childNodes->item(15)->nodeValue;
// $extraAnno3 = $entry->childNodes->item(17)->nodeValue;
// $extraAnno4 = $entry->childNodes->item(19)->nodeValue;
// $extraAnno5 = $entry->childNodes->item(21)->nodeValue;
$count = 0;
$examples = "";
// check polysemy/homophony
$polysemy = $xpath->query("/dictionary/entry/form[orth='$source']/..")->length;
// varying length due to diacritics/special characters
// PHP cannot count some diacritics/special characters
$lenA = strlen($source);
$lenB = strlen($source) - 1;
$lenC = strlen($source) - 2;
$xmlDoc = new DOMDocument();
$xmlDoc->load("../phrasicon/phrasicon.xml");
$xpath = new DOMXPath($xmlDoc);
// if polysemous/homophonous
if ($polysemy > 1) {
$p = false;
$e = false;
$count += $xpath->query("//phrase[starts-with(source, '".$source." ')]")->length;
$count += $xpath->query("//phrase[contains(source, ' ".$source." ')]")->length;
$count += $xpath->query("//phrase[(substring(source, string-length(translation) - $lenA) = '".$source."')]")->length;
$count += $xpath->query("//morpheme[m='".$source."']")->length;
// if phrasicon contains source word
if ($count > 0) {
$p = true;
}
$count = 0;
$count += $xpath->query("(//gloss[g='$hyper'])")->length;
// if phrasicon contains hyper
if ($count > 0) {
$e = true;
}
// if both phrasicon contains both source word and hypernym, set up to provide linkage
if ($p and $e) {
$count = 1;
} else {
$count = 0;
}
// if not polysemous/homophonous
} else {
$count += $xpath->query('//phrase[starts-with(source, "'.$source.' ")]')->length;
$count += $xpath->query('//phrase[contains(source, " '.$source.' ")]')->length;
$count += $xpath->query('//phrase[(substring(source, string-length(source) - '.$lenA.') = " '.$source.'")]')->length;
$count += $xpath->query('//phrase[(substring(source, string-length(source) - '.$lenB.') = " '.$source.'")]')->length;
$count += $xpath->query('//phrase[(substring(source, string-length(source) - '.$lenC.') = " '.$source.'")]')->length;
$count += $xpath->query('//morpheme[m="'.$source.'"]')->length;
}
// if the entry headword appears in phrasicon, provide a link
if ($count > 0) {
if ($polysemy > 1) {
$examples .= "<tr><td colspan=\"2\"><center><a href=\"../phrasicon/word.php?word=" . $source . "&eng=" . $eng . "&lang=poly\">Example phrases (phrasicon)</a></center></td></tr>";
} else {
$examples .= "<tr><td colspan=\"2\"><center><a href=\"../phrasicon/word.php?word=" . $source . "&lang=source\">Example phrases (phrasicon)</a></center></td></tr>";
}
}
$table = $table . "<a name=\"" . $id . "\"><table align=\"center\" width=\"300px\"><tr><td class=\"english\" colspan=\"2\"><center>" . $eng . "</center></td></tr>";
// This is where you add annotation layers.
// $table = $table . "<tr><td class=\"english\" colspan=\"2\"><center>" . $extraAnno1 . "</center></td></tr>";
// $table = $table . "<tr><td class=\"english\" colspan=\"2\"><center>" . $extraAnno2 . "</center></td></tr>";
// $table = $table . "<tr><td class=\"english\" colspan=\"2\"><center>" . $extraAnno3 . "</center></td></tr>";
// $table = $table . "<tr><td class=\"english\" colspan=\"2\"><center>" . $extraAnno4 . "</center></td></tr>";
// $table = $table . "<tr><td class=\"english\" colspan=\"2\"><center>" . $extraAnno5 . "</center></td></tr>";
$table = $table . "<tr><td class=\"source\" colspan=\"2\"><center>" . $source . "</center></td></tr>" . "<tr class=\"body\">" . "<td valign=\"top\" class=\"description\"><center><em>" . $pos . "</center></em></td><td class=\"description\">" . $note . "</td></tr>" . $examples . "<tr class=\"space\"><td colspan=\"2\"><center><audio width=\"300px\" src=\"../dictionary/sounds/" . $media . "\" controls preload=\"auto\" autobuffer></audio></center></td></tr></table></a>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Dictionary Template</title>
<meta name="description" content="Multi-layered Language Learning Resources" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="User" />
<meta name="copyright" content="User" />
<link rel="stylesheet" href="css/foundation.css" />
<script src="js/vendor/modernizr.js"></script>
<script src="js/loadxmldoc.js"></script>
</head>
<body>
<!-- Menu Bar. -->
<div class="fixed">
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<h1>
<a href="../">
Back to Main Menu
</a>
</h1>
</li>
<li class="toggle-topbar menu-icon"><a href="#"><span>menu</span></a>
</li>
</ul>
<section class="top-bar-section">
<ul class="right">
<li class="divider"></li>
<li class="name">
<h1>
<!-- Link to Phrasicon. -->
<a href="../phrasicon">
Phrasicon</a>
</h1>
</li>
<li class="divider"></li>
</ul>
</section>
</nav>
</div>
<div class="row">
<div class="large-12 columns">
<hr>
<!-- Title of page. -->
<h4 class="title"><a class="home" href="../dictionary/">Online Talking Dictionary Template</a></h4>
<hr>
<!-- Search by letter (title). -->
<h4 class="subsubheader">English to Source</h4>
<!-- Search by letter (A-Z). -->
<ul class="pagination">
<center>
<li><a href="../dictionary/category.php?letter=a">a</a>
</li>
<li><a href="../dictionary/category.php?letter=b">b</a>
</li>
<li><a href="../dictionary/category.php?letter=c">c</a>
</li>
<li><a href="../dictionary/category.php?letter=d">d</a>
</li>
<li><a href="../dictionary/category.php?letter=e">e</a>
</li>
<li><a href="../dictionary/category.php?letter=f">f</a>
</li>
<li><a href="../dictionary/category.php?letter=g">g</a>
</li>
<li><a href="../dictionary/category.php?letter=h">h</a>
</li>
<li><a href="../dictionary/category.php?letter=i">i</a>
</li>
<li><a href="../dictionary/category.php?letter=j">j</a>
</li>
<li><a href="../dictionary/category.php?letter=k">k</a>
</li>
<li><a href="../dictionary/category.php?letter=l">l</a>
</li>
<li><a href="../dictionary/category.php?letter=m">m</a>
</li>
<li><a href="../dictionary/category.php?letter=n">n</a>
</li>
<li><a href="../dictionary/category.php?letter=o">o</a>
</li>
<li><a href="../dictionary/category.php?letter=p">p</a>
</li>
<li><a href="../dictionary/category.php?letter=q">q</a>
</li>
<li><a href="../dictionary/category.php?letter=r">r</a>
</li>
<li><a href="../dictionary/category.php?letter=s">s</a>
</li>
<li><a href="../dictionary/category.php?letter=t">t</a>
</li>
<li><a href="../dictionary/category.php?letter=u">u</a>
</li>
<li><a href="../dictionary/category.php?letter=v">v</a>
</li>
<li><a href="../dictionary/category.php?letter=w">w</a>
</li>
<li><a href="../dictionary/category.php?letter=x">x</a>
</li>
<li><a href="../dictionary/category.php?letter=y">y</a>
</li>
<li><a href="../dictionary/category.php?letter=z">z</a>
</li>
</center>
</ul>
<div class="row collapse">
<div class="large-2 small-3 columns">
<form name="form1" action="../dictionary/category.php" method="post">
<!-- Language options. -->
<select name="lang">
<option value="english">English</option>
<option value="source">Source</option>
</select>
</div>
<div class="large-6 small-4 columns">
<!-- Search bar. -->
<input type="text" placeholder="Type word..." name="word">
</div>
<div class="large-3 small-3 columns">
<!-- Submit button. -->
<input class="button postfix" type="submit" value="Submit">
</div>
<div class="large-1 small-2 columns">
<!-- Dropdown for special characters. -->
<a class="button dropdown postfix" data-dropdown="drop"></a>
<ul id="drop" class="f-dropdown" data-dropdown-content>
<li><a onmouseover="showtip(this,event,'U02B0')" onmouseout=hidetip() href="javascript:;" onclick="form1.word.value=form1.word.value + 'ʔ';">ʔ</a>
</li>
</ul>
</div>
</div>
<p>
<!-- Background image. -->
<img src="background_dictionary.jpg" />
</p>
<!-- Search results here... -->
<?php echo $table ?>
</div>
</div>
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation/foundation.js"></script>
<script>
$(document).foundation();
var doc = document.documentElement;
doc.setAttribute('data-useragent', navigator.userAgent);
</script>
</body>
</html>