1 ;;; ids-find.el --- search utility based on Ideographic-structures ;; -*- coding: utf-8-mcs-er -*-
3 ;; Copyright (C) 2002, 2003, 2005, 2006, 2007, 2017, 2020 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 CHISE-IDS.
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 ids-index-store-char (product component)
28 (let ((ret (get-char-attribute component 'ideographic-products)))
29 (unless (memq product ret)
30 (put-char-attribute component 'ideographic-products
32 (when (setq ret (char-feature component 'ideographic-structure))
33 (ids-index-store-structure product ret)))
36 (defun ids-index-store-structure (product structure)
38 (dolist (cell (cdr structure))
40 (setq cell (plist-get cell :char)))
41 (cond ((characterp cell)
42 (ids-index-store-char product cell))
43 ((setq ret (assq 'ideographic-structure cell))
44 (ids-index-store-structure product (cdr ret)))
45 ((setq ret (find-char cell))
46 (ids-index-store-char product ret))
50 (defun ids-update-index (&optional in-memory)
54 (ids-index-store-structure c v)
56 'ideographic-structure)
59 (ids-index-store-structure c v)
61 'ideographic-structure@apparent)
63 (save-char-attribute-table 'ideographic-products)))
66 (mount-char-attribute-table 'ideographic-products)
69 (defun ids-find-all-products (char)
71 (dolist (cell (char-feature char 'ideographic-products))
72 (unless (memq cell dest)
73 (setq dest (cons cell dest)))
74 (setq dest (union dest (ids-find-all-products cell))))
77 (defun of-component-features ()
79 (dolist (feature (char-attribute-list))
80 (when (string-match "^<-.*[@/]component\\(/[^*/]+\\)*$"
81 (symbol-name feature))
83 (list* '<-mistakable '->mistakable
86 '<-original '->original
90 (defun to-component-features ()
92 (dolist (feature (char-attribute-list))
93 (when (string-match "^->.*[@/]component\\(/[^*/]+\\)*$"
94 (symbol-name feature))
99 (defun char-component-variants (char)
100 (let ((dest (list char))
102 (dolist (feature (to-component-features))
103 (if (setq ret (get-char-attribute char feature))
105 (setq dest (union dest (char-component-variants c))))))
107 ;; ((setq ret (some (lambda (feature)
108 ;; (get-char-attribute char feature))
109 ;; (to-component-features)))
111 ;; (setq dest (union dest (char-component-variants c))))
113 ((setq ret (get-char-attribute char '->ucs-unified))
114 (setq dest (cons char ret))
116 (setq dest (union dest
117 (some (lambda (feature)
118 (get-char-attribute c feature))
119 (of-component-features))
122 ((and (setq ret (get-char-attribute char '=>ucs))
123 (setq uchr (decode-char '=ucs ret)))
124 (setq dest (cons uchr (char-variants uchr)))
126 (setq dest (union dest
127 (some (lambda (feature)
128 (get-char-attribute c feature))
129 (of-component-features))
135 (unless (memq c dest)
136 (setq dest (cons c dest)))
139 (some (lambda (feature)
140 (char-feature c feature))
141 (of-component-features))
149 (defun ideographic-products-find (&rest components)
150 (if (stringp (car components))
151 (setq components (string-to-char-list (car components))))
153 (dolist (variant (char-component-variants (car components)))
156 (get-char-attribute variant 'ideographic-products))))
159 (setq components (cdr components)))
161 (dolist (variant (char-component-variants (car components)))
164 (get-char-attribute variant 'ideographic-products))))
165 (setq dest (intersection dest products)))
168 (defun ideograph-find-products-with-variants (components &optional ignored-chars)
169 (if (stringp components)
170 (setq components (string-to-char-list components)))
172 (dolist (variant (char-component-variants (car components)))
176 (get-char-attribute variant 'ideographic-products)
180 (setq components (cdr components)))
182 (dolist (variant (char-component-variants (car components)))
186 (get-char-attribute variant 'ideographic-products)
188 (setq dest (intersection dest products)))
191 (defun ideograph-find-products (components &optional ignored-chars)
192 (if (stringp components)
193 (setq components (string-to-char-list components)))
195 ;; (dolist (variant (char-component-variants (car components)))
198 ;; (get-char-attribute variant 'ideographic-products))))
199 ;; (setq dest products)
200 (setq dest (get-char-attribute (car components) 'ideographic-products))
202 (setq components (cdr components)))
203 ;; (setq products nil)
204 ;; (dolist (variant (char-component-variants (car components)))
207 ;; (get-char-attribute variant 'ideographic-products))))
208 (setq products (get-char-attribute (car components) 'ideographic-products))
209 (setq dest (intersection dest products)))
213 (defun ideographic-structure-char= (c1 c2)
216 (let ((m1 (char-ucs c1))
220 (memq c1 (char-component-variants c2)))))))
222 (defun ideographic-structure-member-compare-components (component s-component)
224 (cond ((char-ref= component s-component #'ideographic-structure-char=))
226 (if (setq ret (assq 'ideographic-structure s-component))
227 (ideographic-structure-member component (cdr ret))))
228 ((setq ret (get-char-attribute s-component 'ideographic-structure))
229 (ideographic-structure-member component ret)))))
232 (defun ideographic-structure-member (component structure)
233 "Return non-nil if COMPONENT is included in STRUCTURE."
234 (or (memq component structure)
236 (setq structure (cdr structure))
237 (ideographic-structure-member-compare-components
238 component (car structure)))
240 (setq structure (cdr structure))
241 (ideographic-structure-member-compare-components
242 component (car structure)))
244 (setq structure (cdr structure))
246 (ideographic-structure-member-compare-components
247 component (car structure))))))
251 (defun ideographic-structure-repertoire-p (structure components)
252 "Return non-nil if STRUCTURE can be constructed by a subset of COMPONENTS."
254 (let (ret s-component)
256 (while (setq structure (cdr structure))
257 (setq s-component (car structure))
258 (unless (characterp s-component)
259 (if (setq ret (find-char s-component))
260 (setq s-component ret)))
263 (if (setq ret (assq 'ideographic-structure s-component))
264 (ideographic-structure-repertoire-p
265 (cdr ret) components)))
266 ((member* s-component components
267 :test #'ideographic-structure-char=))
269 (get-char-attribute s-component
270 'ideographic-structure))
271 (ideographic-structure-repertoire-p ret components)))
276 (defvar ids-find-result-buffer "*ids-chars*")
278 (defun ids-find-format-line (c v)
279 (format "%c\t%s\t%s\n"
281 (or (let ((ucs (or (char-ucs c)
282 (encode-char c 'ucs))))
284 (cond ((<= ucs #xFFFF)
285 (format " U+%04X" ucs))
287 (format "U-%08X" ucs)))))
289 (or (ideographic-structure-to-ids v)
292 (defun ids-insert-chars-including-components* (components
293 &optional level ignored-chars)
297 (dolist (c (sort (copy-tree (ideograph-find-products components
300 (if (setq as (char-total-strokes a))
301 (if (setq bs (char-total-strokes b))
303 (ideograph-char< a b)
306 (ideograph-char< a b)))))
307 (unless (memq c ignored-chars)
308 (setq is (char-feature c 'ideographic-structure))
313 (insert (ids-find-format-line c is))
315 (ids-insert-chars-including-components*
316 (char-to-string c) (1+ level)
317 (cons c ignored-chars))))
322 (defun ids-insert-chars-including-components (components
323 &optional level ignored-chars)
328 (ids-insert-chars-including-components* components
329 level ignored-chars)))
331 (dolist (c ignored-chars)
332 (dolist (vc (char-component-variants c))
333 (unless (memq vc ignored-chars)
334 (when (setq is (get-char-attribute vc 'ideographic-structure))
339 (insert (ids-find-format-line vc is))
341 (ids-insert-chars-including-components*
342 (char-to-string vc) (1+ level)
343 (cons vc ignored-chars)))))))
344 (dolist (c (sort (copy-tree (ideograph-find-products-with-variants
345 components ignored-chars))
347 (if (setq as (char-total-strokes a))
348 (if (setq bs (char-total-strokes b))
350 (ideograph-char< a b)
353 (ideograph-char< a b)))))
354 (unless (memq c ignored-chars)
355 (setq is (get-char-attribute c 'ideographic-structure))
360 (insert (ids-find-format-line c is))
362 (ids-insert-chars-including-components*
363 (char-to-string c) (1+ level)
364 (cons c ignored-chars))))
370 (defun ids-find-chars-including-components (components)
371 "Search Ideographs whose structures have COMPONENTS."
372 (interactive "sComponents : ")
373 (with-current-buffer (get-buffer-create ids-find-result-buffer)
374 (setq buffer-read-only nil)
376 (ids-insert-chars-including-components components 0 nil)
377 ;; (let ((ignored-chars
379 ;; (ids-insert-chars-including-components components 0 nil
380 ;; #'ideograph-find-products)))
382 ;; (setq rest ignored-chars)
383 ;; ;; (dolist (c rest)
384 ;; ;; (setq ignored-chars
385 ;; ;; (union ignored-chars
386 ;; ;; (ids-insert-chars-including-components
387 ;; ;; (list c) 0 ignored-chars
388 ;; ;; #'ideograph-find-products-with-variants))))
389 ;; (ids-insert-chars-including-components components 0 ignored-chars
390 ;; #'ideograph-find-products-with-variants))
391 (goto-char (point-min)))
392 (view-buffer ids-find-result-buffer))
395 (define-obsolete-function-alias 'ideographic-structure-search-chars
396 'ids-find-chars-including-components)
399 (defun ids-find-chars-covered-by-components (components)
400 "Search Ideographs which structures are consisted by subsets of COMPONENTS."
401 (interactive "sComponents: ")
402 (if (stringp components)
403 (setq components (string-to-char-list components)))
404 (with-current-buffer (get-buffer-create ids-find-result-buffer)
405 (setq buffer-read-only nil)
409 (when (ideographic-structure-repertoire-p v components)
410 (insert (ids-find-format-line c v))))
411 'ideographic-structure)
412 (goto-char (point-min)))
413 (view-buffer ids-find-result-buffer))
416 (defun ideographic-structure-merge-components-alist (ca1 ca2)
417 (let ((dest-alist ca1)
420 (if (setq ret (assq (car cell) dest-alist))
421 (setcdr ret (+ (cdr ret)(cdr cell)))
422 (setq dest-alist (cons cell dest-alist))))
425 (defun ideographic-structure-to-components-alist (structure)
426 (apply #'ideographic-structure-to-components-alist* structure))
428 (defun ideographic-structure-to-components-alist* (operator component1 component2
431 (let (dest-alist ret)
433 (cond ((characterp component1)
434 (unless (encode-char component1 'ascii)
435 (list (cons component1 1)))
437 ((setq ret (assq 'ideographic-structure component1))
438 (ideographic-structure-to-components-alist (cdr ret))
440 ((setq ret (find-char component1))
444 (ideographic-structure-merge-components-alist
446 (cond ((characterp component2)
447 (unless (encode-char component2 'ascii)
448 (list (cons component2 1)))
450 ((setq ret (assq 'ideographic-structure component2))
451 (ideographic-structure-to-components-alist (cdr ret))
453 ((setq ret (find-char component2))
456 (if (memq operator '(?\u2FF2 ?\u2FF3))
457 (ideographic-structure-merge-components-alist
459 (cond ((characterp component3)
460 (unless (encode-char component3 'ascii)
461 (list (cons component3 1)))
463 ((setq ret (assq 'ideographic-structure component3))
464 (ideographic-structure-to-components-alist (cdr ret))
466 ((setq ret (find-char component3))
471 (defun ids-find-merge-variables (ve1 ve2)
477 (let ((dest-alist ve1)
481 (setq cell (car rest))
482 (if (setq ret (assq (car cell) ve1))
483 (eq (cdr ret)(cdr cell))
484 (setq dest-alist (cons cell dest-alist))))
485 (setq rest (cdr rest)))
491 (defun ideographic-structure-equal (structure1 structure2)
492 (let (dest-alist ret)
493 (and (setq dest-alist (ideographic-structure-character=
494 (car structure1)(car structure2)))
495 (setq ret (ideographic-structure-character=
496 (nth 1 structure1)(nth 1 structure2)))
497 (setq dest-alist (ids-find-merge-variables dest-alist ret))
498 (setq ret (ideographic-structure-character=
499 (nth 2 structure1)(nth 2 structure2)))
500 (setq dest-alist (ids-find-merge-variables dest-alist ret))
501 (if (memq (car structure1) '(?\u2FF2 ?\u2FF3))
502 (and (setq ret (ideographic-structure-character=
503 (nth 3 structure1)(nth 3 structure2)))
504 (setq dest-alist (ids-find-merge-variables dest-alist ret)))
508 (defun ideographic-structure-character= (c1 c2)
510 (cond ((characterp c1)
511 (cond ((encode-char c1 'ascii)
515 (if (encode-char c2 'ascii)
519 ((setq ret2 (find-char c2))
522 ((setq ret2 (assq 'ideographic-structure c2))
523 (and (setq ret (get-char-attribute c1 'ideographic-structure))
524 (ideographic-structure-equal ret (cdr ret2)))
527 ((setq ret (assq 'ideographic-structure c1))
528 (cond ((characterp c2)
529 (if (encode-char c2 'ascii)
531 (and (setq ret2 (get-char-attribute c2 'ideographic-structure))
532 (ideographic-structure-equal (cdr ret) ret2)))
534 ((setq ret2 (find-char c2))
535 (and (setq ret2 (get-char-attribute ret2 'ideographic-structure))
536 (ideographic-structure-equal (cdr ret) ret2))
538 ((setq ret2 (assq 'ideographic-structure c2))
539 (ideographic-structure-equal (cdr ret)(cdr ret2))
542 ((setq ret (find-char c1))
543 (cond ((characterp c2)
544 (if (encode-char c2 'ascii)
548 ((setq ret2 (find-char c2))
551 ((setq ret2 (assq 'ideographic-structure c2))
552 (and (setq ret (get-char-attribute ret 'ideographic-structure))
553 (ideographic-structure-equal ret (cdr ret2))
557 (defun ideographic-structure-find-chars (structure)
558 (apply #'ideographic-structure-find-chars* structure))
560 (defun ideographic-structure-find-chars* (operator component1 component2
561 &optional component3)
562 (let ((comp-alist (ideographic-structure-to-components-alist*
563 operator component1 component2 component3))
568 (sort (mapcar (lambda (cell)
569 (if (setq ret (get-char-attribute
570 (car cell) 'ideographic-products))
571 (cons ret (length ret))
575 (< (cdr a)(cdr b))))))
576 (when (and (setq str (get-char-attribute pc 'ideographic-structure))
578 (ideographic-structure-character= (car str) operator))
579 (setq c1 (nth 1 str))
580 (setq ret (ideographic-structure-character= c1 component1))
581 (setq var-alist (ids-find-merge-variables var-alist ret))
582 (setq c2 (nth 2 str))
583 (setq ret (ideographic-structure-character= c2 component2))
584 (setq var-alist (ids-find-merge-variables var-alist ret))
585 (cond ((memq (car str) '(?\u2FF2 ?\u2FF3))
586 (setq c3 (nth 3 str))
587 (and (setq ret (ideographic-structure-character=
589 (ids-find-merge-variables var-alist ret))
592 (setq pl (cons pc pl))
597 (defun ideographic-char-count-components (char component)
600 (cond ((eq char component)
602 ((setq structure (get-char-attribute char 'ideographic-structure))
603 (dolist (cell (ideographic-structure-to-components-alist structure))
606 (if (eq (car cell) char)
608 (* (ideographic-char-count-components (car cell) component)
616 (defun ideographic-character-get-structure (character)
617 "Return ideographic-structure of CHARACTER.
618 CHARACTER can be a character or char-spec."
620 (cond ((characterp character)
621 (get-char-attribute character 'ideographic-structure)
623 ((setq ret (assq 'ideographic-structure character))
626 ((setq ret (find-char character))
627 (get-char-attribute ret 'ideographic-structure)
631 (defun ideographic-char-match-component (char component)
632 "Return non-nil if character CHAR has COMPONENT in ideographic-structure.
633 COMPONENT can be a character or char-spec."
634 (or (ideographic-structure-character= char component)
635 (let ((str (ideographic-character-get-structure char)))
637 (or (ideographic-char-match-component (nth 1 str) component)
638 (ideographic-char-match-component (nth 2 str) component)
639 (if (memq (car str) '(?\u2FF2 ?\u2FF3))
640 (ideographic-char-match-component (nth 3 str) component)))))))
642 (defun ideographic-structure-char< (a b)
643 (let ((sa (get-char-attribute a 'ideographic-structure))
644 (sb (get-char-attribute b 'ideographic-structure))
648 (setq tsa (char-total-strokes a)
649 tsb (char-total-strokes b))
654 (ideograph-char< a b)))
658 (ideograph-char< a b))))
666 (setq tsa (char-total-strokes a)
667 tsb (char-total-strokes b))
672 (ideograph-char< a b)))
676 (ideograph-char< a b)))
681 (defun ideographic-chars-to-is-a-tree (chars)
682 (let (comp char products others dest rest
684 (setq chars (sort chars #'ideographic-structure-char<))
686 (setq comp (pop chars)
691 (setq char (pop rest))
693 ((ideographic-char-match-component char comp)
700 ;; (nreverse products)
702 (sort (ideographic-chars-to-is-a-tree products)
704 (setq la (length (cdr a))
708 (ideograph-char< (car a) (car b))
710 ;; (setq tsa (char-total-strokes (car a))
711 ;; tsb (char-total-strokes (car b)))
717 ;; (car a) (car b))))
721 ;; (ideograph-char< (car a) (car b)))))
729 (defun ids-find-chars-including-ids* (operator component1 component2
730 &optional component3)
731 (let ((comp-alist (ideographic-structure-to-components-alist*
732 operator component1 component2 component3))
734 (list (list* 'ideographic-structure
735 operator component1 component2
737 (list component3)))))
740 (sort (mapcar (lambda (cell)
741 (if (setq ret (get-char-attribute
742 (car cell) 'ideographic-products))
743 (cons ret (length ret))
747 (< (cdr a)(cdr b))))))
748 (when (and (every (lambda (cell)
749 (>= (ideographic-char-count-components pc (car cell))
752 (or (ideographic-char-match-component pc comp-spec)
753 (and (setq str (get-char-attribute pc 'ideographic-structure))
754 (ideographic-char-match-component
757 'ideographic-structure
758 (functional-ideographic-structure-to-apparent-structure
762 (ideographic-chars-to-is-a-tree rest)))
764 (defun ids-find-chars-including-ids (structure)
765 (if (characterp structure)
766 (setq structure (get-char-attribute structure 'ideographic-structure)))
767 (apply #'ids-find-chars-including-ids* structure))
769 (defun functional-ideographic-structure-to-apparent-structure (structure)
770 (ideographic-structure-compare-functional-and-apparent
771 structure nil 'conversion-only)
772 ;; (ideographic-structure-compact
773 ;; (let (enc enc-str enc2-str new-str)
775 ;; ((eq (car structure) ?⿸)
776 ;; (setq enc (nth 1 structure))
777 ;; (when (setq enc-str
778 ;; (cond ((characterp enc)
779 ;; (get-char-attribute enc 'ideographic-structure)
782 ;; (cdr (assq 'ideographic-structure enc))
785 ;; ((eq (car enc-str) ?⿰)
786 ;; (list ?⿰ (nth 1 enc-str)
787 ;; (list (list 'ideographic-structure
790 ;; (nth 2 structure))))
792 ;; ((and (eq (car enc-str) ?⿲)
793 ;; (memq (char-ucs (nth 1 enc-str)) '(#x4EBB #x2E85))
794 ;; (eq (nth 2 enc-str) ?丨))
796 ;; (decode-char '=big5-cdp #x8B7A)
797 ;; (list (list 'ideographic-structure
800 ;; (nth 2 structure))))
802 ;; ((eq (car enc-str) ?⿱)
803 ;; (list ?⿱ (nth 1 enc-str)
805 ;; (cons 'ideographic-structure
806 ;; (or (functional-ideographic-structure-to-apparent-structure
810 ;; ((characterp (nth 2 enc-str))
811 ;; (if (or (eq (encode-char
835 ;; (eq (or (encode-char
840 ;; '=big5-cdp-itaiji-001))
843 ;; (get-char-attribute
845 ;; 'ideographic-structure))
851 ;; (assq 'ideographic-structure
852 ;; (nth 2 enc-str))))
862 ;; ((eq (car enc-str) ?⿸)
863 ;; (list ?⿸ (nth 1 enc-str)
865 ;; (cons 'ideographic-structure
869 ;; ((characterp (nth 2 enc-str))
870 ;; (if (memq (char-ucs (nth 2 enc-str))
878 ;; (nth 2 structure))))))
881 ;; ((eq (car structure) ?⿹)
882 ;; (setq enc (nth 1 structure))
883 ;; (when (setq enc-str
884 ;; (cond ((characterp enc)
885 ;; (get-char-attribute enc 'ideographic-structure)
888 ;; (cdr (assq 'ideographic-structure enc))
891 ;; ((eq (car enc-str) ?⿰)
893 ;; (list (list 'ideographic-structure
896 ;; (nth 2 structure)))
900 ;; ((eq (get-char-attribute (car structure) '=ucs-itaiji-001) #x2FF6)
901 ;; (setq enc (nth 1 structure))
902 ;; (when (setq enc-str
903 ;; (cond ((characterp enc)
904 ;; (get-char-attribute enc 'ideographic-structure)
907 ;; (cdr (assq 'ideographic-structure enc))
910 ;; ((eq (car enc-str) ?⿺)
912 ;; (list (list 'ideographic-structure
918 ;; ((eq (car enc-str) ?⿱)
920 ;; (list (list 'ideographic-structure
928 ;; ((eq (car structure) ?⿴)
929 ;; (setq enc (nth 1 structure))
930 ;; (when (setq enc-str
931 ;; (cond ((characterp enc)
932 ;; (get-char-attribute enc 'ideographic-structure)
935 ;; (cdr (assq 'ideographic-structure enc))
938 ;; ((eq (car enc-str) ?⿱)
940 ;; ((and (characterp (nth 2 enc-str))
941 ;; (or (memq (char-ucs (nth 2 enc-str)) '(#x56D7 #x5F51 #x897F))
942 ;; (eq (char-feature (nth 2 enc-str) '=>big5-cdp)
946 ;; (list (list 'ideographic-structure
949 ;; (nth 2 structure)))
952 ;; ((and (characterp (nth 2 enc-str))
953 ;; (eq (char-ucs (nth 2 enc-str)) #x51F5))
956 ;; (list (list 'ideographic-structure
959 ;; (nth 2 structure)))
962 ;; ((and (characterp (nth 1 enc-str))
963 ;; (eq (char-feature (nth 1 enc-str) '=>ucs@component)
966 ;; (list (list 'ideographic-structure
969 ;; (nth 2 structure)))
981 ;; ((eq (car structure) ?⿶)
982 ;; (setq enc (nth 1 structure))
983 ;; (when (setq enc-str
984 ;; (cond ((characterp enc)
985 ;; (get-char-attribute enc 'ideographic-structure)
988 ;; (cdr (assq 'ideographic-structure enc))
991 ;; ((eq (car enc-str) ?⿱)
992 ;; (setq enc2-str (ideographic-character-get-structure (nth 1 enc-str)))
993 ;; (when (and enc2-str
994 ;; (eq (car enc2-str) ?⿰))
996 ;; (list (list 'ideographic-structure
1000 ;; (nth 2 enc2-str)))
1001 ;; (nth 2 enc-str)))
1003 ;; ((eq (car enc-str) ?⿳)
1004 ;; (setq enc2-str (ideographic-character-get-structure (nth 1 enc-str)))
1005 ;; (when (and enc2-str
1006 ;; (eq (car enc2-str) ?⿰))
1008 ;; (list (list 'ideographic-structure
1011 ;; (nth 2 structure)
1012 ;; (nth 2 enc2-str)))
1014 ;; (nth 3 enc-str)))
1016 ;; ((eq (car enc-str) ?⿲)
1019 ;; (list (list 'ideographic-structure
1021 ;; (nth 2 structure)
1022 ;; (nth 2 enc-str)))
1025 ;; ((eq (car enc-str) ?⿴)
1026 ;; (setq enc2-str (ideographic-character-get-structure (nth 1 enc-str)))
1027 ;; (when (and enc2-str
1028 ;; (eq (car enc2-str) ?⿰))
1031 ;; (list (list 'ideographic-structure
1033 ;; (nth 2 structure)
1034 ;; (nth 2 enc-str)))
1035 ;; (nth 2 enc2-str)))
1038 ;; ((eq (car structure) ?⿵)
1039 ;; (setq enc (nth 1 structure))
1040 ;; (when (setq enc-str
1041 ;; (cond ((characterp enc)
1042 ;; (get-char-attribute enc 'ideographic-structure)
1045 ;; (cdr (assq 'ideographic-structure enc))
1048 ;; ((eq (car enc-str) ?⿱)
1049 ;; (setq enc2-str (ideographic-character-get-structure (nth 2 enc-str)))
1050 ;; (when (and enc2-str
1051 ;; (eq (car enc2-str) ?⿰))
1054 ;; (list (list 'ideographic-structure
1057 ;; (nth 2 structure)
1058 ;; (nth 2 enc2-str)))))
1060 ;; ((eq (car enc-str) ?⿳)
1061 ;; (setq enc2-str (ideographic-character-get-structure (nth 3 enc-str)))
1062 ;; (when (and enc2-str
1063 ;; (eq (car enc2-str) ?⿰))
1067 ;; (list (list 'ideographic-structure
1070 ;; (nth 2 structure)
1071 ;; (nth 2 enc2-str)))))
1073 ;; ((eq (car enc-str) ?⿲)
1076 ;; (list (list 'ideographic-structure
1079 ;; (nth 2 structure)))
1082 ;; ((eq (car enc-str) ?⿴)
1083 ;; (setq enc2-str (ideographic-character-get-structure (nth 1 enc-str)))
1084 ;; (when (and enc2-str
1085 ;; (eq (car enc2-str) ?⿰))
1088 ;; (list (list 'ideographic-structure
1091 ;; (nth 2 structure)))
1092 ;; (nth 2 enc2-str)))
1095 ;; ((eq (car structure) ?⿻)
1096 ;; (setq enc (nth 1 structure))
1097 ;; (when (setq enc-str
1098 ;; (cond ((characterp enc)
1099 ;; (get-char-attribute enc 'ideographic-structure)
1102 ;; (cdr (assq 'ideographic-structure enc))
1105 ;; ((eq (car enc-str) ?⿱)
1108 ;; (nth 2 structure)
1116 (defun ideographic-structure-compact (structure)
1117 (let ((rest structure)
1121 (setq cell (pop rest))
1124 (cond ((setq ret (assq 'ideographic-structure cell))
1125 (setq sub (cdr ret))
1131 (if (setq ret (ideographic-structure-find-chars sub))
1133 (list (cons 'ideographic-structure sub))))
1135 (setq dest (cons cell dest)))
1138 (defun ideographic-structure-compare-functional-and-apparent (structure
1141 (let (enc enc-str enc2-str new-str new-str-c f-res a-res code ret)
1143 ((eq (car structure) ?⿸)
1144 (setq enc (nth 1 structure))
1146 (cond ((characterp enc)
1147 (get-char-attribute enc 'ideographic-structure)
1150 (cdr (assq 'ideographic-structure enc))
1153 ((eq (car enc-str) ?⿰)
1154 (unless conversion-only
1155 (setq f-res (ids-find-chars-including-ids enc-str)))
1156 (setq new-str (list ?⿱
1160 (if (setq ret (ideographic-structure-find-chars new-str))
1162 (list (cons 'ideographic-structure new-str))))
1164 (list ?⿰ (nth 1 enc-str) new-str-c)
1165 (setq a-res (ids-find-chars-including-ids new-str))
1170 (list ?⿰ (nth 1 enc-str) new-str-c)
1173 ((and (eq (car enc-str) ?⿲)
1174 (memq (char-ucs (nth 1 enc-str)) '(#x4EBB #x2E85))
1175 (eq (nth 2 enc-str) ?丨))
1176 (unless conversion-only
1177 (setq f-res (ids-find-chars-including-ids enc-str)))
1178 (setq new-str (list ?⿱
1182 (if (setq ret (ideographic-structure-find-chars new-str))
1184 (list (cons 'ideographic-structure new-str))))
1186 (list ?⿰ (decode-char '=big5-cdp #x8B7A) new-str-c)
1187 (setq a-res (ids-find-chars-including-ids new-str))
1192 (list ?⿰ (decode-char '=big5-cdp #x8B7A) new-str-c)
1195 ((eq (car enc-str) ?⿱)
1196 (unless conversion-only
1197 (setq f-res (ids-find-chars-including-ids enc-str)))
1201 ((characterp (nth 2 enc-str))
1202 (if (or (eq (encode-char (nth 2 enc-str) '=>ucs@component)
1204 (eq (encode-char (nth 2 enc-str) '=>ucs@component)
1206 (eq (encode-char (nth 2 enc-str) '=>ucs@component)
1208 (eq (encode-char (nth 2 enc-str) '=big5-cdp)
1210 (eq (encode-char (nth 2 enc-str) '=>big5-cdp)
1212 (eq (encode-char (nth 2 enc-str) '=big5-cdp)
1214 (eq (or (encode-char (nth 2 enc-str) '=>big5-cdp)
1215 (encode-char (nth 2 enc-str) '=big5-cdp-itaiji-001))
1217 (eq (car (get-char-attribute (nth 2 enc-str)
1218 'ideographic-structure))
1222 ((eq (car (cdr (assq 'ideographic-structure (nth 2 enc-str))))
1230 (if (setq ret (ideographic-structure-find-chars new-str))
1232 (list (cons 'ideographic-structure new-str))))
1234 (list ?⿱ (nth 1 enc-str) new-str-c)
1235 (setq a-res (ids-find-chars-including-ids new-str))
1240 (list ?⿱ (nth 1 enc-str) new-str-c)
1241 (if (eq (car new-str) ?⿸)
1245 ((eq (car enc-str) ?⿸)
1246 (unless conversion-only
1247 (setq f-res (ids-find-chars-including-ids enc-str)))
1248 (setq new-str (list (cond
1249 ((characterp (nth 2 enc-str))
1250 (if (memq (char-ucs (nth 2 enc-str))
1260 (if (setq ret (ideographic-structure-find-chars new-str))
1262 (list (cons 'ideographic-structure new-str))))
1264 (list ?⿸ (nth 1 enc-str) new-str-c)
1265 (setq a-res (ids-find-chars-including-ids new-str))
1270 (list ?⿸ (nth 1 enc-str) new-str-c)
1271 (if (eq (car new-str) ?⿰)
1276 ((eq (car structure) ?⿹)
1277 (setq enc (nth 1 structure))
1279 (cond ((characterp enc)
1280 (get-char-attribute enc 'ideographic-structure)
1283 (cdr (assq 'ideographic-structure enc))
1286 ((eq (car enc-str) ?⿰)
1287 (unless conversion-only
1288 (setq f-res (ids-find-chars-including-ids enc-str)))
1289 (setq new-str (list ?⿱
1293 (if (setq ret (ideographic-structure-find-chars new-str))
1295 (list (cons 'ideographic-structure new-str))))
1297 (list ?⿰ new-str-c (nth 2 enc-str))
1298 (setq a-res (ids-find-chars-including-ids new-str))
1303 (list ?⿰ new-str-c (nth 2 enc-str))
1307 ((eq (get-char-attribute (car structure) '=ucs-itaiji-001) #x2FF6)
1308 (setq enc (nth 1 structure))
1310 (cond ((characterp enc)
1311 (get-char-attribute enc 'ideographic-structure)
1314 (cdr (assq 'ideographic-structure enc))
1317 ((eq (car enc-str) ?⿺)
1318 (unless conversion-only
1319 (setq f-res (ids-find-chars-including-ids enc-str)))
1320 (setq new-str (list ?⿱
1324 (if (setq ret (ideographic-structure-find-chars new-str))
1326 (list (cons 'ideographic-structure new-str))))
1328 (list ?⿺ new-str-c (nth 2 enc-str))
1329 (setq a-res (ids-find-chars-including-ids new-str))
1334 (list ?⿺ new-str-c (nth 2 enc-str))
1337 ((eq (car enc-str) ?⿱)
1338 (unless conversion-only
1339 (setq f-res (ids-find-chars-including-ids enc-str)))
1340 (setq new-str (list ?⿰
1344 (if (setq ret (ideographic-structure-find-chars new-str))
1346 (list (cons 'ideographic-structure new-str))))
1348 (list ?⿱ new-str-c (nth 2 enc-str))
1349 (setq a-res (ids-find-chars-including-ids new-str))
1354 (list ?⿱ new-str-c (nth 2 enc-str))
1359 ((eq (car structure) ?⿴)
1360 (setq enc (nth 1 structure))
1362 (cond ((characterp enc)
1363 (get-char-attribute enc 'ideographic-structure)
1366 (cdr (assq 'ideographic-structure enc))
1369 ((eq (car enc-str) ?⿱)
1371 ((and (characterp (nth 2 enc-str))
1372 (or (memq (char-ucs (nth 2 enc-str)) '(#x56D7 #x5F51 #x897F))
1373 (eq (char-feature (nth 2 enc-str) '=>big5-cdp)
1375 (unless conversion-only
1376 (setq f-res (ids-find-chars-including-ids enc-str)))
1377 (setq new-str (list ?⿴
1381 (if (setq ret (ideographic-structure-find-chars new-str))
1383 (list (cons 'ideographic-structure new-str))))
1385 (list ?⿱ (nth 1 enc-str) new-str-c)
1386 (setq a-res (ids-find-chars-including-ids new-str))
1391 (list ?⿱ (nth 1 enc-str) new-str-c)
1394 ((and (characterp (nth 2 enc-str))
1395 (eq (char-ucs (nth 2 enc-str)) #x51F5))
1396 (unless conversion-only
1397 (setq f-res (ids-find-chars-including-ids enc-str)))
1398 (setq new-str (list ?⿶
1402 (if (setq ret (ideographic-structure-find-chars new-str))
1404 (list (cons 'ideographic-structure new-str))))
1406 (list ?⿱ (nth 1 enc-str) new-str-c)
1407 (setq a-res (ids-find-chars-including-ids new-str))
1412 (list ?⿱ (nth 1 enc-str) new-str-c)
1415 ((and (characterp (nth 1 enc-str))
1416 (eq (char-feature (nth 1 enc-str) '=>ucs@component)
1418 (unless conversion-only
1419 (setq f-res (ids-find-chars-including-ids enc-str)))
1420 (setq new-str (list ?⿵
1424 (if (setq ret (ideographic-structure-find-chars new-str))
1426 (list (cons 'ideographic-structure new-str))))
1428 (list ?⿱ new-str-c (nth 2 enc-str))
1429 (setq a-res (ids-find-chars-including-ids new-str))
1434 (list ?⿱ new-str-c (nth 2 enc-str))
1438 (unless conversion-only
1439 (setq f-res (ids-find-chars-including-ids enc-str)))
1440 (setq new-str (list ?⿱ (nth 2 structure) (nth 2 enc-str)))
1442 (if (setq ret (ideographic-structure-find-chars new-str))
1444 (list (cons 'ideographic-structure new-str))))
1446 (list ?⿱ (nth 1 enc-str) new-str-c)
1447 (setq a-res (ids-find-chars-including-ids new-str))
1452 (list ?⿱ (nth 1 enc-str) new-str-c)
1458 ((eq (car structure) ?⿶)
1459 (setq enc (nth 1 structure))
1461 (cond ((characterp enc)
1462 (get-char-attribute enc 'ideographic-structure)
1465 (cdr (assq 'ideographic-structure enc))
1468 ((eq (car enc-str) ?⿱)
1469 (setq enc2-str (ideographic-character-get-structure (nth 1 enc-str)))
1471 (eq (car enc2-str) ?⿰))
1472 (unless conversion-only
1473 (setq f-res (ids-find-chars-including-ids enc-str)))
1474 (setq new-str (list ?⿲
1479 (if (setq ret (ideographic-structure-find-chars new-str))
1481 (list (cons 'ideographic-structure new-str))))
1483 (list ?⿱ new-str-c (nth 2 enc-str))
1484 (setq a-res (ids-find-chars-including-ids new-str))
1489 (list ?⿱ new-str-c (nth 2 enc-str))
1493 ((eq (car enc-str) ?⿳)
1494 (setq enc2-str (ideographic-character-get-structure (nth 1 enc-str)))
1496 (eq (car enc2-str) ?⿰))
1497 (unless conversion-only
1498 (setq f-res (ids-find-chars-including-ids enc-str)))
1499 (setq new-str (list ?⿲
1504 (if (setq ret (ideographic-structure-find-chars new-str))
1506 (list (cons 'ideographic-structure new-str))))
1508 (list ?⿳ new-str-c (nth 2 enc-str) (nth 3 enc-str))
1509 (setq a-res (ids-find-chars-including-ids new-str))
1514 (list ?⿳ new-str-c (nth 2 enc-str) (nth 3 enc-str))
1518 ((eq (car enc-str) ?⿲)
1519 (unless conversion-only
1520 (setq f-res (ids-find-chars-including-ids enc-str)))
1521 (setq new-str (list ?⿱
1525 (if (setq ret (ideographic-structure-find-chars new-str))
1527 (list (cons 'ideographic-structure new-str))))
1529 (list ?⿲ (nth 1 enc-str) new-str-c (nth 3 enc-str))
1530 (setq a-res (ids-find-chars-including-ids new-str))
1535 (list ?⿲ (nth 1 enc-str) new-str-c (nth 3 enc-str))
1538 ((eq (car enc-str) ?⿴)
1539 (setq enc2-str (ideographic-character-get-structure (nth 1 enc-str)))
1541 (eq (car enc2-str) ?⿰))
1542 (unless conversion-only
1543 (setq f-res (ids-find-chars-including-ids enc-str)))
1544 (setq new-str (list ?⿱
1548 (if (setq ret (ideographic-structure-find-chars new-str))
1550 (list (cons 'ideographic-structure new-str))))
1552 (list ?⿲ (nth 1 enc2-str) new-str-c (nth 2 enc2-str))
1553 (setq a-res (ids-find-chars-including-ids new-str))
1558 (list ?⿲ (nth 1 enc2-str) new-str-c (nth 2 enc2-str))
1563 ((eq (car structure) ?⿵)
1564 (setq enc (nth 1 structure))
1566 (cond ((characterp enc)
1567 (get-char-attribute enc 'ideographic-structure)
1570 (cdr (assq 'ideographic-structure enc))
1573 ((eq (car enc-str) ?⿱)
1574 (setq enc2-str (ideographic-character-get-structure (nth 2 enc-str)))
1576 (eq (car enc2-str) ?⿰))
1577 (unless conversion-only
1578 (setq f-res (ids-find-chars-including-ids enc-str)))
1579 (setq new-str (list ?⿲
1584 (if (setq ret (ideographic-structure-find-chars new-str))
1586 (list (cons 'ideographic-structure new-str))))
1588 (list ?⿱ (nth 1 enc-str) new-str-c)
1589 (setq a-res (ids-find-chars-including-ids new-str))
1594 (list ?⿱ (nth 1 enc-str) new-str-c)
1598 ((eq (car enc-str) ?⿳)
1599 (setq enc2-str (ideographic-character-get-structure (nth 3 enc-str)))
1601 (eq (car enc2-str) ?⿰))
1602 (unless conversion-only
1603 (setq f-res (ids-find-chars-including-ids enc-str)))
1604 (setq new-str (list ?⿲
1609 (if (setq ret (ideographic-structure-find-chars new-str))
1611 (list (cons 'ideographic-structure new-str))))
1613 (list ?⿳ (nth 1 enc-str) (nth 2 enc-str) new-str-c)
1614 (setq a-res (ids-find-chars-including-ids new-str))
1619 (list ?⿳ (nth 1 enc-str) (nth 2 enc-str) new-str-c)
1623 ((eq (car enc-str) ?⿲)
1624 (unless conversion-only
1625 (setq f-res (ids-find-chars-including-ids enc-str)))
1626 (setq new-str (list ?⿱
1630 (if (setq ret (ideographic-structure-find-chars new-str))
1632 (list (cons 'ideographic-structure new-str))))
1634 (list ?⿲ (nth 1 enc-str) new-str-c (nth 3 enc-str))
1635 (setq a-res (ids-find-chars-including-ids new-str))
1640 (list ?⿲ (nth 1 enc-str) new-str-c (nth 3 enc-str))
1643 ((eq (car enc-str) ?⿴)
1644 (setq enc2-str (ideographic-character-get-structure (nth 1 enc-str)))
1646 (eq (car enc2-str) ?⿰))
1647 (unless conversion-only
1648 (setq f-res (ids-find-chars-including-ids enc-str)))
1649 (setq new-str (list ?⿱
1653 (if (setq ret (ideographic-structure-find-chars new-str))
1655 (list (cons 'ideographic-structure new-str))))
1657 (list ?⿲ (nth 1 enc2-str) new-str-c (nth 2 enc2-str))
1658 (setq a-res (ids-find-chars-including-ids new-str))
1663 (list ?⿲ (nth 1 enc2-str) new-str-c (nth 2 enc2-str))
1668 ((eq (car structure) ?⿻)
1669 (setq enc (nth 1 structure))
1671 (cond ((characterp enc)
1672 (get-char-attribute enc 'ideographic-structure)
1675 (cdr (assq 'ideographic-structure enc))
1678 ((eq (car enc-str) ?⿱)
1679 (unless conversion-only
1680 (setq f-res (ids-find-chars-including-ids enc-str)))
1682 (list ?⿳ (nth 1 enc-str) (nth 2 structure) (nth 2 enc-str))
1702 ;;; ids-find.el ends here