1 ;;; ids-find.el --- search utility based on Ideographic-structures
3 ;; Copyright (C) 2002 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: Kanji, Ideographs, search, IDS
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 (setq m1 (car (get-char-attribute c1 '<-radical))
36 m2 (car (get-char-attribute c2 '<-radical)))
37 (unless (characterp m1)
38 (setq m1 (or (find-char m1))))
39 (unless (characterp m2)
40 (setq m2 (find-char m2)))
42 (ideographic-structure-char= m1 m2))))))))
44 (defun ideographic-structure-member-compare-components (component s-component)
46 (cond ((char-ref= component s-component #'ideographic-structure-char=))
48 (if (setq ret (assq 'ideographic-structure s-component))
49 (ideographic-structure-member component (cdr ret))))
50 ((setq ret (get-char-attribute s-component 'ideographic-structure))
51 (ideographic-structure-member component ret)))))
54 (defun ideographic-structure-member (component structure)
55 "Return non-nil if COMPONENT is included in STRUCTURE."
57 (setq structure (cdr structure))
58 (ideographic-structure-member-compare-components
59 component (car structure)))
61 (setq structure (cdr structure))
62 (ideographic-structure-member-compare-components
63 component (car structure)))
65 (setq structure (cdr structure))
67 (ideographic-structure-member-compare-components
68 component (car structure))))))
72 (defun ideographic-structure-repertoire-p (structure components)
73 "Return non-nil if STRUCTURE can be constructed by a subset of COMPONENTS."
75 (let (ret s-component)
77 (while (setq structure (cdr structure))
78 (setq s-component (car structure))
79 (unless (characterp s-component)
80 (if (setq ret (find-char s-component))
81 (setq s-component ret)))
84 (if (setq ret (assq 'ideographic-structure s-component))
85 (ideographic-structure-repertoire-p
86 (cdr ret) components)))
87 ((member* s-component components
88 :test #'ideographic-structure-char=))
90 (get-char-attribute s-component
91 'ideographic-structure))
92 (ideographic-structure-repertoire-p ret components)))
97 (defvar ids-find-result-buffer "*ids-chars*")
99 (defun ids-find-format-line (c v)
100 (format "%c\t%s\t%s\n"
102 (or (let ((ucs (or (char-ucs c)
103 (encode-char c 'ucs))))
105 (cond ((<= ucs #xFFFF)
106 (format " U+%04X" ucs))
108 (format "U-%08X" ucs)))))
110 (or (ideographic-structure-to-ids v)
114 (defun ids-find-chars-including-components (components)
115 "Search Ideographs whose structures have COMPONENTS."
116 (interactive "sComponents : ")
117 (with-current-buffer (get-buffer-create ids-find-result-buffer)
118 (setq buffer-read-only nil)
122 (when (every (lambda (p)
123 (ideographic-structure-member p v))
125 (insert (ids-find-format-line c v)))
127 'ideographic-structure)
128 (goto-char (point-min)))
129 (view-buffer ids-find-result-buffer))
132 (define-obsolete-function-alias 'ideographic-structure-search-chars
133 'ids-find-chars-including-components)
136 (defun ids-find-chars-covered-by-components (components)
137 "Search Ideographs which structures are consisted by subsets of COMPONENTS."
138 (interactive "sComponents: ")
139 (if (stringp components)
140 (setq components (string-to-char-list components)))
141 (with-current-buffer (get-buffer-create ids-find-result-buffer)
142 (setq buffer-read-only nil)
147 (when (ideographic-structure-repertoire-p v components)
148 (insert (ids-find-format-line c v))))
149 'ideographic-structure))
150 (goto-char (point-min)))
151 (view-buffer ids-find-result-buffer))
159 ;;; ids-find.el ends here