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