1 ;;; char-db-turtle.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 2017 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, RDF, Turtle, ISO/IEC 10646, UCS, Unicode, MULE.
8 ;; This file is part of CHISET (CHISE/Turtle).
10 ;; XEmacs CHISE 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 ;; XEmacs CHISE 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 GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs CHISE; 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 (require 'char-db-util)
28 (require 'cwiki-common)
30 (require 'ideograph-util)
32 (setq est-coded-charset-priority-list
43 =jis-x0208 =jis-x0208@1990
45 =jis-x0213-1@2000 =jis-x0213-1@2004
65 =cns11643-1 =cns11643-2 =cns11643-3
66 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
76 =zinbun-oracle =>zinbun-oracle
81 =+>ucs@iso =+>ucs@unicode
87 =>jis-x0208 =>jis-x0213-1
94 =>ucs@jis =>ucs@cns =>ucs@ks
97 =>>ucs@iso =>>ucs@unicode
98 =>>ucs@jis =>>ucs@cns =>>ucs@ks
116 ==cns11643-1 ==cns11643-2 ==cns11643-3
117 ==cns11643-4 ==cns11643-5 ==cns11643-6 ==cns11643-7
127 =>>jis-x0208 =>>jis-x0213-1 =>>jis-x0213-2
128 =+>jis-x0208 =+>jis-x0213-1 =+>jis-x0213-2
134 =jis-x0208@1983 =jis-x0208@1978
164 (defvar chise-turtle-ccs-prefix-alist nil)
166 (defun charset-code-point-format-spec (ccs)
167 (cond ((memq ccs '(=ucs))
170 (let ((ccs-name (symbol-name ccs)))
173 "\\(shinjigen\\|daikanwa/ho\\|=>iwds-1\\)"
177 "\\(gt\\|daikanwa\\|adobe-japan1\\|cbeta\\|zinbun-oracle\\|hng\\)"
180 ((string-match "\\(hanyo-denshi/ks\\|koseki\\|mj\\)" ccs-name)
182 ((string-match "hanyo-denshi/tk" ccs-name)
187 (defun chise-turtle-uri-decode-feature-name (uri-feature)
188 (cond ((string= "a.ucs" uri-feature)
190 ((string= "a.big5" uri-feature)
193 (www-uri-decode-feature-name uri-feature))))
195 (defun chise-turtle-uri-encode-ccs-name (feature-name)
197 ((eq '=ucs feature-name)
199 ((eq '=big5 feature-name)
201 ((eq '==>ucs@bucs feature-name)
204 (mapconcat (lambda (c)
213 (char-to-string c))))
214 (www-uri-encode-feature-name feature-name)
217 (defun chise-turtle-uri-encode-feature-name (feature-name)
219 ((eq '->subsumptive feature-name)
221 ((eq '<-denotational feature-name)
223 ((eq '<-formed feature-name)
225 ((eq '<-same feature-name)
227 ((eq '<-simplified feature-name)
228 "ideo:simplified-form-of")
229 ((eq '<-vulgar feature-name)
230 "ideo:vulgar-form-of")
231 ((eq '<-wrong feature-name)
232 "ideo:wrong-form-of")
233 ((eq '<-original feature-name)
234 "ideo:original-form-of")
235 ((eq '<-ancient feature-name)
236 "ideo:ancient-form-of")
237 ((eq '<-Small-Seal feature-name)
238 "ideo:Small-Seal-of")
239 ((eq '<-interchangeable feature-name)
240 "ideo:interchangeable-form-of")
241 ((eq '->interchangeable feature-name)
242 "ideo:interchangeable")
243 ((eq '->mistakable feature-name)
245 ((eq 'hanyu-dazidian feature-name)
246 "ideo:hanyu-dazidian")
248 (concat ":" (chise-turtle-uri-encode-ccs-name feature-name)))))
250 (defun chise-turtle-format-ccs-code-point (ccs code-point)
251 (let ((ccs-uri (chise-turtle-uri-encode-ccs-name ccs)))
252 (unless (assoc ccs-uri chise-turtle-ccs-prefix-alist)
253 (setq chise-turtle-ccs-prefix-alist
254 (cons (cons ccs-uri ccs)
255 chise-turtle-ccs-prefix-alist)))
258 (format (charset-code-point-format-spec ccs)
261 (defun chise-turtle-encode-char (object)
262 (let ((ccs-list est-coded-charset-priority-list)
264 (if (setq ret (encode-char object '=ucs))
265 (chise-turtle-format-ccs-code-point '=ucs ret)
267 (setq ccs (pop ccs-list))
268 (not (setq ret (encode-char object ccs 'defined-only)))))
270 (chise-turtle-format-ccs-code-point ccs ret)
272 ((and (setq ccs (car (split-char object)))
273 (setq ret (encode-char object ccs)))
274 (chise-turtle-format-ccs-code-point ccs ret)
276 ((setq ret (get-char-attribute object 'ideographic-combination))
277 (format "ideocomb:%s"
278 (mapconcat (lambda (cell)
279 (cond ((characterp cell)
280 (char-to-string cell)
282 ((setq ret2 (find-char cell))
283 (char-to-string ret2)
291 (format (if est-hide-cgi-mode
292 "system-char-id=0x%X"
293 "system-char-id:0x%X")
294 (encode-char object 'system-char-id))
297 (defun chise-split-feature-name (feature-name)
298 (let (base domain number meta)
299 (setq feature-name (symbol-name feature-name))
300 (if (string-match ".\\*." feature-name)
302 (format ":%s" (substring feature-name (1- (match-end 0)))))
303 feature-name (substring feature-name 0 (1+ (match-beginning 0)))))
304 (if (string-match "\\$_\\([0-9]+\\)$" feature-name)
305 (setq number (car (read-from-string (match-string 1 feature-name)))
306 feature-name (substring feature-name 0 (match-beginning 0))))
307 (if (string-match "@" feature-name)
308 (setq domain (car (read-from-string (substring feature-name (match-end 0))))
309 base (intern (substring feature-name 0 (match-beginning 0))))
310 (setq base (intern feature-name)))
311 (list base domain number meta)))
313 (defun chise-compose-feature-name (base domain number meta)
314 (let ((name (if domain
315 (format "%s@%s" base domain)
316 (symbol-name base))))
318 (setq name (format "%s$_%d" name number)))
320 (setq name (format "%s*%s" name
321 (substring (symbol-name meta) 1))))
324 (defvar chise-feature-name-base-metadata-alist nil)
326 (defun chise-update-feature-name-base-metadata-alist ()
328 (let (base domain number metadata
329 bcell dcell ncell ret)
330 (setq chise-feature-name-base-metadata-alist nil)
331 (dolist (fname (sort (char-attribute-list)
332 #'char-attribute-name<))
333 (setq ret (chise-split-feature-name fname)
337 metadata (nth 3 ret))
339 (if (setq bcell (assq base chise-feature-name-base-metadata-alist))
340 (if (setq dcell (assq domain (cdr bcell)))
341 (if (setq ncell (assq number (cdr dcell)))
342 (unless (memq metadata (cdr ncell))
343 (setcdr ncell (nconc (cdr ncell)
345 (setcdr dcell (cons (list number metadata)
347 (setcdr bcell (cons (list domain (list number metadata))
349 (setq chise-feature-name-base-metadata-alist
350 (cons (list base (list domain (list number metadata)))
351 chise-feature-name-base-metadata-alist))
354 (chise-update-feature-name-base-metadata-alist)
356 (defun chise-get-char-attribute-with-metadata (character feature-name-base domain)
357 (let ((value (get-char-attribute
359 (chise-compose-feature-name feature-name-base domain nil nil)
360 '*feature-value-is-empty*))
362 base-metadata metadata
364 (unless (eq value '*feature-value-is-empty*)
366 ((and (setq ret (assq feature-name-base
367 chise-feature-name-base-metadata-alist))
368 (setq dcell (assq domain (cdr ret))))
369 (if (setq ret (assq nil (cdr dcell)))
370 (dolist (bmn (cdr ret))
371 (when (setq m (get-char-attribute
373 (chise-compose-feature-name
374 feature-name-base domain nil bmn)))
376 (list* bmn m base-metadata)))))
382 ((setq ret (assq i (cdr dcell)))
384 (dolist (mn (cdr ret))
385 (when (setq m (get-char-attribute
387 (chise-compose-feature-name
388 feature-name-base domain i mn)))
389 (setq metadata (list* mn m metadata))))
391 (list* :target (car rest) metadata)
398 (list (nconc (nreverse dest) rest)
401 (t (list value nil)))
404 (defun chise-split-ccs-name (ccs)
405 (cond ((eq ccs '=ucs)
406 '(ucs abstract-character nil)
409 '(big5 abstract-character nil)
412 (setq ccs (symbol-name ccs))
414 (if (string-match "^\\(=[=+>]*\\)\\([^=>@*]+\\)@?" ccs)
415 (list (intern (match-string 2 ccs))
416 (chise-decode-ccs-prefix (match-string 1 ccs))
417 (if (string= (setq ret (substring ccs (match-end 0))) "")
422 (defun chise-decode-ccs-prefix (ccs)
423 (or (cdr (assoc ccs '(("==>" . super-abstract-character)
424 ("=>" . abstract-character)
425 ("=+>" . unified-glyph)
426 ("=" . abstract-glyph)
427 ("=>>" . detailed-glyph)
428 ("==" . abstract-glyph-form)
429 ("===" . glyph-image))))
432 (defun chise-turtle-uri-split-ccs (uri-ccs)
434 ((string-match "^a2\\." uri-ccs)
435 (cons ":super-abstract-character"
436 (substring uri-ccs (match-end 0)))
438 ((string-match "^a\\." uri-ccs)
439 (cons ":abstract-character"
440 (substring uri-ccs (match-end 0)))
442 ((string-match "^o\\." uri-ccs)
443 (cons ":unified-glyph"
444 (substring uri-ccs (match-end 0)))
446 ((string-match "^rep\\." uri-ccs)
447 (cons ":abstract-glyph"
448 (substring uri-ccs (match-end 0)))
450 ((string-match "^g\\." uri-ccs)
451 (cons ":detailed-glyph"
452 (substring uri-ccs (match-end 0)))
454 ((string-match "^g2\\." uri-ccs)
455 (cons ":abstract-glyph-form"
456 (substring uri-ccs (match-end 0)))
458 ((string-match "^gi\\." uri-ccs)
459 (cons ":abstract-glyph-form"
460 (substring uri-ccs (match-end 0)))
462 ((string-match "^repi\\." uri-ccs)
464 (substring uri-ccs (match-end 0)))
466 (t (cons ":character" uri-ccs))))
468 (defun char-db-turtle-insert-relation-feature (char name value line-breaking
470 (insert (format " %s%s "
471 (chise-turtle-uri-encode-feature-name name)
473 (char-db-turtle-insert-relations value readable)
477 (defun char-db-turtle-insert-metadata (name value)
479 (insert (format "%-7s " name))
481 ((or (eq name :sources)
483 (setq col (current-column))
484 (setq indent (make-string col ?\ ))
485 (insert (format "chisebib:%s"
486 (chise-turtle-uri-encode-ccs-name (car value))))
487 (dolist (source (cdr value))
488 (insert (format " ,\n%schisebib:%s" indent
489 (chise-turtle-uri-encode-ccs-name source))))
492 (insert (format "%S" value))
495 (defun char-db-turtle-insert-radical (radical-number)
496 (insert (format " %3d ; # %c"
498 (ideographic-radical radical-number)))
501 (defun char-db-turtle-insert-list (value &optional readable)
502 (let (lbs separator rest cell al cal key ret)
504 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
507 (setq cell (car value))
508 (if (and (consp cell)
510 (setq ret (condition-case nil
518 (setq key (car (car rest)))
519 (if (find-charset key)
520 (setq cal (cons key cal))
521 (setq al (cons key al)))
522 (setq rest (cdr rest)))
525 (char-db-turtle-insert-char-features ret
529 (setq separator lbs))
530 (setq ret (prin1-to-string cell))
532 (if (< (+ (current-column)
539 (setq separator " "))
540 (setq value (cdr value)))
544 (defun char-db-turtle-insert-source-list (value &optional readable)
545 (let (lbs separator rest cell al cal key ret)
546 (setq lbs (concat " ,\n" (make-string (current-column) ?\ ))
549 (setq cell (car value))
550 (if (and (consp cell)
552 (setq ret (condition-case nil
560 (setq key (car (car rest)))
561 (if (find-charset key)
562 (setq cal (cons key cal))
563 (setq al (cons key al)))
564 (setq rest (cdr rest)))
567 (char-db-turtle-insert-char-features ret
571 (setq separator lbs))
572 (setq ret (prin1-to-string cell))
574 (if (< (+ (current-column)
580 (if (string-match "=" ret)
581 (insert (format "%s:%s"
582 (substring ret 0 (match-beginning 0))
583 (substring ret (match-end 0))))
584 (insert (format "chisebib:%s" ret)))
585 (setq separator " , "))
586 (setq value (cdr value)))
590 (defun char-db-turtle-insert-relations (value &optional readable)
591 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
593 (if (characterp value)
594 (setq value (list value)))
596 (setq cell (car value))
598 (setq cell (decode-char '=ucs cell)))
601 (setq separator (format " ,%s" lbs)))
602 (if (characterp cell)
603 (insert (format "%-20s" (chise-turtle-encode-char cell)))
604 (char-db-turtle-insert-char-ref cell '<-formed))
605 (setq value (cdr value)))
608 (defun char-db-turtle-insert-target-value (value feature-name-base &optional readable)
609 (cond ((eq feature-name-base 'ideographic-radical)
610 (char-db-turtle-insert-radical value)
612 ((or (eq feature-name-base 'ideographic-combination)
613 (eq feature-name-base '=decomposition)
614 (eq feature-name-base '<-formed)
615 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name feature-name-base)))
616 (char-db-turtle-insert-relations value readable)
618 ((eq feature-name-base 'comment)
619 (insert (format "%S" value))
621 ((eq feature-name-base 'sources)
622 (char-db-turtle-insert-source-list value readable)
625 (char-db-turtle-insert-list value readable)
628 (insert (format " %-14s" value))
631 (defun char-db-turtle-insert-feature-value (value metadata domain feature-name-base)
632 (let (indent0 indent rest mdname mdval lb)
634 ((or metadata domain)
635 (setq indent0 (make-string (current-column) ?\ ))
637 (setq indent (make-string (current-column) ?\ ))
639 (insert (format ":context domain:%-7s ;"
640 (chise-turtle-uri-encode-ccs-name domain)))
644 (setq mdname (pop rest)
647 (insert (format "\n%s" indent))
649 (unless (char-db-turtle-insert-metadata mdname mdval)
652 (insert (format "\n%s" indent)))
654 (if (char-db-turtle-insert-target-value value feature-name-base)
655 (insert (format "\n%s] ;" indent0))
659 (char-db-turtle-insert-target-value value feature-name-base)
662 (defun char-db-turtle-insert-char-ref (char-ref feature-name-base)
663 (let (indent0 indent rest mdname mdval lb last-sep)
664 (setq indent0 (make-string (current-column) ?\ ))
666 (setq indent (make-string (current-column) ?\ ))
669 (setq mdname (pop rest)
672 (insert (format "%s\n%s"
679 (cond ((eq mdname :target)
681 (char-db-turtle-insert-target-value mdval feature-name-base)
684 (char-db-turtle-insert-metadata mdname mdval)))))
686 (insert (format "\n%s]" indent0))
690 (defun char-db-turtle-insert-char-features (char
691 &optional readable attributes column
694 (setq column (current-column)))
695 (let ((est-coded-charset-priority-list est-coded-charset-priority-list)
696 (est-view-url-prefix "http://chise.org/est/view")
697 id obj-id type domain
699 name-base name-domain
701 (line-breaking (concat "\n" (make-string column ?\ )))
705 dest-ccss ; sources required-features
707 uri-ccs uri-cpos ccs-base children child-ccs-list col indent)
711 (if (consp attributes)
713 (dolist (name attributes)
714 (unless (or (memq name char-db-ignored-attributes)
715 (string-match "\\*" (symbol-name name)))
716 (if (find-charset name)
720 (dolist (name (char-attribute-list))
721 (unless (or (memq name char-db-ignored-attributes)
722 (string-match "\\*" (symbol-name name)))
723 (if (find-charset name)
727 #'char-attribute-name<)))
728 (setq line-separator line-breaking)
729 (setq id (chise-turtle-encode-char char))
730 (setq obj-id (file-name-nondirectory id))
731 (string-match ":" obj-id)
732 (setq uri-ccs (substring obj-id 0 (match-beginning 0))
733 uri-cpos (substring obj-id (match-end 0)))
734 (insert (format "%s" obj-id))
735 (setq ret (assoc uri-ccs chise-turtle-ccs-prefix-alist))
736 (setq dest-ccss (list (cdr ret)))
737 (setq ret (chise-split-ccs-name (cdr ret)))
738 (setq ccs-base (car ret)
741 (insert (format "%s a chisegg:%s ;" line-separator type))
742 (insert (format "%s :%s-of" line-breaking type))
744 (insert (format " %s:%s ;"
745 (chise-turtle-uri-encode-ccs-name ccs-base) uri-cpos))
747 (setq col (current-column))
748 (insert (format ":context domain:%-7s ;\n%s:target %7s:%-7s ] ;"
749 (chise-turtle-uri-encode-ccs-name domain)
750 (make-string col ?\ )
751 (chise-turtle-uri-encode-ccs-name ccs-base) uri-cpos)))
752 (when (memq '<-subsumptive attributes)
753 (when (or readable (not for-sub-node))
754 (when (setq value (get-char-attribute char '<-subsumptive))
755 (insert line-separator)
756 (char-db-turtle-insert-relation-feature char '<-subsumptive value
760 (setq attributes (delq '<-subsumptive attributes))
762 (when (and (memq '<-denotational attributes)
763 (setq value (get-char-attribute char '<-denotational)))
764 (insert line-separator)
765 (char-db-turtle-insert-relation-feature char '<-denotational value
768 (setq attributes (delq '<-denotational attributes)))
769 (when (and (memq '<-denotational@component attributes)
771 (get-char-attribute char '<-denotational@component)))
772 (insert line-separator)
773 (char-db-turtle-insert-relation-feature
774 char '<-denotational@component value
777 (setq attributes (delq '<-denotational@component attributes)))
778 (when (and (memq 'name attributes)
779 (setq value (get-char-attribute char 'name)))
780 (insert (format "%s " line-separator))
782 (if (> (+ (current-column) (length value)) 48)
786 (setq attributes (delq 'name attributes))
788 (when (and (memq 'name* attributes)
789 (setq value (get-char-attribute char 'name*)))
790 (insert line-separator)
792 (if (> (+ (current-column) (length value)) 48)
796 (setq attributes (delq 'name* attributes))
798 (when (and (memq 'script attributes)
799 (setq value (get-char-attribute char 'script)))
800 (insert (format "%s :script\t\t ( %s ) ;"
802 (mapconcat (lambda (cell)
803 (format "script:%s" cell))
805 (setq attributes (delq 'script attributes))
807 ;; (dolist (name '(=>ucs =>ucs*))
808 ;; (when (and (memq name attributes)
809 ;; (setq value (get-char-attribute char name)))
810 ;; (insert line-separator)
811 ;; (insert (format " \"%-20s\": #x%04X,\t\"_comment\": \"%c\""
812 ;; name value (decode-char '=ucs value)))
813 ;; (setq attributes (delq name attributes))))
814 (when (and (memq '=>ucs attributes)
815 (setq value (get-char-attribute char '=>ucs)))
816 (insert (format "%s :to.ucs\t\t a.ucs:0x%04X ; # %c"
817 line-separator value (decode-char '=ucs value)))
818 (setq attributes (delq '=>ucs attributes))
820 (when (setq value (get-char-attribute char '=>ucs*))
821 (insert (format "%s :to.canonical-ucs\ta.ucs:0x%04X ; # %c"
822 line-separator value (decode-char '=ucs value)))
823 (setq attributes (delq '=>ucs* attributes))
825 (dolist (name '(=>ucs@gb =>ucs@big5))
826 (when (and (memq name attributes)
827 (setq value (get-char-attribute char name)))
828 (insert line-separator)
829 (insert (format " \"%-20s\": #x%04X,\t\"_comment\": \"%c\"%s"
834 (symbol-name name) 2)))
837 (setq attributes (delq name attributes))
839 (when (and (memq 'general-category attributes)
840 (setq value (get-char-attribute char 'general-category)))
841 (insert (format "%s :general-category \"%s\" ; # %s"
843 (cond ((rassoc value unidata-normative-category-alist)
844 "Normative Category")
845 ((rassoc value unidata-informative-category-alist)
846 "Informative Category")
848 "Unknown Category"))))
849 (setq attributes (delq 'general-category attributes))
851 (when (and (memq 'bidi-category attributes)
852 (setq value (get-char-attribute char 'bidi-category)))
853 (insert (format "%s :bidi-category %S ;"
856 (setq attributes (delq 'bidi-category attributes))
858 (unless (or (not (memq 'mirrored attributes))
859 (eq (setq value (get-char-attribute char 'mirrored 'empty))
861 (insert (format "%s :mirrored \"%s\" ;"
864 (setq attributes (delq 'mirrored attributes))
867 ((and (memq 'decimal-digit-value attributes)
868 (setq value (get-char-attribute char 'decimal-digit-value)))
869 (insert (format "%s :decimal-digit-value %2d ;"
870 line-separator value))
871 (setq attributes (delq 'decimal-digit-value attributes))
872 (when (and (memq 'digit-value attributes)
873 (setq value (get-char-attribute char 'digit-value)))
874 (insert (format "%s :digit-value\t %2d ;"
875 line-separator value))
876 (setq attributes (delq 'digit-value attributes))
878 (when (and (memq 'numeric-value attributes)
879 (setq value (get-char-attribute char 'numeric-value)))
880 (insert (format "%s :numeric-value\t %2d ;"
881 line-separator value))
882 (setq attributes (delq 'numeric-value attributes))
886 (when (and (memq 'digit-value attributes)
887 (setq value (get-char-attribute char 'digit-value)))
888 (insert line-separator)
889 (insert (format "%s :digit-value\t %2d ;"
890 line-separator value))
891 (setq attributes (delq 'digit-value attributes))
893 (when (and (memq 'numeric-value attributes)
894 (setq value (get-char-attribute char 'numeric-value)))
895 (insert line-separator)
896 (insert (format "%s :numeric-value\t %2d ;"
897 line-separator value))
898 (setq attributes (delq 'numeric-value attributes))
900 (when (and (memq 'iso-10646-comment attributes)
901 (setq value (get-char-attribute char 'iso-10646-comment)))
902 (insert line-separator)
903 (insert (format "{\"iso-10646-comment\":\t %S}%s"
906 (setq attributes (delq 'iso-10646-comment attributes))
908 (when (and (memq 'morohashi-daikanwa attributes)
909 (setq value (get-char-attribute char 'morohashi-daikanwa)))
910 (insert line-separator)
911 (insert (format "%s :morohashi-daikanwa\t %S ;"
912 line-separator value))
913 (setq attributes (delq 'morohashi-daikanwa attributes))
917 (when (and (memq 'ideographic-radical attributes)
918 (setq value (get-char-attribute char 'ideographic-radical)))
920 (insert (format "%s ideo:radical %3d ; # %c "
923 (ideographic-radical radical)
925 (setq attributes (delq 'ideographic-radical attributes))
927 (when (and (memq 'shuowen-radical attributes)
928 (setq value (get-char-attribute char 'shuowen-radical)))
929 (insert line-separator)
930 (insert (format " \"shuowen-radical\":\t %S,\t\"_comment\": \"%c\""
932 (shuowen-radical value)))
933 (setq attributes (delq 'shuowen-radical attributes))
938 char-db-feature-domains
940 (dolist (feature (char-attribute-list))
941 (setq feature (symbol-name feature))
943 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
945 (setq domain (intern (match-string 2 feature)))
946 (unless (memq domain dest)
947 (setq dest (cons domain dest)))))
948 (sort dest #'string<))))
949 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
950 (when (and (memq key attributes)
951 (setq value (get-char-attribute char key)))
953 (insert (format "%s ideo:radical "
955 (char-db-turtle-insert-feature-value value nil domain 'ideographic-radical)
956 (setq attributes (delq key attributes))
958 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
959 (when (and (memq key attributes)
960 (setq value (get-char-attribute char key)))
962 (insert (format "%s ideo:strokes [ "
964 (setq col (current-column))
965 (setq indent (make-string col ?\ ))
966 (insert (format ":context domain:%-7s ;\n%s:target %S"
967 (chise-turtle-uri-encode-ccs-name domain)
969 (setq attributes (delq key attributes))
970 (setq skey (intern (format "%s*sources" key)))
971 (when (and (memq skey attributes)
972 (setq value (get-char-attribute char skey)))
973 (insert (format " ;\n%s:sources (" indent))
974 (setq col (current-column))
975 (setq indent (make-string col ?\ ))
976 (insert (format " chisebib:%s" (car value)))
977 (dolist (cell (cdr value))
978 (insert (format "\n%s chisebib:%s" indent cell)))
980 (setq attributes (delq skey attributes))
983 (setq key (intern (format "%s@%s" 'total-strokes domain)))
984 (when (and (memq key attributes)
985 (setq value (get-char-attribute char key)))
986 (insert (format "%s ideo:total-strokes [ "
988 (setq col (current-column))
989 (insert (format ":context domain:%-7s ;\n%s:target %S"
990 (chise-turtle-uri-encode-ccs-name domain)
991 (make-string col ?\ )
993 (setq attributes (delq key attributes))
994 (setq skey (intern (format "%s*sources" key)))
997 (dolist (feature '(ideographic-radical
1000 (setq key (intern (format "%s@%s*sources" feature domain)))
1001 (when (and (memq key attributes)
1002 (setq value (get-char-attribute char key)))
1003 (insert line-separator)
1004 (insert (format " \"%s\":%s" key line-breaking))
1005 (dolist (cell value)
1006 (insert (format " %s" cell)))
1007 (setq attributes (delq key attributes))
1010 (when (and (memq 'ideographic-strokes attributes)
1011 (setq value (get-char-attribute char 'ideographic-strokes)))
1012 (setq strokes value)
1013 (insert (format "%s ideo:strokes %2d ;"
1014 line-separator strokes))
1015 (setq attributes (delq 'ideographic-strokes attributes))
1017 (when (and (memq 'kangxi-radical attributes)
1018 (setq value (get-char-attribute char 'kangxi-radical)))
1019 (unless (eq value radical)
1020 (insert line-separator)
1021 (insert (format "{\"kangxi-radical\":\t%S},\t\"_comment\": \"%c\"%s"
1023 (ideographic-radical value)
1026 (setq radical value)))
1027 (setq attributes (delq 'kangxi-radical attributes))
1029 (when (and (memq 'kangxi-strokes attributes)
1030 (setq value (get-char-attribute char 'kangxi-strokes)))
1031 (unless (eq value strokes)
1032 (insert line-separator)
1033 (insert (format "{\"kangxi-strokes\":\t%S}%s"
1037 (setq strokes value)))
1038 (setq attributes (delq 'kangxi-strokes attributes))
1040 (when (and (memq 'japanese-strokes attributes)
1041 (setq value (get-char-attribute char 'japanese-strokes)))
1042 (unless (eq value strokes)
1043 (insert line-separator)
1044 (insert (format "{\"japanese-strokes\":\t%S}%s"
1048 (setq strokes value)))
1049 (setq attributes (delq 'japanese-strokes attributes))
1051 (when (and (memq 'cns-radical attributes)
1052 (setq value (get-char-attribute char 'cns-radical)))
1053 (insert line-separator)
1054 (insert (format "{\"cns-radical\":\t%S},\t\"_comment\": \"%c\"%s"
1056 (ideographic-radical value)
1058 (setq attributes (delq 'cns-radical attributes))
1060 (when (and (memq 'cns-strokes attributes)
1061 (setq value (get-char-attribute char 'cns-strokes)))
1062 (unless (eq value strokes)
1063 (insert line-separator)
1064 (insert (format "{\"cns-strokes\":\t%S}%s"
1068 (setq strokes value)))
1069 (setq attributes (delq 'cns-strokes attributes))
1071 (when (and (memq 'total-strokes attributes)
1072 (setq value (get-char-attribute char 'total-strokes)))
1073 (insert (format "%s ideo:total-strokes %2d ;"
1074 line-separator value))
1075 (setq attributes (delq 'total-strokes attributes))
1077 (if (equal (get-char-attribute char '->titlecase)
1078 (get-char-attribute char '->uppercase))
1079 (setq attributes (delq '->titlecase attributes)))
1081 (dolist (ignored '(composition
1082 ->denotational <-subsumptive ->ucs-unified
1083 ->ideographic-component-forms))
1084 (setq attributes (delq ignored attributes))))
1086 (setq name (car attributes))
1087 (setq ret (chise-split-feature-name name))
1088 (setq name-base (car ret)
1089 name-domain (nth 1 ret))
1090 (when (setq value (chise-get-char-attribute-with-metadata
1091 char name-base name-domain))
1092 (setq metadata (nth 1 value)
1094 (cond ((setq ret (find-charset name))
1095 (setq name (charset-name ret))
1096 (when (not (memq name dest-ccss))
1097 (setq dest-ccss (cons name dest-ccss))
1099 (insert (format "%s :%-25s rdf:nil ;" line-separator
1100 (chise-turtle-uri-encode-ccs-name name)))
1101 (setq ret (chise-turtle-format-ccs-code-point name value))
1102 (insert (format "%s :eq %-25s ; # %c" line-separator
1104 (char-db-decode-isolated-char name value)))
1105 (setq eq-cpos-list (cons (list ret name value) eq-cpos-list))))
1107 (setq ret (if (eq name '=ucs)
1108 (if (< value #x10000)
1111 (intern (format "=%s" name)))))
1112 (setq child-ccs-list (cons ret child-ccs-list)))
1116 (not (eq name '->subsumptive))
1117 (not (eq name '->uppercase))
1118 (not (eq name '->lowercase))
1119 (not (eq name '->titlecase))
1120 (not (eq name '->canonical))
1121 (not (eq name '->Bopomofo))
1122 (not (eq name '->mistakable))
1123 (not (eq name '->ideographic-variants))
1124 (or (eq name '<-identical)
1125 (eq name '<-uppercase)
1126 (eq name '<-lowercase)
1127 (eq name '<-titlecase)
1128 (eq name '<-canonical)
1129 (eq name '<-ideographic-variants)
1130 ;; (eq name '<-synonyms)
1131 (string-match "^<-synonyms" (symbol-name name))
1132 (eq name '<-mistakable)
1133 (when (string-match "^->" (symbol-name name))
1135 ((string-match "^->fullwidth" (symbol-name name))
1136 (not (and (consp value)
1137 (characterp (car value))
1139 (car value) '=ucs 'defined-only)))
1144 ((eq name 'ideographic-structure)
1145 (insert (isd-turtle-format-char nil nil value (/ column 4)
1146 'isd 'without-head-char))
1149 ((eq name '->subsumptive)
1150 (insert line-separator)
1151 (char-db-turtle-insert-relation-feature char name value
1154 (setq children value)
1157 (insert (format "%s %-20s "
1159 (chise-turtle-uri-encode-feature-name name-base)))
1160 (unless (char-db-turtle-insert-feature-value
1161 value metadata name-domain name-base)
1165 (setq attributes (cdr attributes)))
1166 (insert (format "%s ." line-breaking))
1167 (dolist (eq-cpos (nreverse eq-cpos-list))
1168 (setq ret (chise-split-ccs-name (nth 1 eq-cpos)))
1169 (insert (format "%s %s" line-breaking
1171 (insert (format "%s %25s" line-breaking
1172 (format ":%s-of" (nth 1 ret))))
1173 (if (null (nth 2 ret))
1174 (insert (format " %14s:%-7s ."
1175 (chise-turtle-uri-encode-ccs-name (car ret))
1176 (nth 1 (split-string (car eq-cpos) ":"))))
1178 (setq col (current-column))
1179 (insert (format ":context domain:%-7s ;\n%s:target %7s:%-7s ] ."
1180 (chise-turtle-uri-encode-ccs-name (nth 2 ret))
1181 (make-string col ?\ )
1182 (chise-turtle-uri-encode-ccs-name (car ret))
1183 (nth 1 (split-string (car eq-cpos) ":"))))))
1184 (setq est-coded-charset-priority-list
1185 (append est-coded-charset-priority-list
1186 (nreverse child-ccs-list)))
1188 (dolist (child children)
1189 (insert (format "%s " line-breaking))
1190 (char-db-turtle-insert-char-features child nil nil nil 'for-sub-node)))
1193 (defun char-db-turtle-insert-char-data (char &optional readable attributes)
1195 (narrow-to-region (point)(point))
1196 (char-db-turtle-insert-char-features char readable attributes)
1200 (defun char-db-turtle-insert-prefix ()
1201 (let (base-ccs-list ret)
1202 (insert "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
1203 @prefix : <http://rdf.chise.org/rdf/property/character/main/> .
1204 @prefix ideo: <http://rdf.chise.org/rdf/property/character/ideo/> .
1205 @prefix isd: <http://rdf.chise.org/rdf/property/character/isd/> .
1206 @prefix idc: <http://rdf.chise.org/rdf/type/character/idc/> .
1207 @prefix chisegg: <http://rdf.chise.org/rdf/type/character/ggg/> .
1208 @prefix domain: <http://rdf.chise.org/data/domain/> .
1209 @prefix script: <http://rdf.chise.org/data/script/> .
1210 @prefix ideocomb: <http://rdf.chise.org/data/character/ideo/combination/> .
1211 @prefix chisebib: <http://rdf.chise.org/data/bibliography/> .
1212 @prefix ruimoku: <http://www.chise.org/est/view/article@ruimoku/rep.id=/> .
1213 @prefix zob1959: <http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/> .
1216 (dolist (cell (sort chise-turtle-ccs-prefix-alist
1218 (char-attribute-name< (cdr a)(cdr b)))))
1219 (insert (format "@prefix %s: <%s/%s=> .\n"
1221 "http://www.chise.org/est/view/character"
1222 (www-uri-encode-feature-name (cdr cell))))
1223 (setq ret (chise-split-ccs-name (cdr cell)))
1224 (unless (memq (car ret) base-ccs-list)
1225 (setq base-ccs-list (cons (car ret) base-ccs-list))))
1227 (dolist (base-ccs (nreverse base-ccs-list))
1228 (insert (format "@prefix %s: <%s/%s/code-point/> .\n"
1229 (chise-turtle-uri-encode-ccs-name base-ccs)
1230 "http://rdf.chise.org/data/ccs"
1231 (www-uri-encode-feature-name base-ccs))))))
1233 (defun char-db-turtle-insert-ideograph-radical-char-data (radical)
1235 (sort (copy-list (aref ideograph-radical-chars-vector radical))
1237 (ideograph-char< a b radical))))
1239 (dolist (name (char-attribute-list))
1240 (unless (memq name char-db-ignored-attributes)
1241 (push name attributes)
1243 (setq attributes (sort attributes #'char-attribute-name<))
1244 (aset ideograph-radical-chars-vector radical chars)
1245 (dolist (char chars)
1246 (when (not (some (lambda (atr)
1247 (get-char-attribute char atr))
1248 char-db-ignored-attributes))
1249 (char-db-turtle-insert-char-data char nil attributes)))
1252 (defun char-db-turtle-write-ideograph-radical-char-data (radical file)
1253 (if (file-directory-p file)
1254 (let ((name (char-feature (decode-char 'ucs (+ #x2EFF radical))
1256 (if (string-match "KANGXI RADICAL " name)
1257 (setq name (capitalize (substring name (match-end 0)))))
1258 (setq name (mapconcat (lambda (char)
1261 (char-to-string char))) name ""))
1264 (format "Ideograph-R%03d-%s.ttl" radical name)
1266 (let (chise-turtle-ccs-prefix-alist)
1268 (char-db-turtle-insert-ideograph-radical-char-data radical)
1269 (goto-char (point-min))
1270 (char-db-turtle-insert-prefix)
1272 (goto-char (point-min))
1273 (insert (format "# -*- coding: %s -*-\n"
1274 char-db-file-coding-system))
1275 (let ((coding-system-for-write char-db-file-coding-system))
1276 (write-region (point-min)(point-max) file)))))
1282 (provide 'char-db-turtle)
1284 ;;; char-db-turtle.el ends here