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
64 =cns11643-1 =cns11643-2 =cns11643-3
65 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
75 =zinbun-oracle =>zinbun-oracle
80 =+>ucs@iso =+>ucs@unicode
86 =>jis-x0208 =>jis-x0213-1
93 =>ucs@jis =>ucs@cns =>ucs@ks
96 =>>ucs@iso =>>ucs@unicode
97 =>>ucs@jis =>>ucs@cns =>>ucs@ks
115 ==cns11643-1 ==cns11643-2 ==cns11643-3
116 ==cns11643-4 ==cns11643-5 ==cns11643-6 ==cns11643-7
126 =>>jis-x0208 =>>jis-x0213-1 =>>jis-x0213-2
127 =+>jis-x0208 =+>jis-x0213-1 =+>jis-x0213-2
133 =jis-x0208@1983 =jis-x0208@1978
162 (defvar chise-turtle-ccs-prefix-alist nil)
164 (defun charset-code-point-format-spec (ccs)
165 (cond ((memq ccs '(=ucs))
168 (let ((ccs-name (symbol-name ccs)))
171 "\\(shinjigen\\|daikanwa/ho\\|=>iwds-1\\)"
175 "\\(gt\\|daikanwa\\|adobe-japan1\\|cbeta\\|zinbun-oracle\\|hng\\)"
178 ((string-match "\\(hanyo-denshi/ks\\|koseki\\|mj\\)" ccs-name)
180 ((string-match "hanyo-denshi/tk" ccs-name)
185 (defun chise-turtle-uri-decode-feature-name (uri-feature)
186 (cond ((string= "a.ucs" uri-feature)
188 ((string= "a.big5" uri-feature)
191 (www-uri-decode-feature-name uri-feature))))
193 (defun chise-turtle-uri-encode-ccs-name (feature-name)
195 ((eq '=ucs feature-name)
197 ((eq '=big5 feature-name)
199 ((eq '==>ucs@bucs feature-name)
202 (mapconcat (lambda (c)
211 (char-to-string c))))
212 (www-uri-encode-feature-name feature-name)
215 (defun chise-turtle-uri-encode-feature-name (feature-name)
217 ((eq '->subsumptive feature-name)
219 ((eq '<-denotational feature-name)
221 ((eq '<-formed feature-name)
223 ((eq '<-same feature-name)
225 ((eq '<-simplified feature-name)
226 "ideo:simplified-form-of")
227 ((eq '<-vulgar feature-name)
228 "ideo:vulgar-form-of")
229 ((eq '<-ancient feature-name)
230 "ideo:ancient-form-of")
231 ((eq '->mistakable feature-name)
233 ((eq 'hanyu-dazidian feature-name)
234 "ideo:hanyu-dazidian")
236 (concat ":" (chise-turtle-uri-encode-ccs-name feature-name)))))
238 (defun chise-turtle-format-ccs-code-point (ccs code-point)
239 (let ((ccs-uri (chise-turtle-uri-encode-ccs-name ccs)))
240 (unless (assoc ccs-uri chise-turtle-ccs-prefix-alist)
241 (setq chise-turtle-ccs-prefix-alist
242 (cons (cons ccs-uri ccs)
243 chise-turtle-ccs-prefix-alist)))
246 (format (charset-code-point-format-spec ccs)
249 (defun chise-turtle-encode-char (object)
250 (let ((ccs-list est-coded-charset-priority-list)
252 (if (setq ret (encode-char object '=ucs))
253 (chise-turtle-format-ccs-code-point '=ucs ret)
255 (setq ccs (pop ccs-list))
256 (not (setq ret (encode-char object ccs 'defined-only)))))
258 (chise-turtle-format-ccs-code-point ccs ret)
260 ((and (setq ccs (car (split-char object)))
261 (setq ret (encode-char object ccs)))
262 (chise-turtle-format-ccs-code-point ccs ret)
264 ((setq ret (get-char-attribute object 'ideographic-combination))
265 (format "ideocomb:%s"
266 (mapconcat (lambda (cell)
267 (cond ((characterp cell)
268 (char-to-string cell)
270 ((setq ret2 (find-char cell))
271 (char-to-string ret2)
279 (format (if est-hide-cgi-mode
280 "system-char-id=0x%X"
281 "system-char-id:0x%X")
282 (encode-char object 'system-char-id))
285 (defun chise-split-feature-name (feature-name)
286 (let (base domain number meta)
287 (setq feature-name (symbol-name feature-name))
288 (if (string-match ".\\*." feature-name)
290 (format ":%s" (substring feature-name (1- (match-end 0)))))
291 feature-name (substring feature-name 0 (1+ (match-beginning 0)))))
292 (if (string-match "\\$_\\([0-9]+\\)$" feature-name)
293 (setq number (car (read-from-string (match-string 1 feature-name)))
294 feature-name (substring feature-name 0 (match-beginning 0))))
295 (if (string-match "@" feature-name)
296 (setq domain (car (read-from-string (substring feature-name (match-end 0))))
297 base (intern (substring feature-name 0 (match-beginning 0))))
298 (setq base (intern feature-name)))
299 (list base domain number meta)))
301 (defun chise-compose-feature-name (base domain number meta)
302 (let ((name (if domain
303 (format "%s@%s" base domain)
304 (symbol-name base))))
306 (setq name (format "%s$_%d" name number)))
308 (setq name (format "%s*%s" name
309 (substring (symbol-name meta) 1))))
312 (defvar chise-feature-name-base-metadata-alist nil)
314 (defun chise-update-feature-name-base-metadata-alist ()
316 (let (base domain number metadata
317 bcell dcell ncell ret)
318 (setq chise-feature-name-base-metadata-alist nil)
319 (dolist (fname (sort (char-attribute-list)
320 #'char-attribute-name<))
321 (setq ret (chise-split-feature-name fname)
325 metadata (nth 3 ret))
327 (if (setq bcell (assq base chise-feature-name-base-metadata-alist))
328 (if (setq dcell (assq domain (cdr bcell)))
329 (if (setq ncell (assq number (cdr dcell)))
330 (unless (memq metadata (cdr ncell))
331 (setcdr ncell (nconc (cdr ncell)
333 (setcdr dcell (cons (list number metadata)
335 (setcdr bcell (cons (list domain (list number metadata))
337 (setq chise-feature-name-base-metadata-alist
338 (cons (list base (list domain (list number metadata)))
339 chise-feature-name-base-metadata-alist))
342 (chise-update-feature-name-base-metadata-alist)
344 (defun chise-get-char-attribute-with-metadata (character feature-name-base domain)
345 (let ((value (get-char-attribute
347 (chise-compose-feature-name feature-name-base domain nil nil)
348 '*feature-value-is-empty*))
350 base-metadata metadata
352 (unless (eq value '*feature-value-is-empty*)
354 ((and (setq ret (assq feature-name-base
355 chise-feature-name-base-metadata-alist))
356 (setq dcell (assq domain (cdr ret))))
357 (if (setq ret (assq nil (cdr dcell)))
358 (dolist (bmn (cdr ret))
359 (when (setq m (get-char-attribute
361 (chise-compose-feature-name
362 feature-name-base domain nil bmn)))
364 (list* bmn m base-metadata)))))
370 ((setq ret (assq i (cdr dcell)))
372 (dolist (mn (cdr ret))
373 (when (setq m (get-char-attribute
375 (chise-compose-feature-name
376 feature-name-base domain i mn)))
377 (setq metadata (list* mn m metadata))))
379 (list* :target (car rest) metadata)
386 (list (nconc (nreverse dest) rest)
389 (t (list value nil)))
392 (defun chise-split-ccs-name (ccs)
393 (cond ((eq ccs '=ucs)
394 '(ucs abstract-character nil)
397 '(big5 abstract-character nil)
400 (setq ccs (symbol-name ccs))
402 (if (string-match "^\\(=[=+>]*\\)\\([^=>@*]+\\)@?" ccs)
403 (list (intern (match-string 2 ccs))
404 (chise-decode-ccs-prefix (match-string 1 ccs))
405 (if (string= (setq ret (substring ccs (match-end 0))) "")
410 (defun chise-decode-ccs-prefix (ccs)
411 (or (cdr (assoc ccs '(("==>" . super-abstract-character)
412 ("=>" . abstract-character)
413 ("=+>" . unified-glyph)
414 ("=" . abstract-glyph)
415 ("=>>" . detailed-glyph)
416 ("==" . abstract-glyph-form)
417 ("===" . glyph-image))))
420 (defun chise-turtle-uri-split-ccs (uri-ccs)
422 ((string-match "^a2\\." uri-ccs)
423 (cons ":super-abstract-character"
424 (substring uri-ccs (match-end 0)))
426 ((string-match "^a\\." uri-ccs)
427 (cons ":abstract-character"
428 (substring uri-ccs (match-end 0)))
430 ((string-match "^o\\." uri-ccs)
431 (cons ":unified-glyph"
432 (substring uri-ccs (match-end 0)))
434 ((string-match "^rep\\." uri-ccs)
435 (cons ":abstract-glyph"
436 (substring uri-ccs (match-end 0)))
438 ((string-match "^g\\." uri-ccs)
439 (cons ":detailed-glyph"
440 (substring uri-ccs (match-end 0)))
442 ((string-match "^g2\\." uri-ccs)
443 (cons ":abstract-glyph-form"
444 (substring uri-ccs (match-end 0)))
446 ((string-match "^gi\\." uri-ccs)
447 (cons ":abstract-glyph-form"
448 (substring uri-ccs (match-end 0)))
450 ((string-match "^repi\\." uri-ccs)
452 (substring uri-ccs (match-end 0)))
454 (t (cons ":character" uri-ccs))))
456 (defun char-db-turtle-insert-relation-feature (char name value line-breaking
458 (insert (format " %s%s "
459 (chise-turtle-uri-encode-feature-name name)
461 (char-db-turtle-insert-relations value readable)
465 (defun char-db-turtle-insert-metadata (name value)
467 (insert (format "%-7s " name))
469 ((or (eq name :sources)
471 (setq col (current-column))
472 (setq indent (make-string col ?\ ))
473 (insert (format "chisebib:%s"
474 (chise-turtle-uri-encode-ccs-name (car value))))
475 (dolist (source (cdr value))
476 (insert (format " ,\n%schisebib:%s" indent
477 (chise-turtle-uri-encode-ccs-name source))))
480 (insert (format "%S" value))
483 (defun char-db-turtle-insert-radical (radical-number)
484 (insert (format " %3d ; # %c"
486 (ideographic-radical radical-number)))
489 (defun char-db-turtle-insert-list (value &optional readable)
490 (let (lbs separator rest cell al cal key ret)
492 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
495 (setq cell (car value))
496 (if (and (consp cell)
498 (setq ret (condition-case nil
506 (setq key (car (car rest)))
507 (if (find-charset key)
508 (setq cal (cons key cal))
509 (setq al (cons key al)))
510 (setq rest (cdr rest)))
513 (char-db-turtle-insert-char-features ret
517 (setq separator lbs))
518 (setq ret (prin1-to-string cell))
520 (if (< (+ (current-column)
527 (setq separator " "))
528 (setq value (cdr value)))
532 (defun char-db-turtle-insert-source-list (value &optional readable)
533 (let (lbs separator rest cell al cal key ret)
534 (setq lbs (concat " ,\n" (make-string (current-column) ?\ ))
537 (setq cell (car value))
538 (if (and (consp cell)
540 (setq ret (condition-case nil
548 (setq key (car (car rest)))
549 (if (find-charset key)
550 (setq cal (cons key cal))
551 (setq al (cons key al)))
552 (setq rest (cdr rest)))
555 (char-db-turtle-insert-char-features ret
559 (setq separator lbs))
560 (setq ret (prin1-to-string cell))
562 (if (< (+ (current-column)
568 (if (string-match "=" ret)
569 (insert (format "%s:%s"
570 (substring ret 0 (match-beginning 0))
571 (substring ret (match-end 0))))
572 (insert (format "chisebib:%s" ret)))
573 (setq separator " , "))
574 (setq value (cdr value)))
578 (defun char-db-turtle-insert-relations (value &optional readable)
579 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
581 (if (characterp value)
582 (setq value (list value)))
584 (setq cell (car value))
586 (setq cell (decode-char '=ucs cell)))
589 (setq separator (format " ,%s" lbs)))
590 (if (characterp cell)
591 (insert (format "%-20s" (chise-turtle-encode-char cell)))
592 (char-db-turtle-insert-char-ref cell '<-formed))
593 (setq value (cdr value)))
596 (defun char-db-turtle-insert-target-value (value feature-name-base &optional readable)
597 (cond ((eq feature-name-base 'ideographic-radical)
598 (char-db-turtle-insert-radical value)
600 ((or (eq feature-name-base 'ideographic-combination)
601 (eq feature-name-base '=decomposition)
602 (eq feature-name-base '<-formed)
603 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name feature-name-base)))
604 (char-db-turtle-insert-relations value readable)
606 ((eq feature-name-base 'comment)
607 (insert (format "%S" value))
609 ((eq feature-name-base 'sources)
610 (char-db-turtle-insert-source-list value readable)
613 (char-db-turtle-insert-list value readable)
616 (insert (format " %-14s" value))
619 (defun char-db-turtle-insert-feature-value (value metadata domain feature-name-base)
620 (let (indent0 indent rest mdname mdval lb)
622 ((or metadata domain)
623 (setq indent0 (make-string (current-column) ?\ ))
625 (setq indent (make-string (current-column) ?\ ))
627 (insert (format ":context domain:%-7s ;"
628 (chise-turtle-uri-encode-ccs-name domain)))
632 (setq mdname (pop rest)
635 (insert (format "\n%s" indent))
637 (unless (char-db-turtle-insert-metadata mdname mdval)
640 (insert (format "\n%s" indent)))
642 (if (char-db-turtle-insert-target-value value feature-name-base)
643 (insert (format "\n%s] ;" indent0))
647 (char-db-turtle-insert-target-value value feature-name-base)
650 (defun char-db-turtle-insert-char-ref (char-ref feature-name-base)
651 (let (indent0 indent rest mdname mdval lb last-sep)
652 (setq indent0 (make-string (current-column) ?\ ))
654 (setq indent (make-string (current-column) ?\ ))
657 (setq mdname (pop rest)
660 (insert (format "%s\n%s"
667 (cond ((eq mdname :target)
669 (char-db-turtle-insert-target-value mdval feature-name-base)
672 (char-db-turtle-insert-metadata mdname mdval)))))
674 (insert (format "\n%s]" indent0))
678 (defun char-db-turtle-insert-char-features (char
679 &optional readable attributes column
682 (setq column (current-column)))
683 (let ((est-coded-charset-priority-list est-coded-charset-priority-list)
684 (est-view-url-prefix "http://chise.org/est/view")
685 id obj-id type domain
687 name-base name-domain
689 (line-breaking (concat "\n" (make-string column ?\ )))
693 dest-ccss ; sources required-features
695 uri-ccs uri-cpos ccs-base children child-ccs-list col indent)
699 (if (consp attributes)
701 (dolist (name attributes)
702 (unless (or (memq name char-db-ignored-attributes)
703 (string-match "\\*" (symbol-name name)))
704 (if (find-charset name)
708 (dolist (name (char-attribute-list))
709 (unless (or (memq name char-db-ignored-attributes)
710 (string-match "\\*" (symbol-name name)))
711 (if (find-charset name)
715 #'char-attribute-name<)))
716 (setq line-separator line-breaking)
717 (setq id (chise-turtle-encode-char char))
718 (setq obj-id (file-name-nondirectory id))
719 (string-match ":" obj-id)
720 (setq uri-ccs (substring obj-id 0 (match-beginning 0))
721 uri-cpos (substring obj-id (match-end 0)))
722 (insert (format "%s" obj-id))
723 (setq ret (assoc uri-ccs chise-turtle-ccs-prefix-alist))
724 (setq dest-ccss (list (cdr ret)))
725 (setq ret (chise-split-ccs-name (cdr ret)))
726 (setq ccs-base (car ret)
729 (insert (format "%s a chisegg:%s ;" line-separator type))
730 (insert (format "%s :%s-of" line-breaking type))
732 (insert (format " %s:%s ;"
733 (chise-turtle-uri-encode-ccs-name ccs-base) uri-cpos))
735 (setq col (current-column))
736 (insert (format ":context domain:%-7s ;\n%s:target %7s:%-7s ] ;"
737 (chise-turtle-uri-encode-ccs-name domain)
738 (make-string col ?\ )
739 (chise-turtle-uri-encode-ccs-name ccs-base) uri-cpos)))
740 (when (memq '<-subsumptive attributes)
741 (when (or readable (not for-sub-node))
742 (when (setq value (get-char-attribute char '<-subsumptive))
743 (insert line-separator)
744 (char-db-turtle-insert-relation-feature char '<-subsumptive value
748 (setq attributes (delq '<-subsumptive attributes))
750 (when (and (memq '<-denotational attributes)
751 (setq value (get-char-attribute char '<-denotational)))
752 (insert line-separator)
753 (char-db-turtle-insert-relation-feature char '<-denotational value
756 (setq attributes (delq '<-denotational attributes)))
757 (when (and (memq '<-denotational@component attributes)
759 (get-char-attribute char '<-denotational@component)))
760 (insert line-separator)
761 (char-db-turtle-insert-relation-feature
762 char '<-denotational@component value
765 (setq attributes (delq '<-denotational@component attributes)))
766 (when (and (memq 'name attributes)
767 (setq value (get-char-attribute char 'name)))
768 (insert (format "%s " line-separator))
770 (if (> (+ (current-column) (length value)) 48)
774 (setq attributes (delq 'name attributes))
776 (when (and (memq 'name* attributes)
777 (setq value (get-char-attribute char 'name*)))
778 (insert line-separator)
780 (if (> (+ (current-column) (length value)) 48)
784 (setq attributes (delq 'name* attributes))
786 (when (and (memq 'script attributes)
787 (setq value (get-char-attribute char 'script)))
788 (insert (format "%s :script\t\t ( %s ) ;"
790 (mapconcat (lambda (cell)
791 (format "script:%s" cell))
793 (setq attributes (delq 'script attributes))
795 ;; (dolist (name '(=>ucs =>ucs*))
796 ;; (when (and (memq name attributes)
797 ;; (setq value (get-char-attribute char name)))
798 ;; (insert line-separator)
799 ;; (insert (format " \"%-20s\": #x%04X,\t\"_comment\": \"%c\""
800 ;; name value (decode-char '=ucs value)))
801 ;; (setq attributes (delq name attributes))))
802 (when (and (memq '=>ucs attributes)
803 (setq value (get-char-attribute char '=>ucs)))
804 (insert (format "%s :to.ucs\t\t a.ucs:0x%04X ; # %c"
805 line-separator value (decode-char '=ucs value)))
806 (setq attributes (delq '=>ucs attributes))
808 (when (setq value (get-char-attribute char '=>ucs*))
809 (insert (format "%s :to.canonical-ucs\ta.ucs:0x%04X ; # %c"
810 line-separator value (decode-char '=ucs value)))
811 (setq attributes (delq '=>ucs* attributes))
813 (dolist (name '(=>ucs@gb =>ucs@big5))
814 (when (and (memq name attributes)
815 (setq value (get-char-attribute char name)))
816 (insert line-separator)
817 (insert (format " \"%-20s\": #x%04X,\t\"_comment\": \"%c\"%s"
822 (symbol-name name) 2)))
825 (setq attributes (delq name attributes))
827 (when (and (memq 'general-category attributes)
828 (setq value (get-char-attribute char 'general-category)))
829 (insert (format "%s :general-category \"%s\" ; # %s"
831 (cond ((rassoc value unidata-normative-category-alist)
832 "Normative Category")
833 ((rassoc value unidata-informative-category-alist)
834 "Informative Category")
836 "Unknown Category"))))
837 (setq attributes (delq 'general-category attributes))
839 (when (and (memq 'bidi-category attributes)
840 (setq value (get-char-attribute char 'bidi-category)))
841 (insert (format "%s :bidi-category %S ;"
844 (setq attributes (delq 'bidi-category attributes))
846 (unless (or (not (memq 'mirrored attributes))
847 (eq (setq value (get-char-attribute char 'mirrored 'empty))
849 (insert (format "%s :mirrored \"%s\" ;"
852 (setq attributes (delq 'mirrored attributes))
855 ((and (memq 'decimal-digit-value attributes)
856 (setq value (get-char-attribute char 'decimal-digit-value)))
857 (insert (format "%s :decimal-digit-value %2d ;"
858 line-separator value))
859 (setq attributes (delq 'decimal-digit-value attributes))
860 (when (and (memq 'digit-value attributes)
861 (setq value (get-char-attribute char 'digit-value)))
862 (insert (format "%s :digit-value\t %2d ;"
863 line-separator value))
864 (setq attributes (delq 'digit-value attributes))
866 (when (and (memq 'numeric-value attributes)
867 (setq value (get-char-attribute char 'numeric-value)))
868 (insert (format "%s :numeric-value\t %2d ;"
869 line-separator value))
870 (setq attributes (delq 'numeric-value attributes))
874 (when (and (memq 'digit-value attributes)
875 (setq value (get-char-attribute char 'digit-value)))
876 (insert line-separator)
877 (insert (format "%s :digit-value\t %2d ;"
878 line-separator value))
879 (setq attributes (delq 'digit-value attributes))
881 (when (and (memq 'numeric-value attributes)
882 (setq value (get-char-attribute char 'numeric-value)))
883 (insert line-separator)
884 (insert (format "%s :numeric-value\t %2d ;"
885 line-separator value))
886 (setq attributes (delq 'numeric-value attributes))
888 (when (and (memq 'iso-10646-comment attributes)
889 (setq value (get-char-attribute char 'iso-10646-comment)))
890 (insert line-separator)
891 (insert (format "{\"iso-10646-comment\":\t %S}%s"
894 (setq attributes (delq 'iso-10646-comment attributes))
896 (when (and (memq 'morohashi-daikanwa attributes)
897 (setq value (get-char-attribute char 'morohashi-daikanwa)))
898 (insert line-separator)
899 (insert (format "%s :morohashi-daikanwa\t %S ;"
900 line-separator value))
901 (setq attributes (delq 'morohashi-daikanwa attributes))
905 (when (and (memq 'ideographic-radical attributes)
906 (setq value (get-char-attribute char 'ideographic-radical)))
908 (insert (format "%s ideo:radical %3d ; # %c "
911 (ideographic-radical radical)
913 (setq attributes (delq 'ideographic-radical attributes))
915 (when (and (memq 'shuowen-radical attributes)
916 (setq value (get-char-attribute char 'shuowen-radical)))
917 (insert line-separator)
918 (insert (format " \"shuowen-radical\":\t %S,\t\"_comment\": \"%c\""
920 (shuowen-radical value)))
921 (setq attributes (delq 'shuowen-radical attributes))
926 char-db-feature-domains
928 (dolist (feature (char-attribute-list))
929 (setq feature (symbol-name feature))
931 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
933 (setq domain (intern (match-string 2 feature)))
934 (unless (memq domain dest)
935 (setq dest (cons domain dest)))))
936 (sort dest #'string<))))
937 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
938 (when (and (memq key attributes)
939 (setq value (get-char-attribute char key)))
941 (insert (format "%s ideo:radical "
943 (char-db-turtle-insert-feature-value value nil domain 'ideographic-radical)
944 (setq attributes (delq key attributes))
946 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
947 (when (and (memq key attributes)
948 (setq value (get-char-attribute char key)))
950 (insert (format "%s ideo:strokes [ "
952 (setq col (current-column))
953 (setq indent (make-string col ?\ ))
954 (insert (format ":context domain:%-7s ;\n%s:target %S"
955 (chise-turtle-uri-encode-ccs-name domain)
957 (setq attributes (delq key attributes))
958 (setq skey (intern (format "%s*sources" key)))
959 (when (and (memq skey attributes)
960 (setq value (get-char-attribute char skey)))
961 (insert (format " ;\n%s:sources (" indent))
962 (setq col (current-column))
963 (setq indent (make-string col ?\ ))
964 (insert (format " chisebib:%s" (car value)))
965 (dolist (cell (cdr value))
966 (insert (format "\n%s chisebib:%s" indent cell)))
968 (setq attributes (delq skey attributes))
971 (setq key (intern (format "%s@%s" 'total-strokes domain)))
972 (when (and (memq key attributes)
973 (setq value (get-char-attribute char key)))
974 (insert (format "%s ideo:total-strokes [ "
976 (setq col (current-column))
977 (insert (format ":context domain:%-7s ;\n%s:target %S"
978 (chise-turtle-uri-encode-ccs-name domain)
979 (make-string col ?\ )
981 (setq attributes (delq key attributes))
982 (setq skey (intern (format "%s*sources" key)))
985 (dolist (feature '(ideographic-radical
988 (setq key (intern (format "%s@%s*sources" feature domain)))
989 (when (and (memq key attributes)
990 (setq value (get-char-attribute char key)))
991 (insert line-separator)
992 (insert (format " \"%s\":%s" key line-breaking))
994 (insert (format " %s" cell)))
995 (setq attributes (delq key attributes))
998 (when (and (memq 'ideographic-strokes attributes)
999 (setq value (get-char-attribute char 'ideographic-strokes)))
1000 (setq strokes value)
1001 (insert (format "%s ideo:strokes %2d ;"
1002 line-separator strokes))
1003 (setq attributes (delq 'ideographic-strokes attributes))
1005 (when (and (memq 'kangxi-radical attributes)
1006 (setq value (get-char-attribute char 'kangxi-radical)))
1007 (unless (eq value radical)
1008 (insert line-separator)
1009 (insert (format "{\"kangxi-radical\":\t%S},\t\"_comment\": \"%c\"%s"
1011 (ideographic-radical value)
1014 (setq radical value)))
1015 (setq attributes (delq 'kangxi-radical attributes))
1017 (when (and (memq 'kangxi-strokes attributes)
1018 (setq value (get-char-attribute char 'kangxi-strokes)))
1019 (unless (eq value strokes)
1020 (insert line-separator)
1021 (insert (format "{\"kangxi-strokes\":\t%S}%s"
1025 (setq strokes value)))
1026 (setq attributes (delq 'kangxi-strokes attributes))
1028 (when (and (memq 'japanese-strokes attributes)
1029 (setq value (get-char-attribute char 'japanese-strokes)))
1030 (unless (eq value strokes)
1031 (insert line-separator)
1032 (insert (format "{\"japanese-strokes\":\t%S}%s"
1036 (setq strokes value)))
1037 (setq attributes (delq 'japanese-strokes attributes))
1039 (when (and (memq 'cns-radical attributes)
1040 (setq value (get-char-attribute char 'cns-radical)))
1041 (insert line-separator)
1042 (insert (format "{\"cns-radical\":\t%S},\t\"_comment\": \"%c\"%s"
1044 (ideographic-radical value)
1046 (setq attributes (delq 'cns-radical attributes))
1048 (when (and (memq 'cns-strokes attributes)
1049 (setq value (get-char-attribute char 'cns-strokes)))
1050 (unless (eq value strokes)
1051 (insert line-separator)
1052 (insert (format "{\"cns-strokes\":\t%S}%s"
1056 (setq strokes value)))
1057 (setq attributes (delq 'cns-strokes attributes))
1059 (when (and (memq 'total-strokes attributes)
1060 (setq value (get-char-attribute char 'total-strokes)))
1061 (insert (format "%s ideo:total-strokes %2d ;"
1062 line-separator value))
1063 (setq attributes (delq 'total-strokes attributes))
1065 (if (equal (get-char-attribute char '->titlecase)
1066 (get-char-attribute char '->uppercase))
1067 (setq attributes (delq '->titlecase attributes)))
1069 (dolist (ignored '(composition
1070 ->denotational <-subsumptive ->ucs-unified
1071 ->ideographic-component-forms))
1072 (setq attributes (delq ignored attributes))))
1074 (setq name (car attributes))
1075 (setq ret (chise-split-feature-name name))
1076 (setq name-base (car ret)
1077 name-domain (nth 1 ret))
1078 (when (setq value (chise-get-char-attribute-with-metadata
1079 char name-base name-domain))
1080 (setq metadata (nth 1 value)
1082 (cond ((setq ret (find-charset name))
1083 (setq name (charset-name ret))
1084 (when (not (memq name dest-ccss))
1085 (setq dest-ccss (cons name dest-ccss))
1087 (insert (format "%s :%-25s rdf:nil ;" line-separator
1088 (chise-turtle-uri-encode-ccs-name name)))
1089 (setq ret (chise-turtle-format-ccs-code-point name value))
1090 (insert (format "%s :eq %-25s ; # %c" line-separator
1092 (char-db-decode-isolated-char name value)))
1093 (setq eq-cpos-list (cons (list ret name value) eq-cpos-list))))
1095 (setq ret (if (eq name '=ucs)
1096 (if (< value #x10000)
1099 (intern (format "=%s" name)))))
1100 (setq child-ccs-list (cons ret child-ccs-list)))
1104 (not (eq name '->subsumptive))
1105 (not (eq name '->uppercase))
1106 (not (eq name '->lowercase))
1107 (not (eq name '->titlecase))
1108 (not (eq name '->canonical))
1109 (not (eq name '->Bopomofo))
1110 (not (eq name '->mistakable))
1111 (not (eq name '->ideographic-variants))
1112 (or (eq name '<-identical)
1113 (eq name '<-uppercase)
1114 (eq name '<-lowercase)
1115 (eq name '<-titlecase)
1116 (eq name '<-canonical)
1117 (eq name '<-ideographic-variants)
1118 ;; (eq name '<-synonyms)
1119 (string-match "^<-synonyms" (symbol-name name))
1120 (eq name '<-mistakable)
1121 (when (string-match "^->" (symbol-name name))
1123 ((string-match "^->fullwidth" (symbol-name name))
1124 (not (and (consp value)
1125 (characterp (car value))
1127 (car value) '=ucs 'defined-only)))
1132 ((eq name 'ideographic-structure)
1133 (insert (isd-turtle-format-char nil nil value (/ column 4)
1134 'isd 'without-head-char))
1137 ((eq name '->subsumptive)
1138 (insert line-separator)
1139 (char-db-turtle-insert-relation-feature char name value
1142 (setq children value)
1145 (insert (format "%s %-20s "
1147 (chise-turtle-uri-encode-feature-name name-base)))
1148 (unless (char-db-turtle-insert-feature-value
1149 value metadata name-domain name-base)
1153 (setq attributes (cdr attributes)))
1154 (insert (format "%s ." line-breaking))
1155 (dolist (eq-cpos (nreverse eq-cpos-list))
1156 (setq ret (chise-split-ccs-name (nth 1 eq-cpos)))
1157 (insert (format "%s %s" line-breaking
1159 (insert (format "%s %25s" line-breaking
1160 (format ":%s-of" (nth 1 ret))))
1161 (if (null (nth 2 ret))
1162 (insert (format " %14s:%-7s ."
1163 (chise-turtle-uri-encode-ccs-name (car ret))
1164 (nth 1 (split-string (car eq-cpos) ":"))))
1166 (setq col (current-column))
1167 (insert (format ":context domain:%-7s ;\n%s:target %7s:%-7s ] ."
1168 (chise-turtle-uri-encode-ccs-name (nth 2 ret))
1169 (make-string col ?\ )
1170 (chise-turtle-uri-encode-ccs-name (car ret))
1171 (nth 1 (split-string (car eq-cpos) ":"))))))
1172 (setq est-coded-charset-priority-list
1173 (append est-coded-charset-priority-list
1174 (nreverse child-ccs-list)))
1176 (dolist (child children)
1177 (insert (format "%s " line-breaking))
1178 (char-db-turtle-insert-char-features child nil nil nil 'for-sub-node)))
1181 (defun char-db-turtle-insert-char-data (char &optional readable attributes)
1183 (narrow-to-region (point)(point))
1184 (char-db-turtle-insert-char-features char readable attributes)
1188 (defun char-db-turtle-insert-prefix ()
1189 (let (base-ccs-list ret)
1190 (insert "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
1191 @prefix : <http://rdf.chise.org/rdf/property/character/main/> .
1192 @prefix ideo: <http://rdf.chise.org/rdf/property/character/ideo/> .
1193 @prefix isd: <http://rdf.chise.org/rdf/property/character/isd/> .
1194 @prefix idc: <http://rdf.chise.org/rdf/type/character/idc/> .
1195 @prefix chisegg: <http://rdf.chise.org/rdf/type/character/ggg/> .
1196 @prefix domain: <http://rdf.chise.org/data/domain/> .
1197 @prefix script: <http://rdf.chise.org/data/script/> .
1198 @prefix ideocomb: <http://rdf.chise.org/data/character/ideo/combination/> .
1199 @prefix chisebib: <http://rdf.chise.org/data/bibliography/> .
1200 @prefix ruimoku: <http://www.chise.org/est/view/article@ruimoku/rep.id=/> .
1201 @prefix zob1959: <http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/> .
1204 (dolist (cell (sort chise-turtle-ccs-prefix-alist
1206 (char-attribute-name< (cdr a)(cdr b)))))
1207 (insert (format "@prefix %s: <%s/%s=> .\n"
1209 "http://www.chise.org/est/view/character"
1210 (www-uri-encode-feature-name (cdr cell))))
1211 (setq ret (chise-split-ccs-name (cdr cell)))
1212 (unless (memq (car ret) base-ccs-list)
1213 (setq base-ccs-list (cons (car ret) base-ccs-list))))
1215 (dolist (base-ccs (nreverse base-ccs-list))
1216 (insert (format "@prefix %s: <%s/%s/code-point/> .\n"
1217 (chise-turtle-uri-encode-ccs-name base-ccs)
1218 "http://rdf.chise.org/data/ccs"
1219 (www-uri-encode-feature-name base-ccs))))))
1221 (defun char-db-turtle-insert-ideograph-radical-char-data (radical)
1223 (sort (copy-list (aref ideograph-radical-chars-vector radical))
1225 (ideograph-char< a b radical))))
1227 (dolist (name (char-attribute-list))
1228 (unless (memq name char-db-ignored-attributes)
1229 (push name attributes)
1231 (setq attributes (sort attributes #'char-attribute-name<))
1232 (aset ideograph-radical-chars-vector radical chars)
1233 (dolist (char chars)
1234 (when (not (some (lambda (atr)
1235 (get-char-attribute char atr))
1236 char-db-ignored-attributes))
1237 (char-db-turtle-insert-char-data char nil attributes)))
1240 (defun char-db-turtle-write-ideograph-radical-char-data (radical file)
1241 (if (file-directory-p file)
1242 (let ((name (char-feature (decode-char 'ucs (+ #x2EFF radical))
1244 (if (string-match "KANGXI RADICAL " name)
1245 (setq name (capitalize (substring name (match-end 0)))))
1246 (setq name (mapconcat (lambda (char)
1249 (char-to-string char))) name ""))
1252 (format "Ideograph-R%03d-%s.ttl" radical name)
1254 (let (chise-turtle-ccs-prefix-alist)
1256 (char-db-turtle-insert-ideograph-radical-char-data radical)
1257 (goto-char (point-min))
1258 (char-db-turtle-insert-prefix)
1260 (goto-char (point-min))
1261 (insert (format "# -*- coding: %s -*-\n"
1262 char-db-file-coding-system))
1263 (let ((coding-system-for-write char-db-file-coding-system))
1264 (write-region (point-min)(point-max) file)))))
1270 (provide 'char-db-turtle)
1272 ;;; char-db-turtle.el ends here