comparison lisp/international/skkdic-utl.el @ 18645:d290e793b965

(skkdic-okuri-ari): Doc-string modified. (skkdic-postfix, skkdic-prefix, skkdic-okuri-nasi): Likewise. (skkdic-lookup-key): Add 4th argument PREFER-NOUN. Arrange order of returning list according to this value.
author Kenichi Handa <handa@m17n.org>
date Mon, 07 Jul 1997 00:53:02 +0000
parents 8b4a66c66dd6
children 60bf060b9ab1
comparison
equal deleted inserted replaced
18644:69c91eee7ba1 18645:d290e793b965
23 ;; Boston, MA 02111-1307, USA. 23 ;; Boston, MA 02111-1307, USA.
24 24
25 ;;; Commentary: 25 ;;; Commentary:
26 26
27 ;; SKK is a free Japanese input method running on Mule created by 27 ;; SKK is a free Japanese input method running on Mule created by
28 ;; Masahiko Sato <masahiko@sato.riec.tohoku.ac.jp>. A dictionary of 28 ;; Masahiko Sato <masahiko@sato.riec.tohoku.ac.jp>. The Emacs Lisp
29 ;; SKK can be converted by `skkdic-convert' (skkdic-conv.el) to a file 29 ;; library kkc.el provides a facility to convert a Japanese kana
30 ;; "skkdic.el" in which the dictionary entries are defined in the 30 ;; string to a kanji-kana-mixed string by using a SKK dictionary.
31 ;; format which can be handled by the following functions. 31 ;;
32 ;; This file provides a generic function to look up a SKK dictionary.
33 ;;
34 ;; The original SKK dictionary SKK-JISYO.L is converted to skkdic.el.
35 ;; We get entries of the dictionary in four variables (listed below)
36 ;; by loadig this file (or byte-compiled version skkdic.elc).
32 37
33 ;;; Code: 38 ;;; Code:
34 39
40 ;; The following four variables are set by loading skkdic.el[c].
35 (defvar skkdic-okuri-ari nil 41 (defvar skkdic-okuri-ari nil
36 "OKURI-ARI entries of SKK dictionary.") 42 "Nested alist for OKURI-ARI entries of SKK dictionary.")
43
37 (defvar skkdic-postfix nil 44 (defvar skkdic-postfix nil
38 "POSTFIX entries of SKK dictionary.") 45 "Nested alist for SETSUBIJI (postfix) entries of SKK dictionary.")
46
39 (defvar skkdic-prefix nil 47 (defvar skkdic-prefix nil
40 "PREFIX entries of SKK dictionary.") 48 "Nested alist SETTOUJI (prefix) entries of SKK dictionary.")
49
41 (defvar skkdic-okuri-nasi nil 50 (defvar skkdic-okuri-nasi nil
42 "OKURI-NASI entries of SKK dictionary.") 51 "Nested alist for OKURI-NASI entries of SKK dictionary.")
43 52
44 ;; Alist of Okuriganas vs trailing ASCII letters in OKURI-ARI entry.
45 (defconst skkdic-okurigana-table 53 (defconst skkdic-okurigana-table
46 '((?$B$!(B . ?a) (?$B$"(B . ?a) (?$B$#(B . ?i) (?$B$$(B . ?i) (?$B$%(B . ?u) 54 '((?$B$!(B . ?a) (?$B$"(B . ?a) (?$B$#(B . ?i) (?$B$$(B . ?i) (?$B$%(B . ?u)
47 (?$B$&(B . ?u) (?$B$'(B . ?e) (?$B$((B . ?e) (?$B$)(B . ?o) (?$B$*(B . ?o) 55 (?$B$&(B . ?u) (?$B$'(B . ?e) (?$B$((B . ?e) (?$B$)(B . ?o) (?$B$*(B . ?o)
48 (?$B$+(B . ?k) (?$B$,(B . ?g) (?$B$-(B . ?k) (?$B$.(B . ?g) (?$B$/(B . ?k) 56 (?$B$+(B . ?k) (?$B$,(B . ?g) (?$B$-(B . ?k) (?$B$.(B . ?g) (?$B$/(B . ?k)
49 (?$B$0(B . ?g) (?$B$1(B . ?k) (?$B$2(B . ?g) (?$B$3(B . ?k) (?$B$4(B . ?g) 57 (?$B$0(B . ?g) (?$B$1(B . ?k) (?$B$2(B . ?g) (?$B$3(B . ?k) (?$B$4(B . ?g)
58 (?$B$^(B . ?m) (?$B$_(B . ?m) (?$B$`(B . ?m) (?$B$a(B . ?m) (?$B$b(B . ?m) 66 (?$B$^(B . ?m) (?$B$_(B . ?m) (?$B$`(B . ?m) (?$B$a(B . ?m) (?$B$b(B . ?m)
59 (?$B$c(B . ?y) (?$B$d(B . ?y) (?$B$e(B . ?y) (?$B$f(B . ?y) (?$B$g(B . ?y) (?$B$h(B . ?y) 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)
60 (?$B$i(B . ?r) (?$B$j(B . ?r) (?$B$k(B . ?r) (?$B$l(B . ?r) (?$B$m(B . ?r) 68 (?$B$i(B . ?r) (?$B$j(B . ?r) (?$B$k(B . ?r) (?$B$l(B . ?r) (?$B$m(B . ?r)
61 (?$B$o(B . ?w) (?$B$p(B . ?w) (?$B$q(B . ?w) (?$B$r(B . ?w) 69 (?$B$o(B . ?w) (?$B$p(B . ?w) (?$B$q(B . ?w) (?$B$r(B . ?w)
62 (?$B$s(B . ?n) 70 (?$B$s(B . ?n)
63 )) 71 )
72 "Alist of Okuriganas vs trailing ASCII letters in OKURI-ARI entry.")
64 73
65 (defconst skkdic-jbytes 74 (defconst skkdic-jbytes
66 (charset-bytes 'japanese-jisx0208)) 75 (charset-bytes 'japanese-jisx0208))
67 76
68 (defun skkdic-merge-head-and-tail (heads tails postfix) 77 (defun skkdic-merge-head-and-tail (heads tails postfix)
80 (setq heads (cdr heads))) 89 (setq heads (cdr heads)))
81 l)) 90 l))
82 91
83 (defconst skkdic-jisx0208-hiragana-block (nth 1 (split-char ?$B$"(B))) 92 (defconst skkdic-jisx0208-hiragana-block (nth 1 (split-char ?$B$"(B)))
84 93
85 (defun skkdic-lookup-key (seq len &optional postfix) 94 (defun skkdic-lookup-key (seq len &optional postfix prefer-noun)
86 "Return a list of conversion string for sequence SEQ of length LEN. 95 "Return a list of conversion string for sequence SEQ of length LEN.
87 96
88 SEQ is a vector of Kana characters to be converted by SKK dictionary. 97 SEQ is a vector of Kana characters to be converted by SKK dictionary.
89 If LEN is shorter than the length of KEYSEQ, the first LEN keys in SEQ 98 If LEN is shorter than the length of KEYSEQ, the first LEN keys in SEQ
90 are took into account. 99 are took into account.
91 100
92 Postfixes are handled only if the optional argument POSTFIX is non-nil." 101 Optional 3rd arg POSTFIX non-nil means SETSUBIJI (postfix) are also
102 considered to find conversion strings.
103
104 Optional 4th arg PREFER-NOUN non-nil means that the conversions
105 without okurigana are placed at the head of the returned list."
93 (or skkdic-okuri-nasi 106 (or skkdic-okuri-nasi
94 (condition-case err 107 (condition-case err
95 (load-library "skk/skkdic") 108 (load-library "skk/skkdic")
96 (error (ding) 109 (error (ding)
97 (with-output-to-temp-buffer "*Help*" 110 (with-output-to-temp-buffer "*Help*"
109 entry) 122 entry)
110 ;; At first, generate vector VEC from SEQ for looking up SKK 123 ;; At first, generate vector VEC from SEQ for looking up SKK
111 ;; alists. Nth element in VEC corresponds to Nth element in SEQ. 124 ;; alists. Nth element in VEC corresponds to Nth element in SEQ.
112 ;; The values are decided as follows. 125 ;; The values are decided as follows.
113 ;; If SEQ[N] is `$B!<(B', VEC[N] is 0, 126 ;; If SEQ[N] is `$B!<(B', VEC[N] is 0,
114 ;; Else if SEQ[N] is a Hiragana character, VEC[N] is: 127 ;; else if SEQ[N] is a Hiragana character, VEC[N] is:
115 ;; ((The 2nd position code o SEQ[N]) - 32), 128 ;; ((The 2nd position code of SEQ[N]) - 32),
116 ;; ELse VEC[N] is 128. 129 ;; else VEC[N] is 128.
117 (while (< i len) 130 (while (< i len)
118 (let ((ch (aref seq i)) 131 (let ((ch (aref seq i))
119 elts) 132 elts)
120 (if (= ch ?$B!<(B) 133 (if (= ch ?$B!<(B)
121 (aset vec i 0) 134 (aset vec i 0)
162 (setq entry-tail 175 (setq entry-tail
163 (lookup-nested-alist vec skkdic-okuri-nasi len break t)) 176 (lookup-nested-alist vec skkdic-okuri-nasi len break t))
164 (consp (car entry-tail)) 177 (consp (car entry-tail))
165 (setq entry2 (skkdic-merge-head-and-tail 178 (setq entry2 (skkdic-merge-head-and-tail
166 (car entry-prefix) (car entry-tail) nil))) 179 (car entry-prefix) (car entry-tail) nil)))
167 (if entry 180 (progn
168 (nconc entry entry2) 181 (if entry
169 (setq entry entry2))) 182 (nconc entry entry2)
183 (setq entry entry2))))
170 (setq break (1- break)))) 184 (setq break (1- break))))
171 185
172 ;; Search OKURI-ARI entries. 186 ;; Search OKURI-ARI entries.
173 (let ((okurigana (assq (aref seq (1- len)) skkdic-okurigana-table)) 187 (let ((okurigana (assq (aref seq (1- len)) skkdic-okurigana-table))
174 orig-element entry2) 188 orig-element entry2)
185 (okuri (char-to-string (aref seq (1- len))))) 199 (okuri (char-to-string (aref seq (1- len)))))
186 (while l 200 (while l
187 (setcar l (concat (car l) okuri)) 201 (setcar l (concat (car l) okuri))
188 (setq l (cdr l))) 202 (setq l (cdr l)))
189 (if entry 203 (if entry
190 (nconc entry entry2) 204 (if prefer-noun
191 (setq entry entry2))))) 205 (nconc entry entry2)
206 (setq entry2 (nreverse entry2))
207 (nconc entry2 entry)
208 (setq entry entry2))
209 (setq entry (nreverse entry2))))))
192 (aset vec (1- len) orig-element)))) 210 (aset vec (1- len) orig-element))))
193 211
194 entry)) 212 entry))
195 213
196 ;; 214 ;;