/* */
This source file includes following definitions.
- checkAgent
- logging
- errorsend
- clearother
- clearvse
- clearself
- setprelength
- setaftlength
- tabKwic
- tabOpts
- tabRkbd
- tabGenr
- tabDesc
1 /* -*- coding: utf-8; mode: c++; -*-
2 * Concordance to A. S. Pushkin's Works - Functions
3 * $Id: ConcordanceFunc.cpp 16 2013-11-04 16:38:10Z isao $
4 * Copyright (C) 2012, isao yasuda
5 */
6
7 #include "Concordance.hpp"
8
9 using namespace Wt;
10 using namespace boost::interprocess;
11
12 // UserAgent チェック
13 bool checkAgent(std::string& agent)
14 {
15 boost::regex r("Mac OS X 10_([0-9]+)_.*Safari");
16 boost::smatch m;
17 int ver;
18 // Mac OS X 10.4 以下なら false
19 if (boost::regex_search(agent, m, r)) {
20 ver = std::atoi(m.str(1).c_str());
21 std::cerr << "UserAgent: Mac OS X 10." << ver << " Safari\n";
22 if (ver <= 4)
23 return false;
24 }
25 return true;
26 }
27
28 // ロギング
29 void logging(const char* mesg, logkind kind)
30 {
31 switch (kind) {
32 case INFO:
33 log("info") << mesg;
34 break;
35 case WARN:
36 log("warn") << mesg;
37 break;
38 case ERROR:
39 log("error") << mesg;
40 break;
41 default:
42 log("info") << mesg;
43 break;
44 }
45 }
46
47 // エラーメッセージ出力
48 void Concordance::errorsend(const std::string& emsg)
49 {
50 WString s(emsg, UTF8);
51 s = "<p class=\"err\">" + s + "</p>";
52 cmesg->setTextFormat(XHTMLUnsafeText);
53 cmesg->setText(s);
54 }
55
56 // オール以外クリア
57 void Concordance::clearother()
58 {
59 // オール指定がチェックされていたらほかをクリア
60 if (g12->isChecked()) {
61 g0->setChecked(false);
62 g1->setChecked(false);
63 g2->setChecked(false);
64 g3->setChecked(false);
65 g4->setChecked(false);
66 g5->setChecked(false);
67 g6->setChecked(false);
68 g7->setChecked(false);
69 g8->setChecked(false);
70 g9->setChecked(false);
71 g10->setChecked(false);
72 g11->setChecked(false);
73 if (genrev.size() > 0)
74 genrev.clear();
75 std::cerr << "g12 checked.\n";
76 }
77 }
78
79 // オール指定クリア
80 void Concordance::clearvse()
81 {
82 g12->setChecked(false);
83 std::vector<int>::iterator i;
84 // オール指定以外がチェックされていたらオール指定をクリア
85 if (g0->isChecked())
86 if ((i = find(genrev.begin(), genrev.end(), 0)) == genrev.end())
87 genrev.push_back(0);
88 if (g1->isChecked())
89 if ((i = find(genrev.begin(), genrev.end(), 1)) == genrev.end())
90 genrev.push_back(1);
91 if (g2->isChecked())
92 if ((i = find(genrev.begin(), genrev.end(), 2)) == genrev.end())
93 genrev.push_back(2);
94 if (g3->isChecked())
95 if ((i = find(genrev.begin(), genrev.end(), 3)) == genrev.end())
96 genrev.push_back(3);
97 if (g4->isChecked())
98 if ((i = find(genrev.begin(), genrev.end(), 4)) == genrev.end())
99 genrev.push_back(4);
100 if (g5->isChecked())
101 if ((i = find(genrev.begin(), genrev.end(), 5)) == genrev.end())
102 genrev.push_back(5);
103 if (g6->isChecked())
104 if ((i = find(genrev.begin(), genrev.end(), 6)) == genrev.end())
105 genrev.push_back(6);
106 if (g7->isChecked())
107 if ((i = find(genrev.begin(), genrev.end(), 7)) == genrev.end())
108 genrev.push_back(7);
109 if (g8->isChecked())
110 if ((i = find(genrev.begin(), genrev.end(), 8)) == genrev.end())
111 genrev.push_back(8);
112 if (g9->isChecked())
113 if ((i = find(genrev.begin(), genrev.end(), 9)) == genrev.end())
114 genrev.push_back(9);
115 if (g10->isChecked())
116 if ((i = find(genrev.begin(), genrev.end(), 10)) == genrev.end())
117 genrev.push_back(10);
118 if (g11->isChecked())
119 if ((i = find(genrev.begin(), genrev.end(), 11)) == genrev.end())
120 genrev.push_back(11);
121 }
122
123 // アンチェック: チェック解除されたものを vector から取り除く
124 void Concordance::clearself()
125 {
126 if (! g0->isChecked()) {
127 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 0);
128 genrev.erase(i, genrev.end());
129 }
130 if (! g1->isChecked()) {
131 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 1);
132 genrev.erase(i, genrev.end());
133 }
134 if (! g2->isChecked()) {
135 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 2);
136 genrev.erase(i, genrev.end());
137 }
138 if (! g3->isChecked()) {
139 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 3);
140 genrev.erase(i, genrev.end());
141 }
142 if (! g4->isChecked()) {
143 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 4);
144 genrev.erase(i, genrev.end());
145 }
146 if (! g5->isChecked()) {
147 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 5);
148 genrev.erase(i, genrev.end());
149 }
150 if (! g6->isChecked()) {
151 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 6);
152 genrev.erase(i, genrev.end());
153 }
154 if (! g7->isChecked()) {
155 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 7);
156 genrev.erase(i, genrev.end());
157 }
158 if (! g8->isChecked()) {
159 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 8);
160 genrev.erase(i, genrev.end());
161 }
162 if (! g9->isChecked()) {
163 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 9);
164 genrev.erase(i, genrev.end());
165 }
166 if (! g10->isChecked()) {
167 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 10);
168 genrev.erase(i, genrev.end());
169 }
170 if (! g11->isChecked()) {
171 std::vector<int>::iterator i = remove(genrev.begin(), genrev.end(), 11);
172 genrev.erase(i, genrev.end());
173 }
174 }
175
176 void Concordance::setprelength()
177 {
178 cprelen = std::atoi((lenpEdit->text()).toUTF8().c_str());
179 std::cerr << "* Changed Prelength to: " << cprelen << std::endl;
180 }
181
182 void Concordance::setaftlength()
183 {
184 caftlen = std::atoi((lenaEdit->text()).toUTF8().c_str());
185 std::cerr << "* Changed Aftlength to: " << caftlen << std::endl;
186 }
187
188 void Concordance::tabKwic()
189 {
190 // 式ラベル表示,ユーザ入力式内容表示エリア
191 wmesg = new WText(kwic);
192 pmesg = new WText(kwic);
193 kwic->addWidget(new WBreak());
194
195 // コンコーダンスエラー/終了メッセージ出力エリア
196 cmesg = new WText(kwic);
197
198 // コンコーダンス出力テーブル
199 kwic->addWidget(new WBreak());
200 ctbl = new WTable(kwic);
201 ctbl->clear();
202 }
203
204 void Concordance::tabOpts()
205 {
206 // オプション設定タブ
207 // 見出語形/出現形ツリー選択ラジオボタン
208 WGroupBox* gbox0 = new WGroupBox(L"Форма Базы данных", opts);
209 gbox0->setId("gbx0");
210 wbg0 = new WButtonGroup(gbox0);
211 WRadioButton* rb0;
212 rb0 = new WRadioButton(L"Lemmatized (форма заглавных слов)", gbox0);
213 wbg0->addButton(rb0, 0);
214 rb0 = new WRadioButton(L"Non Lemmatized (форма в тексте)", gbox0);
215 wbg0->addButton(rb0, 1);
216 wbg0->setCheckedButton(wbg0->button(0)); // Lemmatized
217
218 // 入力見出語変換(見出語形の場合のみ)
219 WGroupBox* gbox1 = new WGroupBox(L"Лемматизация ввода", opts);
220 gbox1->setId("gbx1");
221 wbg1 = new WButtonGroup(gbox1);
222 WRadioButton* rb1;
223 rb1 = new WRadioButton(L"ON (только в случае Lemmatized)", gbox1);
224 wbg1->addButton(rb1, 0);
225 rb1 = new WRadioButton(L"OFF", gbox1);
226 wbg1->addButton(rb1, 1);
227 wbg1->setCheckedButton(wbg1->button(0)); // YES
228
229 // コンテキスト長設定テキストボックス
230 WGroupBox* gbox2 = new WGroupBox(L"Ограничение длины контекста", opts);
231 gbox2->setId("gbx2");
232 gbox2->addWidget(new WText(WString::tr("labelpre"), XHTMLText));
233 lenpEdit = new WLineEdit("48", gbox2);
234 lenpEdit->setValidator(new WIntValidator(0, 300));
235 lenpEdit->setTextSize(4);
236 lenpEdit->changed().connect(this, &Concordance::setprelength);
237 gbox2->addWidget(new WText(WString::tr("labelaft"), XHTMLText));
238 lenaEdit = new WLineEdit("58", gbox2);
239 lenaEdit->setValidator(new WIntValidator(0, 300));
240 lenaEdit->setTextSize(4);
241 lenaEdit->changed().connect(this, &Concordance::setaftlength);
242 gbox2->addWidget(new WText(WString::tr("labelpost"), XHTMLText));
243 cprelen = 48; // initial
244 caftlen = 58; // initial
245
246 // ジャンル選択チェックボックス
247 gbox = new WGroupBox(L"Выбор жанров", opts);
248 gbox->setId("gbx");
249 g12 = new WCheckBox(L"Все", gbox);
250 g0 = new WCheckBox(L"Стихи", gbox);
251 g1 = new WCheckBox(L"Поэмы", gbox);
252 g2 = new WCheckBox(L"Сказки", gbox);
253 g3 = new WCheckBox(L"Евгений Онегин", gbox);
254 g4 = new WCheckBox(L"Драматические произведения", gbox);
255 g5 = new WCheckBox(L"Романы и Повести", gbox);
256 g6 = new WCheckBox(L"Критика", gbox);
257 gbox->addWidget(new WBreak());
258 g7 = new WCheckBox(L"Исторические произведения ", gbox);
259 g8 = new WCheckBox(L"История Петра I", gbox);
260 g9 = new WCheckBox(L"Воспоминания и Дневники", gbox);
261 g10 = new WCheckBox(L"Записки и Деловые бумаги", gbox);
262 g11 = new WCheckBox(L"Письма", gbox);
263
264 // ジャンル初期設定: 全ジャンル選択
265 g12->setChecked(true);
266 // チェック時イベント処理登録
267 g0->checked().connect(this, &Concordance::clearvse);
268 g1->checked().connect(this, &Concordance::clearvse);
269 g2->checked().connect(this, &Concordance::clearvse);
270 g3->checked().connect(this, &Concordance::clearvse);
271 g4->checked().connect(this, &Concordance::clearvse);
272 g5->checked().connect(this, &Concordance::clearvse);
273 g6->checked().connect(this, &Concordance::clearvse);
274 g7->checked().connect(this, &Concordance::clearvse);
275 g8->checked().connect(this, &Concordance::clearvse);
276 g9->checked().connect(this, &Concordance::clearvse);
277 g10->checked().connect(this, &Concordance::clearvse);
278 g11->checked().connect(this, &Concordance::clearvse);
279 g12->checked().connect(this, &Concordance::clearother);
280 // アンチェック時イベント処理登録
281 g0->unChecked().connect(this, &Concordance::clearself);
282 g1->unChecked().connect(this, &Concordance::clearself);
283 g2->unChecked().connect(this, &Concordance::clearself);
284 g3->unChecked().connect(this, &Concordance::clearself);
285 g4->unChecked().connect(this, &Concordance::clearself);
286 g5->unChecked().connect(this, &Concordance::clearself);
287 g6->unChecked().connect(this, &Concordance::clearself);
288 g7->unChecked().connect(this, &Concordance::clearself);
289 g8->unChecked().connect(this, &Concordance::clearself);
290 g9->unChecked().connect(this, &Concordance::clearself);
291 g10->unChecked().connect(this, &Concordance::clearself);
292 g11->unChecked().connect(this, &Concordance::clearself);
293
294 }
295
296 void Concordance::tabRkbd()
297 {
298 keytype = none;
299 keyboard();
300 }
301
302 void Concordance::tabGenr()
303 {
304 genr->addWidget(new WText(WString::tr("genrelink"), XHTMLText));
305 }
306
307 void Concordance::tabDesc()
308 {
309 desc->addWidget(new WText(WString::tr("description"), XHTMLText));
310 }
311
/* */