-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconcordance.php
More file actions
153 lines (139 loc) · 6.59 KB
/
Copy pathconcordance.php
File metadata and controls
153 lines (139 loc) · 6.59 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
<?php
require_once '/home/raphi/config/mysql_config.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/section.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/sql_queries.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/corpus.php';
$mysql = new mysqli($servername, $username, $password, $dbname);
$mysql->set_charset('utf8mb4');
if ($mysql->connect_error) {
die("Connection failed: " . $mysql->connect_error);
}
$term = (string)($_GET['q'] ?? '');
$width = max(2, min(12, (int)($_GET['w'] ?? 6)));
$page = max(1, (int)($_GET['p'] ?? 1));
$per = 60;
$ready = corpusReady($mysql);
$res = ($ready && $term !== '')
? corpusConcordance($mysql, $term, $GENRE, $width, $per, ($page - 1) * $per)
: ['mode' => 'none', 'total' => 0, 'poems' => 0, 'hits' => [], 'term' => ''];
$spellings = ($res['total'] > 0)
? corpusSpellings($mysql, $res['term'], $res['mode'] === 'unpointed')
: [];
$byYear = ($res['total'] > 0)
? corpusByYear($mysql, $res['term'], $GENRE, $res['mode'] === 'unpointed')
: [];
$totals = corpusTotals($mysql, $GENRE);
$pages = (int)ceil($res['total'] / $per);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $SECTION_BASE ?>/style.css">
<link rel='shortcut icon' href='/favicon.png' type='image/x-icon' />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<title><?= $res['term'] !== '' ? e($res['term']) . ' — ' : '' ?>Concordance</title>
</head>
<body>
<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/header.php'; ?>
<?php include $_SERVER['DOCUMENT_ROOT'] . '/nav.html'; ?>
<div class="conc">
<h2>Concordance <span dir="rtl" class="yid">קאָנקאָרדאַנץ</span></h2>
<?php if (!$ready): ?>
<p class="conc_note">The word index has not been built yet.</p>
<?php else: ?>
<form class="conc_form" method="get">
<input type="search" name="q" dir="rtl" value="<?= e($res['term']) ?>"
placeholder="אַ װאָרט" autofocus>
<label class="conc_label">context
<select name="w">
<?php foreach ([3,4,5,6,8,10] as $o): ?>
<option value="<?= $o ?>" <?= $o === $width ? 'selected' : '' ?>><?= $o ?></option>
<?php endforeach; ?>
</select> words
</label>
<button type="submit">Search</button>
<span class="conc_count">
<?= number_format((int)($totals['tokens'] ?? 0)) ?> words in
<?= number_format((int)($totals['poems'] ?? 0)) ?> <?= e(strtolower($S['works_e'])) ?>
</span>
</form>
<?php if ($res['term'] === ''): ?>
<p class="conc_note">
Type a Yiddish word to see every place it appears, with the words
around it.
</p>
<?php elseif ($res['total'] === 0): ?>
<p class="conc_note">
No occurrences of <strong dir="rtl" class="yid"><?= e($res['term']) ?></strong>.
Note that pointing matters: <span dir="rtl" class="yid">אַ</span> and
<span dir="rtl" class="yid">אָ</span> are different words, though an
unpointed search will find both.
</p>
<?php else: ?>
<?php if ($res['mode'] === 'unpointed'): ?>
<p class="conc_note conc_warn">
No exact match, so these are <strong>unpointed</strong> matches —
every word that looks the same once the vowel points are removed.
They may include genuinely different words:
<span dir="rtl" class="yid">אַ</span> /a/ and
<span dir="rtl" class="yid">אָ</span> /o/ both reduce to
<span dir="rtl" class="yid">א</span>.
</p>
<?php endif; ?>
<p class="conc_summary">
<strong><?= number_format($res['total']) ?></strong> occurrence<?= $res['total'] === 1 ? '' : 's' ?>
in <strong><?= $res['poems'] ?></strong> <?= $res['poems'] === 1 ? 'poem' : 'poems' ?>
<?php if (count($spellings) > 1): ?>
· spelled <span class="spellings"><?= implode(' · ', array_map('e', $spellings)) ?></span>
<?php endif; ?>
</p>
<?php if (count($byYear) > 1):
$max = max(array_column($byYear, 'n')); ?>
<div class="years_wrap">
<div class="years">
<?php foreach ($byYear as $y): ?>
<div style="height:<?= max(3, (int)round(100 * $y['n'] / $max)) ?>%"
title="<?= (int)$y['yr'] ?>: <?= (int)$y['n'] ?> in <?= (int)$y['poems'] ?> poems"></div>
<?php endforeach; ?>
</div>
<div class="years_axis">
<span><?= (int)$byYear[0]['yr'] ?></span>
<span>occurrences by year — hover for counts</span>
<span><?= (int)$byYear[count($byYear) - 1]['yr'] ?></span>
</div>
</div>
<?php endif; ?>
<table class="kwic">
<?php foreach ($res['hits'] as $hit): ?>
<tr>
<td class="before"><?= e($hit['before']) ?></td>
<td class="kw"><?= e($hit['surface']) ?></td>
<td class="after"><?= e($hit['after']) ?></td>
<td class="src">
<a href="poem.php?poem=<?= urlencode($hit['poem']) ?>" target="_blank"
title="<?= e($hit['title_y']) ?>"><?= e($hit['poet']) ?></a>
<?= $hit['yr'] ? '· ' . (int)$hit['yr'] : '' ?>
· l.<?= (int)$hit['line_no'] ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php if ($pages > 1): ?>
<div class="pager">
<?php if ($page > 1): ?>
<a href="?q=<?= urlencode($res['term']) ?>&w=<?= $width ?>&p=<?= $page - 1 ?>">← previous</a>
<?php endif; ?>
<span>page <?= $page ?> of <?= $pages ?></span>
<?php if ($page < $pages): ?>
<a href="?q=<?= urlencode($res['term']) ?>&w=<?= $width ?>&p=<?= $page + 1 ?>">next →</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div>
</body>
</html>