Mercurial > emacs
annotate lisp/international/skkdic-cnv.el @ 30453:eadc651de6f7
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Tue, 25 Jul 2000 12:50:16 +0000 |
parents | faac941ad28d |
children |
rev | line source |
---|---|
17315
a3ca5e15c82a
Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents:
17098
diff
changeset
|
1 ;;; skkdic-cnv.el --- Convert a SKK dictionary for `skkdic-utl' |
17052 | 2 |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
18202
diff
changeset
|
4 ;; Licensed to the Free Software Foundation. |
17052 | 5 |
6 ;; Keywords: mule, multilingual, Japanese, SKK | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
17071 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
17052 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; SKK is a Japanese input method running on Mule created by Masahiko | |
28 ;; Sato <masahiko@sato.riec.tohoku.ac.jp>. Here we provide utilities | |
29 ;; to handle a dictionary distributed with SKK so that a different | |
30 ;; input method (e.g. quail-japanese) can utilize the dictionary. | |
31 | |
32 ;; The format of SKK dictionary is quite simple. Each line has the | |
33 ;; form "KANASTRING /CONV1/CONV2/.../" which means KANASTRING ($B2>L>J8(B | |
34 ;; $B;zNs(B) can be converted to one of CONVi. CONVi is a Kanji ($B4A;z(B) | |
35 ;; and Kana ($B2>L>(B) mixed string. | |
36 ;; | |
37 ;; KANASTRING may have a trailing ASCII letter for Okurigana ($BAw$j2>L>(B) | |
38 ;; information. For instance, the trailing letter `k' means that one | |
39 ;; of the following Okurigana is allowed: $B$+$-$/$1$3(B. So, in that | |
40 ;; case, the string "KANASTRING$B$/(B" can be converted to one of "CONV1$B$/(B", | |
41 ;; CONV2$B$/(B, ... | |
42 | |
43 ;;; Code: | |
44 | |
45 ;; Name of a file to generate from SKK dictionary. | |
46 (defvar skkdic-filename "skkdic.el") | |
47 | |
48 ;; To make a generated skkdic.el smaller. | |
49 (make-coding-system | |
18557
c324644fe5d2
Coding system name changed to
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
50 'iso-2022-7bit-short |
17052 | 51 2 ?J |
18202
1fe28ee1b0cd
Coding system name changed from
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
52 "Like `iso-2022-7bit' but no ASCII designation before SPC." |
17052 | 53 '(ascii nil nil nil t t nil t)) |
54 | |
55 (defun skkdic-convert-okuri-ari (skkbuf buf) | |
56 (message "Processing OKURI-ARI entries ...") | |
57 (goto-char (point-min)) | |
58 (save-excursion | |
59 (set-buffer buf) | |
60 (insert ";; Setting okuri-ari entries.\n" | |
61 "(skkdic-set-okuri-ari\n")) | |
62 (while (not (eobp)) | |
63 (let ((from (point)) | |
64 to) | |
65 (end-of-line) | |
66 (setq to (point)) | |
67 | |
68 (save-excursion | |
69 (set-buffer buf) | |
70 (insert-buffer-substring skkbuf from to) | |
71 (beginning-of-line) | |
72 (insert "\"") | |
73 (search-forward " ") | |
74 (delete-char 1) ; delete the first '/' | |
75 (let ((p (point))) | |
76 (end-of-line) | |
77 (delete-char -1) ; delete the last '/' | |
78 (subst-char-in-region p (point) ?/ ? 'noundo)) | |
79 (insert "\"\n")) | |
80 | |
81 (forward-line 1))) | |
82 (save-excursion | |
83 (set-buffer buf) | |
84 (insert ")\n\n"))) | |
85 | |
86 (defconst skkdic-postfix-list '(skkdic-postfix-list)) | |
87 | |
88 (defconst skkdic-postfix-data | |
89 '(("$B$$$-(B" "$B9T(B") | |
90 ("$B$,$+$j(B" "$B78(B") | |
91 ("$B$,$/(B" "$B3X(B") | |
92 ("$B$,$o(B" "$B@n(B") | |
93 ("$B$7$c(B" "$B<R(B") | |
94 ("$B$7$e$&(B" "$B=8(B") | |
95 ("$B$7$g$&(B" "$B>^(B" "$B>k(B") | |
96 ("$B$8$g$&(B" "$B>k(B") | |
97 ("$B$;$s(B" "$B@~(B") | |
98 ("$B$@$1(B" "$B3Y(B") | |
99 ("$B$A$c$/(B" "$BCe(B") | |
100 ("$B$F$s(B" "$BE9(B") | |
101 ("$B$H$&$2(B" "$BF=(B") | |
102 ("$B$I$*$j(B" "$BDL$j(B") | |
103 ("$B$d$^(B" "$B;3(B") | |
104 ("$B$P$7(B" "$B66(B") | |
105 ("$B$O$D(B" "$BH/(B") | |
106 ("$B$b$/(B" "$BL\(B") | |
107 ("$B$f$-(B" "$B9T(B"))) | |
108 | |
109 (defun skkdic-convert-postfix (skkbuf buf) | |
110 (message "Processing POSTFIX entries ...") | |
111 (goto-char (point-min)) | |
112 (save-excursion | |
113 (set-buffer buf) | |
114 (insert ";; Setting postfix entries.\n" | |
115 "(skkdic-set-postfix\n")) | |
116 | |
117 ;; Initialize SKKDIC-POSTFIX-LIST by predefined data | |
118 ;; SKKDIC-POSTFIX-DATA. | |
119 (save-excursion | |
120 (set-buffer buf) | |
121 (let ((l skkdic-postfix-data) | |
122 kana candidates entry) | |
123 (while l | |
124 (setq kana (car (car l)) candidates (cdr (car l))) | |
125 (insert "\"" kana) | |
126 (while candidates | |
127 (insert " " (car candidates)) | |
128 (setq entry (lookup-nested-alist (car candidates) | |
129 skkdic-postfix-list nil nil t)) | |
130 (if (consp (car entry)) | |
131 (setcar entry (cons kana (car entry))) | |
132 (set-nested-alist (car candidates) (list kana) | |
133 skkdic-postfix-list)) | |
134 (setq candidates (cdr candidates))) | |
135 (insert "\"\n") | |
136 (setq l (cdr l))))) | |
137 | |
138 ;; Search postfix entries. | |
139 (while (re-search-forward "^[#<>?]\\(\\cH+\\) " nil t) | |
140 (let ((kana (match-string 1)) | |
141 str candidates) | |
142 (while (looking-at "/[#0-9 ]*\\([^/\n]*\\)/") | |
143 (setq str (match-string 1)) | |
144 (if (not (member str candidates)) | |
145 (setq candidates (cons str candidates))) | |
146 (goto-char (match-end 1))) | |
147 (save-excursion | |
148 (set-buffer buf) | |
149 (insert "\"" kana) | |
150 (while candidates | |
151 (insert " " (car candidates)) | |
152 (let ((entry (lookup-nested-alist (car candidates) | |
153 skkdic-postfix-list nil nil t))) | |
154 (if (consp (car entry)) | |
155 (if (not (member kana (car entry))) | |
156 (setcar entry (cons kana (car entry)))) | |
157 (set-nested-alist (car candidates) (list kana) | |
158 skkdic-postfix-list))) | |
159 (setq candidates (cdr candidates))) | |
160 (insert "\"\n")))) | |
161 (save-excursion | |
162 (set-buffer buf) | |
163 (insert ")\n\n"))) | |
164 | |
165 (defconst skkdic-prefix-list '(skkdic-prefix-list)) | |
166 | |
167 (defun skkdic-convert-prefix (skkbuf buf) | |
168 (message "Processing PREFIX entries ...") | |
169 (goto-char (point-min)) | |
170 (save-excursion | |
171 (set-buffer buf) | |
172 (insert ";; Setting prefix entries.\n" | |
173 "(skkdic-set-prefix\n")) | |
174 (save-excursion | |
175 (while (re-search-forward "^\\(\\cH+\\)[<>?] " nil t) | |
176 (let ((kana (match-string 1)) | |
177 str candidates) | |
178 (while (looking-at "/\\([^/\n]+\\)/") | |
179 (setq str (match-string 1)) | |
180 (if (not (member str candidates)) | |
181 (setq candidates (cons str candidates))) | |
182 (goto-char (match-end 1))) | |
183 (save-excursion | |
184 (set-buffer buf) | |
185 (insert "\"" kana) | |
186 (while candidates | |
187 (insert " " (car candidates)) | |
188 (set-nested-alist (car candidates) kana skkdic-prefix-list) | |
189 (setq candidates (cdr candidates))) | |
190 (insert "\"\n"))))) | |
191 (save-excursion | |
192 (set-buffer buf) | |
193 (insert ")\n\n"))) | |
194 | |
195 ;; FROM and TO point the head and tail of "/J../J../.../". | |
196 (defun skkdic-get-candidate-list (from to) | |
197 (let (candidates) | |
198 (goto-char from) | |
199 (while (re-search-forward "/\\cj+" to t) | |
200 (setq candidates (cons (buffer-substring (1+ (match-beginning 0)) | |
201 (match-end 0)) | |
202 candidates))) | |
203 candidates)) | |
204 | |
205 ;; Return entry for STR from nested alist ALIST. | |
206 (defsubst skkdic-get-entry (str alist) | |
207 (car (lookup-nested-alist str alist nil nil t))) | |
208 | |
209 | |
210 (defconst skkdic-word-list '(skkdic-word-list)) | |
211 | |
212 ;; Return t if substring of STR (between FROM and TO) can be broken up | |
213 ;; to chunks all of which can be derived from another entry in SKK | |
214 ;; dictionary. SKKBUF is the buffer where the original SKK dictionary | |
215 ;; is visited, KANA is the current entry for STR. FIRST is t iff this | |
216 ;; is called at top level. | |
217 | |
218 (defun skkdic-breakup-string (skkbuf kana str from to &optional first) | |
219 (let ((len (- to from))) | |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
220 (or (and (>= len 2) |
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
221 (let ((min-idx (+ from 2)) |
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
222 (idx (if first (1- to ) to)) |
17052 | 223 (found nil)) |
224 (while (and (not found) (>= idx min-idx)) | |
225 (let ((kana2-list (skkdic-get-entry | |
226 (substring str from idx) | |
227 skkdic-word-list))) | |
228 (if (or (and (consp kana2-list) | |
229 (let ((kana-len (length kana)) | |
230 kana2) | |
231 (catch 'skkdic-tag | |
232 (while kana2-list | |
233 (setq kana2 (car kana2-list)) | |
234 (if (string-match kana2 kana) | |
235 (throw 'skkdic-tag t)) | |
236 (setq kana2-list (cdr kana2-list))))) | |
237 (or (= idx to) | |
238 (skkdic-breakup-string skkbuf kana str | |
239 idx to))) | |
240 (and (stringp kana2-list) | |
241 (string-match kana2-list kana))) | |
242 (setq found t) | |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
243 (setq idx (1- idx))))) |
17052 | 244 found)) |
245 (and first | |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
246 (> len 2) |
17052 | 247 (let ((kana2 (skkdic-get-entry |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
248 (substring str from (1+ from)) |
17052 | 249 skkdic-prefix-list))) |
250 (and (stringp kana2) | |
251 (eq (string-match kana2 kana) 0))) | |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
252 (skkdic-breakup-string skkbuf kana str (1+ from) to)) |
17052 | 253 (and (not first) |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
254 (>= len 1) |
17052 | 255 (let ((kana2-list (skkdic-get-entry |
256 (substring str from to) | |
257 skkdic-postfix-list))) | |
258 (and (consp kana2-list) | |
259 (let (kana2) | |
260 (catch 'skkdic-tag | |
261 (while kana2-list | |
262 (setq kana2 (car kana2-list)) | |
263 (if (string= kana2 | |
264 (substring kana (- (length kana2)))) | |
265 (throw 'skkdic-tag t)) | |
266 (setq kana2-list (cdr kana2-list))))))))))) | |
267 | |
268 ;; Return list of candidates which excludes some from CANDIDATES. | |
269 ;; Excluded candidates can be derived from another entry. | |
270 | |
271 (defun skkdic-reduced-candidates (skkbuf kana candidates) | |
272 (let (elt l) | |
273 (while candidates | |
274 (setq elt (car candidates)) | |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
275 (if (or (= (length elt) 1) |
17052 | 276 (and (string-match "^\\cj" elt) |
277 (not (skkdic-breakup-string skkbuf kana elt 0 (length elt) | |
278 'first)))) | |
279 (setq l (cons elt l))) | |
280 (setq candidates (cdr candidates))) | |
281 (nreverse l))) | |
282 | |
283 (defconst skkdic-okuri-nasi-entries (list nil)) | |
284 (defconst skkdic-okuri-nasi-entries-count 0) | |
285 | |
286 (defun skkdic-collect-okuri-nasi () | |
287 (message "Collecting OKURI-NASI entries ...") | |
288 (save-excursion | |
289 (let ((prev-ratio 0) | |
290 ratio) | |
291 (while (re-search-forward "^\\(\\cH+\\) \\(/\\cj.*\\)/$" nil t) | |
292 (let ((kana (match-string 1)) | |
293 (candidates (skkdic-get-candidate-list (match-beginning 2) | |
294 (match-end 2)))) | |
295 (setq skkdic-okuri-nasi-entries | |
296 (cons (cons kana candidates) skkdic-okuri-nasi-entries) | |
297 skkdic-okuri-nasi-entries-count | |
298 (1+ skkdic-okuri-nasi-entries-count)) | |
299 (setq ratio (floor (/ (* (point) 100.0) (point-max)))) | |
300 (if (/= ratio prev-ratio) | |
301 (progn | |
302 (message "collected %2d%% %s ..." ratio kana) | |
303 (setq prev-ratio ratio))) | |
304 (while candidates | |
305 (let ((entry (lookup-nested-alist (car candidates) | |
306 skkdic-word-list nil nil t))) | |
307 (if (consp (car entry)) | |
308 (setcar entry (cons kana (car entry))) | |
309 (set-nested-alist (car candidates) (list kana) | |
310 skkdic-word-list))) | |
311 (setq candidates (cdr candidates)))))))) | |
312 | |
313 (defun skkdic-convert-okuri-nasi (skkbuf buf) | |
314 (message "Processing OKURI-NASI entries ...") | |
315 (save-excursion | |
316 (set-buffer buf) | |
317 (insert ";; Setting okuri-nasi entries.\n" | |
318 "(skkdic-set-okuri-nasi\n") | |
319 (let ((l (nreverse skkdic-okuri-nasi-entries)) | |
320 (count 0) | |
321 (prev-ratio 0) | |
322 ratio) | |
323 (while l | |
324 (let ((kana (car (car l))) | |
325 (candidates (cdr (car l)))) | |
326 (setq ratio (/ (* count 1000) skkdic-okuri-nasi-entries-count) | |
327 count (1+ count)) | |
328 (if (/= prev-ratio (/ ratio 10)) | |
329 (progn | |
330 (message "processed %2d%% %s ..." (/ ratio 10) kana) | |
331 (setq prev-ratio (/ ratio 10)))) | |
332 (if (setq candidates | |
333 (skkdic-reduced-candidates skkbuf kana candidates)) | |
334 (progn | |
335 (insert "\"" kana) | |
336 (while candidates | |
337 (insert " " (car candidates)) | |
338 (setq candidates (cdr candidates))) | |
339 (insert "\"\n")))) | |
340 (setq l (cdr l)))) | |
341 (insert ")\n\n"))) | |
342 | |
343 (defun skkdic-convert (filename &optional dirname) | |
344 "Convert SKK dictionary of FILENAME into the file \"skkdic.el\". | |
345 Optional argument DIRNAME if specified is the directory name under which | |
346 the generated \"skkdic.el\" is saved." | |
347 (interactive "FSKK dictionary file: ") | |
348 (message "Reading file \"%s\" ..." filename) | |
349 (let ((skkbuf(find-file-noselect (expand-file-name filename))) | |
350 (buf (get-buffer-create "*skkdic-work*"))) | |
351 (save-excursion | |
352 ;; Setup and generate the header part of working buffer. | |
353 (set-buffer buf) | |
354 (erase-buffer) | |
355 (buffer-disable-undo) | |
356 (insert ";; skkdic.el -- dictionary for Japanese input method\n" | |
357 ";;\tGenerated by the command `skkdic-convert'\n" | |
358 ";;\tDate: " (current-time-string) "\n" | |
359 ";;\tOriginal SKK dictionary file: " | |
360 (file-name-nondirectory filename) | |
361 "\n\n" | |
362 ";;; Comment:\n\n" | |
363 ";; Do byte-compile this file again after any modification.\n\n" | |
18557
c324644fe5d2
Coding system name changed to
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
364 ";;; Start of the header of the original SKK dictionary.\n\n") |
17052 | 365 (set-buffer skkbuf) |
366 (widen) | |
367 (goto-char 1) | |
368 (let (pos) | |
369 (search-forward ";; okuri-ari") | |
370 (forward-line 1) | |
371 (setq pos (point)) | |
372 (set-buffer buf) | |
373 (insert-buffer-substring skkbuf 1 pos)) | |
374 (insert "\n" | |
24440 | 375 ";;; Code:\n\n(eval-when-compile (require 'skkdic-cnv))\n\n") |
17052 | 376 |
377 ;; Generate the body part of working buffer. | |
378 (set-buffer skkbuf) | |
379 (let ((from (point)) | |
380 to) | |
381 ;; Convert okuri-ari entries. | |
382 (search-forward ";; okuri-nasi") | |
383 (beginning-of-line) | |
384 (setq to (point)) | |
385 (narrow-to-region from to) | |
386 (skkdic-convert-okuri-ari skkbuf buf) | |
387 (widen) | |
388 | |
389 ;; Convert okuri-nasi postfix entries. | |
390 (goto-char to) | |
391 (forward-line 1) | |
392 (setq from (point)) | |
393 (re-search-forward "^\\cH") | |
394 (setq to (match-beginning 0)) | |
395 (narrow-to-region from to) | |
396 (skkdic-convert-postfix skkbuf buf) | |
397 (widen) | |
398 | |
399 ;; Convert okuri-nasi prefix entries. | |
400 (goto-char to) | |
401 (skkdic-convert-prefix skkbuf buf) | |
402 | |
403 ;; | |
404 (skkdic-collect-okuri-nasi) | |
405 | |
406 ;; Convert okuri-nasi general entries. | |
407 (skkdic-convert-okuri-nasi skkbuf buf) | |
408 | |
409 ;; Postfix | |
410 (save-excursion | |
411 (set-buffer buf) | |
412 (goto-char (point-max)) | |
413 (insert ";;\n(provide 'skkdic)\n\n;; skkdic.el ends here\n"))) | |
414 | |
415 ;; Save the working buffer. | |
416 (set-buffer buf) | |
417 (set-visited-file-name (expand-file-name skkdic-filename dirname) t) | |
18557
c324644fe5d2
Coding system name changed to
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
418 (set-buffer-file-coding-system 'iso-2022-7bit-short) |
17052 | 419 (save-buffer 0)) |
420 (kill-buffer skkbuf) | |
421 (switch-to-buffer buf))) | |
422 | |
423 (defun batch-skkdic-convert () | |
424 "Run `skkdic-convert' on the files remaining on the command line. | |
425 Use this from the command line, with `-batch'; | |
426 it won't work in an interactive Emacs. | |
427 For example, invoke: | |
24440 | 428 % emacs -batch -l skkdic-cnv -f batch-skkdic-convert SKK-JISYO.L |
17052 | 429 to generate \"skkdic.el\" from SKK dictionary file \"SKK-JISYO.L\". |
430 To get complete usage, invoke: | |
24440 | 431 % emacs -batch -l skkdic-cnv -f batch-skkdic-convert -h" |
17052 | 432 (defvar command-line-args-left) ; Avoid compiler warning. |
433 (if (not noninteractive) | |
434 (error "`batch-skkdic-convert' should be used only with -batch")) | |
435 (if (string= (car command-line-args-left) "-h") | |
436 (progn | |
437 (message "To convert SKK-JISYO.L into skkdic.el:") | |
438 (message " %% emacs -batch -l skkdic-conv -f batch-skkdic-convert SKK-JISYO.L") | |
439 (message "To convert SKK-JISYO.L into DIR/skkdic.el:") | |
440 (message " %% emacs -batch -l skkdic-conv -f batch-skkdic-convert -dir DIR SKK-JISYO.L")) | |
441 (let (targetdir filename) | |
442 (if (string= (car command-line-args-left) "-dir") | |
443 (progn | |
444 (setq command-line-args-left (cdr command-line-args-left)) | |
445 (setq targetdir (expand-file-name (car command-line-args-left))) | |
446 (setq command-line-args-left (cdr command-line-args-left)))) | |
447 (setq filename (expand-file-name (car command-line-args-left))) | |
448 (message "Converting %s to skkdic.el ..." filename) | |
449 (message "It takes around 10 minutes even on Sun SS20.") | |
450 (skkdic-convert filename targetdir) | |
451 (message "Do byte-compile the created file by:") | |
24440 | 452 (message " %% emacs -batch -f batch-byte-compile skkdic.el") |
17052 | 453 )) |
454 (kill-emacs 0)) | |
455 | |
456 | |
457 ;; The following macros are expanded at byte-compiling time so that | |
458 ;; compiled code can be loaded quickly. | |
459 | |
460 (defun skkdic-get-kana-compact-codes (kana) | |
461 (let* ((len (length kana)) | |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
462 (vec (make-vector len 0)) |
17052 | 463 (i 0) |
464 ch) | |
465 (while (< i len) | |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
466 (setq ch (aref kana i)) |
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
467 (aset vec i |
17052 | 468 (if (< ch 128) ; CH is an ASCII letter for OKURIGANA, |
469 (- ch) ; represented by a negative code. | |
470 (if (= ch ?$B!<(B) ; `$B!<(B' is represented by 0. | |
471 0 | |
472 (- (nth 2 (split-char ch)) 32)))) | |
20736
60bf060b9ab1
(skkdic-jbytes): Variable deleted.
Kenichi Handa <handa@m17n.org>
parents:
18557
diff
changeset
|
473 (setq i (1+ i))) |
17052 | 474 vec)) |
475 | |
476 (defun skkdic-extract-conversion-data (entry) | |
18557
c324644fe5d2
Coding system name changed to
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
477 (string-match "^\\cj+[a-z]* " entry) |
17052 | 478 (let ((kana (substring entry (match-beginning 0) (1- (match-end 0)))) |
479 (i (match-end 0)) | |
480 candidates) | |
481 (while (string-match "[^ ]+" entry i) | |
482 (setq candidates (cons (match-string 0 entry) candidates)) | |
483 (setq i (match-end 0))) | |
484 (cons (skkdic-get-kana-compact-codes kana) candidates))) | |
485 | |
486 (defmacro skkdic-set-okuri-ari (&rest entries) | |
487 `(defconst skkdic-okuri-ari | |
488 ',(let ((l entries) | |
489 (map '(skkdic-okuri-ari)) | |
490 entry) | |
491 (while l | |
492 (setq entry (skkdic-extract-conversion-data (car l))) | |
493 (set-nested-alist (car entry) (cdr entry) map) | |
494 (setq l (cdr l))) | |
495 map))) | |
496 | |
497 (defmacro skkdic-set-postfix (&rest entries) | |
498 `(defconst skkdic-postfix | |
499 ',(let ((l entries) | |
500 (map '(nil)) | |
501 (longest 1) | |
502 len entry) | |
503 (while l | |
504 (setq entry (skkdic-extract-conversion-data (car l))) | |
505 (setq len (length (car entry))) | |
506 (if (> len longest) | |
507 (setq longest len)) | |
508 (let ((entry2 (lookup-nested-alist (car entry) map nil nil t))) | |
509 (if (consp (car entry2)) | |
510 (let ((conversions (cdr entry))) | |
511 (while conversions | |
512 (if (not (member (car conversions) (car entry2))) | |
513 (setcar entry2 (cons (car conversions) (car entry2)))) | |
514 (setq conversions (cdr conversions)))) | |
515 (set-nested-alist (car entry) (cdr entry) map))) | |
516 (setq l (cdr l))) | |
517 (setcar map longest) | |
518 map))) | |
519 | |
520 (defmacro skkdic-set-prefix (&rest entries) | |
521 `(defconst skkdic-prefix | |
522 ',(let ((l entries) | |
523 (map '(nil)) | |
524 (longest 1) | |
525 len entry) | |
526 (while l | |
527 (setq entry (skkdic-extract-conversion-data (car l))) | |
528 (setq len (length (car entry))) | |
529 (if (> len longest) | |
530 (setq longest len)) | |
531 (let ((entry2 (lookup-nested-alist (car entry) map len nil t))) | |
532 (if (consp (car entry2)) | |
533 (let ((conversions (cdr entry))) | |
534 (while conversions | |
535 (if (not (member (car conversions) (car entry2))) | |
536 (setcar entry2 (cons (car conversions) (car entry2)))) | |
537 (setq conversions (cdr conversions)))) | |
538 (set-nested-alist (car entry) (cdr entry) map len))) | |
539 (setq l (cdr l))) | |
540 (setcar map longest) | |
541 map))) | |
542 | |
543 (defmacro skkdic-set-okuri-nasi (&rest entries) | |
544 `(defconst skkdic-okuri-nasi | |
545 ',(let ((l entries) | |
546 (map '(skdic-okuri-nasi)) | |
547 (count 0) | |
548 entry) | |
549 (while l | |
550 (setq count (1+ count)) | |
551 (if (= (% count 10) 0) | |
552 (message (format "%d entries" count))) | |
553 (setq entry (skkdic-extract-conversion-data (car l))) | |
554 (set-nested-alist (car entry) (cdr entry) map) | |
555 (setq l (cdr l))) | |
556 map))) | |
557 | |
24440 | 558 (provide 'skkdic-cnv) |
559 | |
17052 | 560 ;; skkdic-cnv.el ends here |