Mercurial > emacs
annotate lisp/international/ja-dic-utl.el @ 91842:2ac341f3fba9
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 14 Feb 2008 14:37:00 +0000 |
parents | 606f2d163a64 |
children | 1e3a407766b9 |
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 |
74605
6ee41fdd69ff
Update AIST copyright years.
Kenichi Handa <handa@m17n.org>
parents:
74544
diff
changeset
|
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
79709 | 4 ;; 2005, 2006, 2007, 2008 |
62274 | 5 ;; National Institute of Advanced Industrial Science and Technology (AIST) |
6 ;; Registration Number H14PRO021 | |
31163 | 7 |
8 ;; Keywords: mule, multilingual, Japanese | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
78310
2daf9c28b3a4
Restore comma mistakenly removed in last change.
Glenn Morris <rgm@gnu.org>
parents:
78301
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
31163 | 15 ;; any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
31163 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; This file provides a generic function to look up a Japanese | |
30 ;; dictionary of SKK format. | |
31 ;; | |
32 ;; SKK is a free Japanese input method running on Mule created by | |
33 ;; Masahiko Sato <masahiko@sato.riec.tohoku.ac.jp>. The Emacs Lisp | |
34 ;; library kkc.el provides a facility to convert a Japanese kana | |
35 ;; string to a kanji-kana-mixed string by using SKK's dictionary. | |
36 ;; | |
37 ;; The original SKK dictionary SKK-JISYO.L is converted to ja-dic.el | |
38 ;; by ja-dic-cnv.el. We get entries of the dictionary in four | |
39 ;; variables (listed below) by loading that file (or byte-compiled | |
40 ;; version ja-dic.elc). | |
41 | |
42 ;;; Code: | |
43 | |
44 ;; The following four variables are set by loading ja-dic.el[c]. | |
45 (defvar skkdic-okuri-ari nil | |
46 "Nested alist for OKURI-ARI entries of SKK dictionary.") | |
47 | |
48 (defvar skkdic-postfix nil | |
49 "Nested alist for SETSUBIJI (postfix) entries of SKK dictionary.") | |
50 | |
51 (defvar skkdic-prefix nil | |
52 "Nested alist SETTOUJI (prefix) entries of SKK dictionary.") | |
53 | |
54 (defvar skkdic-okuri-nasi nil | |
55 "Nested alist for OKURI-NASI entries of SKK dictionary.") | |
56 | |
57 (defconst skkdic-okurigana-table | |
58 '((?$B$!(B . ?a) (?$B$"(B . ?a) (?$B$#(B . ?i) (?$B$$(B . ?i) (?$B$%(B . ?u) | |
59 (?$B$&(B . ?u) (?$B$'(B . ?e) (?$B$((B . ?e) (?$B$)(B . ?o) (?$B$*(B . ?o) | |
60 (?$B$+(B . ?k) (?$B$,(B . ?g) (?$B$-(B . ?k) (?$B$.(B . ?g) (?$B$/(B . ?k) | |
61 (?$B$0(B . ?g) (?$B$1(B . ?k) (?$B$2(B . ?g) (?$B$3(B . ?k) (?$B$4(B . ?g) | |
62 (?$B$5(B . ?s) (?$B$6(B . ?z) (?$B$7(B . ?s) (?$B$8(B . ?j) (?$B$9(B . ?s) | |
63 (?$B$:(B . ?z) (?$B$;(B . ?s) (?$B$<(B . ?z) (?$B$=(B . ?s) (?$B$>(B . ?z) | |
64 (?$B$?(B . ?t) (?$B$@(B . ?d) (?$B$A(B . ?t) (?$B$B(B . ?d) (?$B$C(B . ?t) | |
65 (?$B$D(B . ?t) (?$B$E(B . ?d) (?$B$F(B . ?t) (?$B$G(B . ?d) (?$B$H(B . ?t) (?$B$I(B . ?d) | |
66 (?$B$J(B . ?n) (?$B$K(B . ?n) (?$B$L(B . ?n) (?$B$M(B . ?n) (?$B$N(B . ?n) | |
67 (?$B$O(B . ?h) (?$B$P(B . ?b) (?$B$Q(B . ?p) (?$B$R(B . ?h) (?$B$S(B . ?b) | |
68 (?$B$T(B . ?p) (?$B$U(B . ?h) (?$B$V(B . ?b) (?$B$W(B . ?p) (?$B$X(B . ?h) | |
69 (?$B$Y(B . ?b) (?$B$Z(B . ?p) (?$B$[(B . ?h) (?$B$\(B . ?b) (?$B$](B . ?p) | |
70 (?$B$^(B . ?m) (?$B$_(B . ?m) (?$B$`(B . ?m) (?$B$a(B . ?m) (?$B$b(B . ?m) | |
71 (?$B$c(B . ?y) (?$B$d(B . ?y) (?$B$e(B . ?y) (?$B$f(B . ?y) (?$B$g(B . ?y) (?$B$h(B . ?y) | |
72 (?$B$i(B . ?r) (?$B$j(B . ?r) (?$B$k(B . ?r) (?$B$l(B . ?r) (?$B$m(B . ?r) | |
73 (?$B$o(B . ?w) (?$B$p(B . ?w) (?$B$q(B . ?w) (?$B$r(B . ?w) | |
74 (?$B$s(B . ?n) | |
75 ) | |
76 "Alist of Okuriganas vs trailing ASCII letters in OKURI-ARI entry.") | |
77 | |
78 (defun skkdic-merge-head-and-tail (heads tails postfix) | |
79 (let ((min-len 2) | |
80 l) | |
81 (while heads | |
82 (if (or (not postfix) | |
83 (>= (length (car heads)) min-len)) | |
84 (let ((tail tails)) | |
85 (while tail | |
86 (if (or postfix | |
87 (>= (length (car tail)) min-len)) | |
88 (setq l (cons (concat (car heads) (car tail)) l))) | |
89 (setq tail (cdr tail))))) | |
90 (setq heads (cdr heads))) | |
91 l)) | |
92 | |
88518
914548535d25
(skkdic-jisx0208-hiragana-block):
Kenichi Handa <handa@m17n.org>
parents:
88407
diff
changeset
|
93 (defconst skkdic-jisx0208-hiragana-block |
914548535d25
(skkdic-jisx0208-hiragana-block):
Kenichi Handa <handa@m17n.org>
parents:
88407
diff
changeset
|
94 (cons (decode-char 'japanese-jisx0208 #x2421) |
914548535d25
(skkdic-jisx0208-hiragana-block):
Kenichi Handa <handa@m17n.org>
parents:
88407
diff
changeset
|
95 (decode-char 'japanese-jisx0208 #x247E))) |
31163 | 96 |
97 (defun skkdic-lookup-key (seq len &optional postfix prefer-noun) | |
98 "Return a list of conversion string for sequence SEQ of length LEN. | |
99 | |
100 SEQ is a vector of Kana characters to be converted by SKK dictionary. | |
101 If LEN is shorter than the length of KEYSEQ, the first LEN keys in SEQ | |
102 are took into account. | |
103 | |
104 Optional 3rd arg POSTFIX non-nil means SETSUBIJI (postfix) are also | |
105 considered to find conversion strings. | |
106 | |
107 Optional 4th arg PREFER-NOUN non-nil means that the conversions | |
108 without okurigana are placed at the head of the returned list." | |
109 (or skkdic-okuri-nasi | |
110 (condition-case err | |
111 (load-library "ja-dic/ja-dic") | |
112 (error (ding) | |
113 (with-output-to-temp-buffer "*Help*" | |
114 (princ "The library `ja-dic' can't be loaded. | |
115 | |
116 The most common case is that you have not yet installed the library | |
117 included in LEIM (Libraries of Emacs Input Method) which is | |
118 distributed separately from Emacs. | |
119 | |
120 LEIM is available from the same ftp directory as Emacs.")) | |
121 (signal (car err) (cdr err))))) | |
122 | |
123 (let ((vec (make-vector len 0)) | |
124 (i 0) | |
125 entry) | |
126 ;; At first, generate vector VEC from SEQ for looking up SKK | |
127 ;; alists. Nth element in VEC corresponds to Nth element in SEQ. | |
128 ;; The values are decided as follows. | |
129 ;; If SEQ[N] is `$B!<(B', VEC[N] is 0, | |
130 ;; else if SEQ[N] is a Hiragana character, VEC[N] is: | |
131 ;; ((The 2nd position code of SEQ[N]) - 32), | |
132 ;; else VEC[N] is 128. | |
133 (while (< i len) | |
134 (let ((ch (aref seq i)) | |
88407
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
135 code) |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
136 (cond ((= ch ?$B!<(B) |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
137 (aset vec i 0)) |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
138 ((and (>= ch (car skkdic-jisx0208-hiragana-block)) |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
139 (<= ch (cdr skkdic-jisx0208-hiragana-block))) |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
140 (setq code (encode-char ch 'japanese-jisx0208)) |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
141 (if code |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
142 (aset vec i (- (logand code #xFF) 32)) |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
143 (aset vec i 128))) |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
144 (t |
9ae36aa886d5
(skkdic-jisx0208-hiragana-block): Value changed.
Kenichi Handa <handa@m17n.org>
parents:
38414
diff
changeset
|
145 (aset vec i 128)))) |
31163 | 146 (setq i (1+ i))) |
147 | |
148 ;; Search OKURI-NASI entries. | |
149 (setq entry (lookup-nested-alist vec skkdic-okuri-nasi len 0 t)) | |
150 (if (consp (car entry)) | |
151 (setq entry (copy-sequence (car entry))) | |
152 (setq entry nil)) | |
153 | |
154 (if postfix | |
155 ;; Search OKURI-NASI entries with postfixes. | |
156 (let ((break (max (- len (car skkdic-postfix)) 1)) | |
157 entry-head entry-postfix entry2) | |
158 (while (< break len) | |
159 (if (and (setq entry-head | |
160 (lookup-nested-alist vec skkdic-okuri-nasi | |
161 break 0 t)) | |
162 (consp (car entry-head)) | |
163 (setq entry-postfix | |
164 (lookup-nested-alist vec skkdic-postfix | |
165 len break t)) | |
166 (consp (car entry-postfix)) | |
167 (setq entry2 (skkdic-merge-head-and-tail | |
168 (car entry-head) (car entry-postfix) t))) | |
169 (if entry | |
170 (nconc entry entry2) | |
171 (setq entry entry2))) | |
172 (setq break (1+ break))))) | |
173 | |
174 ;; Search OKURI-NASI entries with prefixes. | |
175 (let ((break (min (car skkdic-prefix) (- len 2))) | |
176 entry-prefix entry-tail entry2) | |
177 (while (> break 0) | |
178 (if (and (setq entry-prefix | |
179 (lookup-nested-alist vec skkdic-prefix break 0 t)) | |
180 (consp (car entry-prefix)) | |
181 (setq entry-tail | |
182 (lookup-nested-alist vec skkdic-okuri-nasi len break t)) | |
183 (consp (car entry-tail)) | |
184 (setq entry2 (skkdic-merge-head-and-tail | |
185 (car entry-prefix) (car entry-tail) nil))) | |
186 (progn | |
187 (if entry | |
188 (nconc entry entry2) | |
189 (setq entry entry2)))) | |
190 (setq break (1- break)))) | |
191 | |
192 ;; Search OKURI-ARI entries. | |
193 (let ((okurigana (assq (aref seq (1- len)) skkdic-okurigana-table)) | |
194 orig-element entry2) | |
195 (if okurigana | |
196 (progn | |
197 (setq orig-element (aref vec (1- len))) | |
198 (aset vec (1- len) (- (cdr okurigana))) | |
199 (if (and (setq entry2 (lookup-nested-alist vec skkdic-okuri-ari | |
200 len 0 t)) | |
201 (consp (car entry2))) | |
202 (progn | |
203 (setq entry2 (copy-sequence (car entry2))) | |
204 (let ((l entry2) | |
205 (okuri (char-to-string (aref seq (1- len))))) | |
206 (while l | |
207 (setcar l (concat (car l) okuri)) | |
208 (setq l (cdr l))) | |
209 (if entry | |
210 (if prefer-noun | |
211 (nconc entry entry2) | |
212 (setq entry2 (nreverse entry2)) | |
213 (nconc entry2 entry) | |
214 (setq entry entry2)) | |
215 (setq entry (nreverse entry2)))))) | |
216 (aset vec (1- len) orig-element)))) | |
217 | |
218 entry)) | |
219 | |
220 ;; | |
221 (provide 'ja-dic-utl) | |
222 | |
36682
8adcbdf9202c
Add coding: tag in Local Variable: section.
Kenichi Handa <handa@m17n.org>
parents:
31163
diff
changeset
|
223 ;; Local Variables: |
8adcbdf9202c
Add coding: tag in Local Variable: section.
Kenichi Handa <handa@m17n.org>
parents:
31163
diff
changeset
|
224 ;; coding: iso-2022-7bit |
8adcbdf9202c
Add coding: tag in Local Variable: section.
Kenichi Handa <handa@m17n.org>
parents:
31163
diff
changeset
|
225 ;; End: |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36682
diff
changeset
|
226 |
52401 | 227 ;;; arch-tag: df2218fa-469c-40f6-bace-7f89a053f9c0 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36682
diff
changeset
|
228 ;;; ja-dic-utl.el ends here |