Mercurial > emacs
annotate lisp/international/ja-dic-utl.el @ 39364:bd687d055024
(Info-file-list-for-emacs): Add elements for ada-mode, ccmode,
emacs-mime, and eudc manuals.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Thu, 20 Sep 2001 15:29:14 +0000 |
parents | 67b464da13ec |
children | 695cf19ef79e d7ddb3e565de 9ae36aa886d5 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36682
diff
changeset
|
1 ;;; ja-dic-utl.el --- utilities for handling Japanese dictionary (SKK-JISYO.L) |
31163 | 2 |
3 ;; Copyright (C) 1995, 2000 Electrotechnical Laboratory, JAPAN. | |
4 ;; Licensed to the Free Software Foundation. | |
5 | |
6 ;; Keywords: mule, multilingual, Japanese | |
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 | |
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. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; This file provides a generic function to look up a Japanese | |
28 ;; dictionary of SKK format. | |
29 ;; | |
30 ;; SKK is a free Japanese input method running on Mule created by | |
31 ;; Masahiko Sato <masahiko@sato.riec.tohoku.ac.jp>. The Emacs Lisp | |
32 ;; library kkc.el provides a facility to convert a Japanese kana | |
33 ;; string to a kanji-kana-mixed string by using SKK's dictionary. | |
34 ;; | |
35 ;; The original SKK dictionary SKK-JISYO.L is converted to ja-dic.el | |
36 ;; by ja-dic-cnv.el. We get entries of the dictionary in four | |
37 ;; variables (listed below) by loading that file (or byte-compiled | |
38 ;; version ja-dic.elc). | |
39 | |
40 ;;; Code: | |
41 | |
42 ;; The following four variables are set by loading ja-dic.el[c]. | |
43 (defvar skkdic-okuri-ari nil | |
44 "Nested alist for OKURI-ARI entries of SKK dictionary.") | |
45 | |
46 (defvar skkdic-postfix nil | |
47 "Nested alist for SETSUBIJI (postfix) entries of SKK dictionary.") | |
48 | |
49 (defvar skkdic-prefix nil | |
50 "Nested alist SETTOUJI (prefix) entries of SKK dictionary.") | |
51 | |
52 (defvar skkdic-okuri-nasi nil | |
53 "Nested alist for OKURI-NASI entries of SKK dictionary.") | |
54 | |
55 (defconst skkdic-okurigana-table | |
56 '((?$B$!(B . ?a) (?$B$"(B . ?a) (?$B$#(B . ?i) (?$B$$(B . ?i) (?$B$%(B . ?u) | |
57 (?$B$&(B . ?u) (?$B$'(B . ?e) (?$B$((B . ?e) (?$B$)(B . ?o) (?$B$*(B . ?o) | |
58 (?$B$+(B . ?k) (?$B$,(B . ?g) (?$B$-(B . ?k) (?$B$.(B . ?g) (?$B$/(B . ?k) | |
59 (?$B$0(B . ?g) (?$B$1(B . ?k) (?$B$2(B . ?g) (?$B$3(B . ?k) (?$B$4(B . ?g) | |
60 (?$B$5(B . ?s) (?$B$6(B . ?z) (?$B$7(B . ?s) (?$B$8(B . ?j) (?$B$9(B . ?s) | |
61 (?$B$:(B . ?z) (?$B$;(B . ?s) (?$B$<(B . ?z) (?$B$=(B . ?s) (?$B$>(B . ?z) | |
62 (?$B$?(B . ?t) (?$B$@(B . ?d) (?$B$A(B . ?t) (?$B$B(B . ?d) (?$B$C(B . ?t) | |
63 (?$B$D(B . ?t) (?$B$E(B . ?d) (?$B$F(B . ?t) (?$B$G(B . ?d) (?$B$H(B . ?t) (?$B$I(B . ?d) | |
64 (?$B$J(B . ?n) (?$B$K(B . ?n) (?$B$L(B . ?n) (?$B$M(B . ?n) (?$B$N(B . ?n) | |
65 (?$B$O(B . ?h) (?$B$P(B . ?b) (?$B$Q(B . ?p) (?$B$R(B . ?h) (?$B$S(B . ?b) | |
66 (?$B$T(B . ?p) (?$B$U(B . ?h) (?$B$V(B . ?b) (?$B$W(B . ?p) (?$B$X(B . ?h) | |
67 (?$B$Y(B . ?b) (?$B$Z(B . ?p) (?$B$[(B . ?h) (?$B$\(B . ?b) (?$B$](B . ?p) | |
68 (?$B$^(B . ?m) (?$B$_(B . ?m) (?$B$`(B . ?m) (?$B$a(B . ?m) (?$B$b(B . ?m) | |
69 (?$B$c(B . ?y) (?$B$d(B . ?y) (?$B$e(B . ?y) (?$B$f(B . ?y) (?$B$g(B . ?y) (?$B$h(B . ?y) | |
70 (?$B$i(B . ?r) (?$B$j(B . ?r) (?$B$k(B . ?r) (?$B$l(B . ?r) (?$B$m(B . ?r) | |
71 (?$B$o(B . ?w) (?$B$p(B . ?w) (?$B$q(B . ?w) (?$B$r(B . ?w) | |
72 (?$B$s(B . ?n) | |
73 ) | |
74 "Alist of Okuriganas vs trailing ASCII letters in OKURI-ARI entry.") | |
75 | |
76 (defun skkdic-merge-head-and-tail (heads tails postfix) | |
77 (let ((min-len 2) | |
78 l) | |
79 (while heads | |
80 (if (or (not postfix) | |
81 (>= (length (car heads)) min-len)) | |
82 (let ((tail tails)) | |
83 (while tail | |
84 (if (or postfix | |
85 (>= (length (car tail)) min-len)) | |
86 (setq l (cons (concat (car heads) (car tail)) l))) | |
87 (setq tail (cdr tail))))) | |
88 (setq heads (cdr heads))) | |
89 l)) | |
90 | |
91 (defconst skkdic-jisx0208-hiragana-block (nth 1 (split-char ?$B$"(B))) | |
92 | |
93 (defun skkdic-lookup-key (seq len &optional postfix prefer-noun) | |
94 "Return a list of conversion string for sequence SEQ of length LEN. | |
95 | |
96 SEQ is a vector of Kana characters to be converted by SKK dictionary. | |
97 If LEN is shorter than the length of KEYSEQ, the first LEN keys in SEQ | |
98 are took into account. | |
99 | |
100 Optional 3rd arg POSTFIX non-nil means SETSUBIJI (postfix) are also | |
101 considered to find conversion strings. | |
102 | |
103 Optional 4th arg PREFER-NOUN non-nil means that the conversions | |
104 without okurigana are placed at the head of the returned list." | |
105 (or skkdic-okuri-nasi | |
106 (condition-case err | |
107 (load-library "ja-dic/ja-dic") | |
108 (error (ding) | |
109 (with-output-to-temp-buffer "*Help*" | |
110 (princ "The library `ja-dic' can't be loaded. | |
111 | |
112 The most common case is that you have not yet installed the library | |
113 included in LEIM (Libraries of Emacs Input Method) which is | |
114 distributed separately from Emacs. | |
115 | |
116 LEIM is available from the same ftp directory as Emacs.")) | |
117 (signal (car err) (cdr err))))) | |
118 | |
119 (let ((vec (make-vector len 0)) | |
120 (i 0) | |
121 entry) | |
122 ;; At first, generate vector VEC from SEQ for looking up SKK | |
123 ;; alists. Nth element in VEC corresponds to Nth element in SEQ. | |
124 ;; The values are decided as follows. | |
125 ;; If SEQ[N] is `$B!<(B', VEC[N] is 0, | |
126 ;; else if SEQ[N] is a Hiragana character, VEC[N] is: | |
127 ;; ((The 2nd position code of SEQ[N]) - 32), | |
128 ;; else VEC[N] is 128. | |
129 (while (< i len) | |
130 (let ((ch (aref seq i)) | |
131 elts) | |
132 (if (= ch ?$B!<(B) | |
133 (aset vec i 0) | |
134 (setq elts (split-char ch)) | |
135 (if (and (eq (car elts) 'japanese-jisx0208) | |
136 (= (nth 1 elts) skkdic-jisx0208-hiragana-block)) | |
137 (aset vec i (- (nth 2 elts) 32)) | |
138 (aset vec i 128)))) | |
139 (setq i (1+ i))) | |
140 | |
141 ;; Search OKURI-NASI entries. | |
142 (setq entry (lookup-nested-alist vec skkdic-okuri-nasi len 0 t)) | |
143 (if (consp (car entry)) | |
144 (setq entry (copy-sequence (car entry))) | |
145 (setq entry nil)) | |
146 | |
147 (if postfix | |
148 ;; Search OKURI-NASI entries with postfixes. | |
149 (let ((break (max (- len (car skkdic-postfix)) 1)) | |
150 entry-head entry-postfix entry2) | |
151 (while (< break len) | |
152 (if (and (setq entry-head | |
153 (lookup-nested-alist vec skkdic-okuri-nasi | |
154 break 0 t)) | |
155 (consp (car entry-head)) | |
156 (setq entry-postfix | |
157 (lookup-nested-alist vec skkdic-postfix | |
158 len break t)) | |
159 (consp (car entry-postfix)) | |
160 (setq entry2 (skkdic-merge-head-and-tail | |
161 (car entry-head) (car entry-postfix) t))) | |
162 (if entry | |
163 (nconc entry entry2) | |
164 (setq entry entry2))) | |
165 (setq break (1+ break))))) | |
166 | |
167 ;; Search OKURI-NASI entries with prefixes. | |
168 (let ((break (min (car skkdic-prefix) (- len 2))) | |
169 entry-prefix entry-tail entry2) | |
170 (while (> break 0) | |
171 (if (and (setq entry-prefix | |
172 (lookup-nested-alist vec skkdic-prefix break 0 t)) | |
173 (consp (car entry-prefix)) | |
174 (setq entry-tail | |
175 (lookup-nested-alist vec skkdic-okuri-nasi len break t)) | |
176 (consp (car entry-tail)) | |
177 (setq entry2 (skkdic-merge-head-and-tail | |
178 (car entry-prefix) (car entry-tail) nil))) | |
179 (progn | |
180 (if entry | |
181 (nconc entry entry2) | |
182 (setq entry entry2)))) | |
183 (setq break (1- break)))) | |
184 | |
185 ;; Search OKURI-ARI entries. | |
186 (let ((okurigana (assq (aref seq (1- len)) skkdic-okurigana-table)) | |
187 orig-element entry2) | |
188 (if okurigana | |
189 (progn | |
190 (setq orig-element (aref vec (1- len))) | |
191 (aset vec (1- len) (- (cdr okurigana))) | |
192 (if (and (setq entry2 (lookup-nested-alist vec skkdic-okuri-ari | |
193 len 0 t)) | |
194 (consp (car entry2))) | |
195 (progn | |
196 (setq entry2 (copy-sequence (car entry2))) | |
197 (let ((l entry2) | |
198 (okuri (char-to-string (aref seq (1- len))))) | |
199 (while l | |
200 (setcar l (concat (car l) okuri)) | |
201 (setq l (cdr l))) | |
202 (if entry | |
203 (if prefer-noun | |
204 (nconc entry entry2) | |
205 (setq entry2 (nreverse entry2)) | |
206 (nconc entry2 entry) | |
207 (setq entry entry2)) | |
208 (setq entry (nreverse entry2)))))) | |
209 (aset vec (1- len) orig-element)))) | |
210 | |
211 entry)) | |
212 | |
213 ;; | |
214 (provide 'ja-dic-utl) | |
215 | |
36682
8adcbdf9202c
Add coding: tag in Local Variable: section.
Kenichi Handa <handa@m17n.org>
parents:
31163
diff
changeset
|
216 ;; Local Variables: |
8adcbdf9202c
Add coding: tag in Local Variable: section.
Kenichi Handa <handa@m17n.org>
parents:
31163
diff
changeset
|
217 ;; coding: iso-2022-7bit |
8adcbdf9202c
Add coding: tag in Local Variable: section.
Kenichi Handa <handa@m17n.org>
parents:
31163
diff
changeset
|
218 ;; End: |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36682
diff
changeset
|
219 |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36682
diff
changeset
|
220 ;;; ja-dic-utl.el ends here |