17052
|
1 ;; skkdic-utl.el -- utility functions for handling skkdic.el
|
|
2
|
|
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
|
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
|
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;; SKK is a free Japanese input method running on Mule created by
|
|
27 ;; Masahiko Sato <masahiko@sato.riec.tohoku.ac.jp>. A dictionary of
|
|
28 ;; SKK can be converted by `skkdic-convert' (skkdic-conv.el) to a file
|
|
29 ;; "skkdic.el" in which the dictionary entries are defined in the
|
|
30 ;; format which can be handled by the following functions.
|
|
31
|
|
32 ;;; Code:
|
|
33
|
|
34 (defvar skkdic-okuri-ari nil
|
|
35 "OKURI-ARI entries of SKK dictionary.")
|
|
36 (defvar skkdic-postfix nil
|
|
37 "POSTFIX entries of SKK dictionary.")
|
|
38 (defvar skkdic-prefix nil
|
|
39 "PREFIX entries of SKK dictionary.")
|
|
40 (defvar skkdic-okuri-nasi nil
|
|
41 "OKURI-NASI entries of SKK dictionary.")
|
|
42
|
|
43 ;; Alist of Okuriganas vs trailing ASCII letters in OKURI-ARI entry.
|
|
44 (defconst skkdic-okurigana-table
|
|
45 '((?$B$!(B . ?a) (?$B$"(B . ?a) (?$B$#(B . ?i) (?$B$$(B . ?i) (?$B$%(B . ?u)
|
|
46 (?$B$&(B . ?u) (?$B$'(B . ?e) (?$B$((B . ?e) (?$B$)(B . ?o) (?$B$*(B . ?o)
|
|
47 (?$B$+(B . ?k) (?$B$,(B . ?g) (?$B$-(B . ?k) (?$B$.(B . ?g) (?$B$/(B . ?k)
|
|
48 (?$B$0(B . ?g) (?$B$1(B . ?k) (?$B$2(B . ?g) (?$B$3(B . ?k) (?$B$4(B . ?g)
|
|
49 (?$B$5(B . ?s) (?$B$6(B . ?z) (?$B$7(B . ?s) (?$B$8(B . ?j) (?$B$9(B . ?s)
|
|
50 (?$B$:(B . ?z) (?$B$;(B . ?s) (?$B$<(B . ?z) (?$B$=(B . ?s) (?$B$>(B . ?z)
|
|
51 (?$B$?(B . ?t) (?$B$@(B . ?d) (?$B$A(B . ?t) (?$B$B(B . ?d) (?$B$C(B . ?t)
|
|
52 (?$B$D(B . ?t) (?$B$E(B . ?d) (?$B$F(B . ?t) (?$B$G(B . ?d) (?$B$H(B . ?t) (?$B$I(B . ?d)
|
|
53 (?$B$J(B . ?n) (?$B$K(B . ?n) (?$B$L(B . ?n) (?$B$M(B . ?n) (?$B$N(B . ?n)
|
|
54 (?$B$O(B . ?h) (?$B$P(B . ?b) (?$B$Q(B . ?p) (?$B$R(B . ?h) (?$B$S(B . ?b)
|
|
55 (?$B$T(B . ?p) (?$B$U(B . ?h) (?$B$V(B . ?b) (?$B$W(B . ?p) (?$B$X(B . ?h)
|
|
56 (?$B$Y(B . ?b) (?$B$Z(B . ?p) (?$B$[(B . ?h) (?$B$\(B . ?b) (?$B$](B . ?p)
|
|
57 (?$B$^(B . ?m) (?$B$_(B . ?m) (?$B$`(B . ?m) (?$B$a(B . ?m) (?$B$b(B . ?m)
|
|
58 (?$B$c(B . ?y) (?$B$d(B . ?y) (?$B$e(B . ?y) (?$B$f(B . ?y) (?$B$g(B . ?y) (?$B$h(B . ?y)
|
|
59 (?$B$i(B . ?r) (?$B$j(B . ?r) (?$B$k(B . ?r) (?$B$l(B . ?r) (?$B$m(B . ?r)
|
|
60 (?$B$o(B . ?w) (?$B$p(B . ?w) (?$B$q(B . ?w) (?$B$r(B . ?w)
|
|
61 (?$B$s(B . ?n)
|
|
62 ))
|
|
63
|
|
64 (defconst skkdic-jbytes
|
|
65 (charset-bytes 'japanese-jisx0208))
|
|
66
|
|
67 (defun skkdic-merge-head-and-tail (heads tails postfix)
|
|
68 (let ((min-len (* skkdic-jbytes 2))
|
|
69 l)
|
|
70 (while heads
|
|
71 (if (or (not postfix)
|
|
72 (>= (length (car heads)) min-len))
|
|
73 (let ((tail tails))
|
|
74 (while tail
|
|
75 (if (or postfix
|
|
76 (>= (length (car tail)) min-len))
|
|
77 (setq l (cons (concat (car heads) (car tail)) l)))
|
|
78 (setq tail (cdr tail)))))
|
|
79 (setq heads (cdr heads)))
|
|
80 l))
|
|
81
|
|
82 (defconst skkdic-jisx0208-hiragana-block (nth 1 (split-char ?$B$"(B)))
|
|
83
|
|
84 (defun skkdic-lookup-key (seq len &optional postfix)
|
|
85 "Return a list of conversion string for sequence SEQ of length LEN.
|
|
86
|
|
87 SEQ is a vector of Kana characters to be converted by SKK dictionary.
|
|
88 If LEN is shorter than the length of KEYSEQ, the first LEN keys in SEQ
|
|
89 are took into account.
|
|
90
|
|
91 Postfixes are handled only if the optional argument POSTFIX is non-nil."
|
|
92 (or skkdic-okuri-nasi
|
|
93 (condition-case err
|
|
94 (load-library "skk/skkdic")
|
|
95 (error (ding)
|
|
96 (with-output-to-temp-buffer "*Help*"
|
|
97 (princ "The library `skkdic' can't be loaded.
|
|
98
|
|
99 The most common case is that you have not yet installed the library
|
|
100 included in LEIM (Libraries of Emacs Input Method) which is
|
|
101 distributed separately from Emacs.
|
|
102
|
|
103 LEIM is available from the same ftp directory as Emacs."))
|
|
104 (signal (car err) (cdr err)))))
|
|
105
|
|
106 (let ((vec (make-vector len 0))
|
|
107 (i 0)
|
|
108 entry)
|
|
109 ;; At first, generate vector VEC from SEQ for looking up SKK
|
|
110 ;; alists. Nth element in VEC corresponds to Nth element in SEQ.
|
|
111 ;; The values are decided as follows.
|
|
112 ;; If SEQ[N] is `$B!<(B', VEC[N] is 0,
|
|
113 ;; Else if SEQ[N] is a Hiragana character, VEC[N] is:
|
|
114 ;; ((The 2nd position code o SEQ[N]) - 32),
|
|
115 ;; ELse VEC[N] is 128.
|
|
116 (while (< i len)
|
|
117 (let ((ch (aref seq i))
|
|
118 elts)
|
|
119 (if (= ch ?$B!<(B)
|
|
120 (aset vec i 0)
|
|
121 (setq elts (split-char ch))
|
|
122 (if (and (eq (car elts) 'japanese-jisx0208)
|
|
123 (= (nth 1 elts) skkdic-jisx0208-hiragana-block))
|
|
124 (aset vec i (- (nth 2 elts) 32))
|
|
125 (aset vec i 128))))
|
|
126 (setq i (1+ i)))
|
|
127
|
|
128 ;; Search OKURI-NASI entries.
|
|
129 (setq entry (lookup-nested-alist vec skkdic-okuri-nasi len 0 t))
|
|
130 (if (consp (car entry))
|
|
131 (setq entry (copy-sequence (car entry)))
|
|
132 (setq entry nil))
|
|
133
|
|
134 (if postfix
|
|
135 ;; Search OKURI-NASI entries with postfixes.
|
|
136 (let ((break (max (- len (car skkdic-postfix)) 1))
|
|
137 entry-head entry-postfix entry2)
|
|
138 (while (< break len)
|
|
139 (if (and (setq entry-head
|
|
140 (lookup-nested-alist vec skkdic-okuri-nasi
|
|
141 break 0 t))
|
|
142 (consp (car entry-head))
|
|
143 (setq entry-postfix
|
|
144 (lookup-nested-alist vec skkdic-postfix
|
|
145 len break t))
|
|
146 (consp (car entry-postfix))
|
|
147 (setq entry2 (skkdic-merge-head-and-tail
|
|
148 (car entry-head) (car entry-postfix) t)))
|
|
149 (if entry
|
|
150 (nconc entry entry2)
|
|
151 (setq entry entry2)))
|
|
152 (setq break (1+ break)))))
|
|
153
|
|
154 ;; Search OKURI-NASI entries with prefixes.
|
|
155 (let ((break (min (car skkdic-prefix) (- len 2)))
|
|
156 entry-prefix entry-tail entry2)
|
|
157 (while (> break 0)
|
|
158 (if (and (setq entry-prefix
|
|
159 (lookup-nested-alist vec skkdic-prefix break 0 t))
|
|
160 (consp (car entry-prefix))
|
|
161 (setq entry-tail
|
|
162 (lookup-nested-alist vec skkdic-okuri-nasi len break t))
|
|
163 (consp (car entry-tail))
|
|
164 (setq entry2 (skkdic-merge-head-and-tail
|
|
165 (car entry-prefix) (car entry-tail) nil)))
|
|
166 (if entry
|
|
167 (nconc entry entry2)
|
|
168 (setq entry entry2)))
|
|
169 (setq break (1- break))))
|
|
170
|
|
171 ;; Search OKURI-ARI entries.
|
|
172 (let ((okurigana (assq (aref seq (1- len)) skkdic-okurigana-table))
|
|
173 orig-element entry2)
|
|
174 (if okurigana
|
|
175 (progn
|
|
176 (setq orig-element (aref vec (1- len)))
|
|
177 (aset vec (1- len) (- (cdr okurigana)))
|
|
178 (if (and (setq entry2 (lookup-nested-alist vec skkdic-okuri-ari
|
|
179 len 0 t))
|
|
180 (consp (car entry2)))
|
|
181 (progn
|
|
182 (setq entry2 (copy-sequence (car entry2)))
|
|
183 (let ((l entry2)
|
|
184 (okuri (char-to-string (aref seq (1- len)))))
|
|
185 (while l
|
|
186 (setcar l (concat (car l) okuri))
|
|
187 (setq l (cdr l)))
|
|
188 (if entry
|
|
189 (nconc entry entry2)
|
|
190 (setq entry entry2)))))
|
|
191 (aset vec (1- len) orig-element))))
|
|
192
|
|
193 entry))
|
|
194
|
|
195 ;;
|
|
196 (provide 'skkdic-utl)
|
|
197
|
|
198 ;; skkdic-utl.el ends here
|