1 ;;; ids-find.el --- search utility based on Ideographic-structures
3 ;; Copyright (C) 2002,2003 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: Kanji, Ideographs, search, IDS, CHISE, UCS, Unicode
8 ;; This file is a part of Tomoyo-Tools.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 (defun ideographic-structure-char= (c1 c2)
30 (let ((m1 (char-ucs c1))
35 (unless (characterp b2)
36 (setq b2 (find-char b2)))
38 (ideographic-structure-char= c1 b2)))
40 c2 '<-ideographic-component-forms))
42 (setq m1 (car (get-char-attribute c1 '<-radical))
43 m2 (car (get-char-attribute c2 '<-radical)))
44 (unless (characterp m1)
45 (setq m1 (find-char m1)))
46 (unless (characterp m2)
47 (setq m2 (find-char m2)))
49 (ideographic-structure-char= m1 m2))))))))
51 (defun ideographic-structure-member-compare-components (component s-component)
53 (cond ((char-ref= component s-component #'ideographic-structure-char=))
55 (if (setq ret (assq 'ideographic-structure s-component))
56 (ideographic-structure-member component (cdr ret))))
57 ((setq ret (get-char-attribute s-component 'ideographic-structure))
58 (ideographic-structure-member component ret)))))
61 (defun ideographic-structure-member (component structure)
62 "Return non-nil if COMPONENT is included in STRUCTURE."
64 (setq structure (cdr structure))
65 (ideographic-structure-member-compare-components
66 component (car structure)))
68 (setq structure (cdr structure))
69 (ideographic-structure-member-compare-components
70 component (car structure)))
72 (setq structure (cdr structure))
74 (ideographic-structure-member-compare-components
75 component (car structure))))))
79 (defun ideographic-structure-repertoire-p (structure components)
80 "Return non-nil if STRUCTURE can be constructed by a subset of COMPONENTS."
82 (let (ret s-component)
84 (while (setq structure (cdr structure))
85 (setq s-component (car structure))
86 (unless (characterp s-component)
87 (if (setq ret (find-char s-component))
88 (setq s-component ret)))
91 (if (setq ret (assq 'ideographic-structure s-component))
92 (ideographic-structure-repertoire-p
93 (cdr ret) components)))
94 ((member* s-component components
95 :test #'ideographic-structure-char=))
97 (get-char-attribute s-component
98 'ideographic-structure))
99 (ideographic-structure-repertoire-p ret components)))
104 (defvar ids-find-result-buffer "*ids-chars*")
106 (defun ids-find-format-line (c v)
107 (format "%c\t%s\t%s\n"
109 (or (let ((ucs (or (char-ucs c)
110 (encode-char c 'ucs))))
112 (cond ((<= ucs #xFFFF)
113 (format " U+%04X" ucs))
115 (format "U-%08X" ucs)))))
117 (or (ideographic-structure-to-ids v)
121 (defun ids-find-chars-including-components (components)
122 "Search Ideographs whose structures have COMPONENTS."
123 (interactive "sComponents : ")
124 (with-current-buffer (get-buffer-create ids-find-result-buffer)
125 (setq buffer-read-only nil)
129 (when (every (lambda (p)
130 (ideographic-structure-member p v))
132 (insert (ids-find-format-line c v)))
134 'ideographic-structure)
135 (goto-char (point-min)))
136 (view-buffer ids-find-result-buffer))
139 (define-obsolete-function-alias 'ideographic-structure-search-chars
140 'ids-find-chars-including-components)
143 (defun ids-find-chars-covered-by-components (components)
144 "Search Ideographs which structures are consisted by subsets of COMPONENTS."
145 (interactive "sComponents: ")
146 (if (stringp components)
147 (setq components (string-to-char-list components)))
148 (with-current-buffer (get-buffer-create ids-find-result-buffer)
149 (setq buffer-read-only nil)
154 (when (ideographic-structure-repertoire-p v components)
155 (insert (ids-find-format-line c v))))
156 'ideographic-structure))
157 (goto-char (point-min)))
158 (view-buffer ids-find-result-buffer))
166 ;;; ids-find.el ends here