Mercurial > emacs
annotate lisp/international/skkdic-utl.el @ 20383:3a76b48c399d
1997-11-27 Richard Stallman <rms@sucrose.ai.mit.edu>
* dired.el (dired-move-to-filename-regexp): Make regexp fussier
about amount of whitespace after month name.
author | Joel N. Weber II <devnull@gnu.org> |
---|---|
date | Sat, 29 Nov 1997 05:21:18 +0000 |
parents | d290e793b965 |
children | 60bf060b9ab1 |
rev | line source |
---|---|
17315
a3ca5e15c82a
Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1 ;;; skkdic-utl.el --- Utility functions for handling SKK dictionary |
17052 | 2 |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
17315
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 free Japanese input method running on Mule created by | |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
28 ;; Masahiko Sato <masahiko@sato.riec.tohoku.ac.jp>. The Emacs Lisp |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
29 ;; library kkc.el provides a facility to convert a Japanese kana |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
30 ;; string to a kanji-kana-mixed string by using a SKK dictionary. |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
31 ;; |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
32 ;; This file provides a generic function to look up a SKK dictionary. |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
33 ;; |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
34 ;; The original SKK dictionary SKK-JISYO.L is converted to skkdic.el. |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
35 ;; We get entries of the dictionary in four variables (listed below) |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
36 ;; by loadig this file (or byte-compiled version skkdic.elc). |
17052 | 37 |
38 ;;; Code: | |
39 | |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
40 ;; The following four variables are set by loading skkdic.el[c]. |
17052 | 41 (defvar skkdic-okuri-ari nil |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
42 "Nested alist for OKURI-ARI entries of SKK dictionary.") |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
43 |
17052 | 44 (defvar skkdic-postfix nil |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
45 "Nested alist for SETSUBIJI (postfix) entries of SKK dictionary.") |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
46 |
17052 | 47 (defvar skkdic-prefix nil |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
48 "Nested alist SETTOUJI (prefix) entries of SKK dictionary.") |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
49 |
17052 | 50 (defvar skkdic-okuri-nasi nil |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
51 "Nested alist for OKURI-NASI entries of SKK dictionary.") |
17052 | 52 |
53 (defconst skkdic-okurigana-table | |
54 '((?$B$!(B . ?a) (?$B$"(B . ?a) (?$B$#(B . ?i) (?$B$$(B . ?i) (?$B$%(B . ?u) | |
55 (?$B$&(B . ?u) (?$B$'(B . ?e) (?$B$((B . ?e) (?$B$)(B . ?o) (?$B$*(B . ?o) | |
56 (?$B$+(B . ?k) (?$B$,(B . ?g) (?$B$-(B . ?k) (?$B$.(B . ?g) (?$B$/(B . ?k) | |
57 (?$B$0(B . ?g) (?$B$1(B . ?k) (?$B$2(B . ?g) (?$B$3(B . ?k) (?$B$4(B . ?g) | |
58 (?$B$5(B . ?s) (?$B$6(B . ?z) (?$B$7(B . ?s) (?$B$8(B . ?j) (?$B$9(B . ?s) | |
59 (?$B$:(B . ?z) (?$B$;(B . ?s) (?$B$<(B . ?z) (?$B$=(B . ?s) (?$B$>(B . ?z) | |
60 (?$B$?(B . ?t) (?$B$@(B . ?d) (?$B$A(B . ?t) (?$B$B(B . ?d) (?$B$C(B . ?t) | |
61 (?$B$D(B . ?t) (?$B$E(B . ?d) (?$B$F(B . ?t) (?$B$G(B . ?d) (?$B$H(B . ?t) (?$B$I(B . ?d) | |
62 (?$B$J(B . ?n) (?$B$K(B . ?n) (?$B$L(B . ?n) (?$B$M(B . ?n) (?$B$N(B . ?n) | |
63 (?$B$O(B . ?h) (?$B$P(B . ?b) (?$B$Q(B . ?p) (?$B$R(B . ?h) (?$B$S(B . ?b) | |
64 (?$B$T(B . ?p) (?$B$U(B . ?h) (?$B$V(B . ?b) (?$B$W(B . ?p) (?$B$X(B . ?h) | |
65 (?$B$Y(B . ?b) (?$B$Z(B . ?p) (?$B$[(B . ?h) (?$B$\(B . ?b) (?$B$](B . ?p) | |
66 (?$B$^(B . ?m) (?$B$_(B . ?m) (?$B$`(B . ?m) (?$B$a(B . ?m) (?$B$b(B . ?m) | |
67 (?$B$c(B . ?y) (?$B$d(B . ?y) (?$B$e(B . ?y) (?$B$f(B . ?y) (?$B$g(B . ?y) (?$B$h(B . ?y) | |
68 (?$B$i(B . ?r) (?$B$j(B . ?r) (?$B$k(B . ?r) (?$B$l(B . ?r) (?$B$m(B . ?r) | |
69 (?$B$o(B . ?w) (?$B$p(B . ?w) (?$B$q(B . ?w) (?$B$r(B . ?w) | |
70 (?$B$s(B . ?n) | |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
71 ) |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
72 "Alist of Okuriganas vs trailing ASCII letters in OKURI-ARI entry.") |
17052 | 73 |
74 (defconst skkdic-jbytes | |
75 (charset-bytes 'japanese-jisx0208)) | |
76 | |
77 (defun skkdic-merge-head-and-tail (heads tails postfix) | |
78 (let ((min-len (* skkdic-jbytes 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 | |
92 (defconst skkdic-jisx0208-hiragana-block (nth 1 (split-char ?$B$"(B))) | |
93 | |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
94 (defun skkdic-lookup-key (seq len &optional postfix prefer-noun) |
17052 | 95 "Return a list of conversion string for sequence SEQ of length LEN. |
96 | |
97 SEQ is a vector of Kana characters to be converted by SKK dictionary. | |
98 If LEN is shorter than the length of KEYSEQ, the first LEN keys in SEQ | |
99 are took into account. | |
100 | |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
101 Optional 3rd arg POSTFIX non-nil means SETSUBIJI (postfix) are also |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
102 considered to find conversion strings. |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
103 |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
104 Optional 4th arg PREFER-NOUN non-nil means that the conversions |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
105 without okurigana are placed at the head of the returned list." |
17052 | 106 (or skkdic-okuri-nasi |
107 (condition-case err | |
108 (load-library "skk/skkdic") | |
109 (error (ding) | |
110 (with-output-to-temp-buffer "*Help*" | |
111 (princ "The library `skkdic' can't be loaded. | |
112 | |
113 The most common case is that you have not yet installed the library | |
114 included in LEIM (Libraries of Emacs Input Method) which is | |
115 distributed separately from Emacs. | |
116 | |
117 LEIM is available from the same ftp directory as Emacs.")) | |
118 (signal (car err) (cdr err))))) | |
119 | |
120 (let ((vec (make-vector len 0)) | |
121 (i 0) | |
122 entry) | |
123 ;; At first, generate vector VEC from SEQ for looking up SKK | |
124 ;; alists. Nth element in VEC corresponds to Nth element in SEQ. | |
125 ;; The values are decided as follows. | |
126 ;; If SEQ[N] is `$B!<(B', VEC[N] is 0, | |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
127 ;; else if SEQ[N] is a Hiragana character, VEC[N] is: |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
128 ;; ((The 2nd position code of SEQ[N]) - 32), |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
129 ;; else VEC[N] is 128. |
17052 | 130 (while (< i len) |
131 (let ((ch (aref seq i)) | |
132 elts) | |
133 (if (= ch ?$B!<(B) | |
134 (aset vec i 0) | |
135 (setq elts (split-char ch)) | |
136 (if (and (eq (car elts) 'japanese-jisx0208) | |
137 (= (nth 1 elts) skkdic-jisx0208-hiragana-block)) | |
138 (aset vec i (- (nth 2 elts) 32)) | |
139 (aset vec i 128)))) | |
140 (setq i (1+ i))) | |
141 | |
142 ;; Search OKURI-NASI entries. | |
143 (setq entry (lookup-nested-alist vec skkdic-okuri-nasi len 0 t)) | |
144 (if (consp (car entry)) | |
145 (setq entry (copy-sequence (car entry))) | |
146 (setq entry nil)) | |
147 | |
148 (if postfix | |
149 ;; Search OKURI-NASI entries with postfixes. | |
150 (let ((break (max (- len (car skkdic-postfix)) 1)) | |
151 entry-head entry-postfix entry2) | |
152 (while (< break len) | |
153 (if (and (setq entry-head | |
154 (lookup-nested-alist vec skkdic-okuri-nasi | |
155 break 0 t)) | |
156 (consp (car entry-head)) | |
157 (setq entry-postfix | |
158 (lookup-nested-alist vec skkdic-postfix | |
159 len break t)) | |
160 (consp (car entry-postfix)) | |
161 (setq entry2 (skkdic-merge-head-and-tail | |
162 (car entry-head) (car entry-postfix) t))) | |
163 (if entry | |
164 (nconc entry entry2) | |
165 (setq entry entry2))) | |
166 (setq break (1+ break))))) | |
167 | |
168 ;; Search OKURI-NASI entries with prefixes. | |
169 (let ((break (min (car skkdic-prefix) (- len 2))) | |
170 entry-prefix entry-tail entry2) | |
171 (while (> break 0) | |
172 (if (and (setq entry-prefix | |
173 (lookup-nested-alist vec skkdic-prefix break 0 t)) | |
174 (consp (car entry-prefix)) | |
175 (setq entry-tail | |
176 (lookup-nested-alist vec skkdic-okuri-nasi len break t)) | |
177 (consp (car entry-tail)) | |
178 (setq entry2 (skkdic-merge-head-and-tail | |
179 (car entry-prefix) (car entry-tail) nil))) | |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
180 (progn |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
181 (if entry |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
182 (nconc entry entry2) |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
183 (setq entry entry2)))) |
17052 | 184 (setq break (1- break)))) |
185 | |
186 ;; Search OKURI-ARI entries. | |
187 (let ((okurigana (assq (aref seq (1- len)) skkdic-okurigana-table)) | |
188 orig-element entry2) | |
189 (if okurigana | |
190 (progn | |
191 (setq orig-element (aref vec (1- len))) | |
192 (aset vec (1- len) (- (cdr okurigana))) | |
193 (if (and (setq entry2 (lookup-nested-alist vec skkdic-okuri-ari | |
194 len 0 t)) | |
195 (consp (car entry2))) | |
196 (progn | |
197 (setq entry2 (copy-sequence (car entry2))) | |
198 (let ((l entry2) | |
199 (okuri (char-to-string (aref seq (1- len))))) | |
200 (while l | |
201 (setcar l (concat (car l) okuri)) | |
202 (setq l (cdr l))) | |
203 (if entry | |
18645
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
204 (if prefer-noun |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
205 (nconc entry entry2) |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
206 (setq entry2 (nreverse entry2)) |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
207 (nconc entry2 entry) |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
208 (setq entry entry2)) |
d290e793b965
(skkdic-okuri-ari): Doc-string
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
209 (setq entry (nreverse entry2)))))) |
17052 | 210 (aset vec (1- len) orig-element)))) |
211 | |
212 entry)) | |
213 | |
214 ;; | |
215 (provide 'skkdic-utl) | |
216 | |
217 ;; skkdic-utl.el ends here |