(est-coded-charset-priority-list): Add `=>>mj'.
[chise/chiset.git] / char-db-turtle.el
1 ;;; char-db-turtle.el --- Character Database utility -*- coding: utf-8-er; -*-
2
3 ;; Copyright (C) 2017, 2018 MORIOKA Tomohiko.
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, RDF, Turtle, ISO/IEC 10646, UCS, Unicode, MULE.
7
8 ;; This file is part of CHISET (CHISE/Turtle).
9
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.
14
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.
19
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.
24
25 ;;; Code:
26
27 (require 'char-db-util)
28 (require 'cwiki-common)
29 (require 'isd-turtle)
30 (require 'ideograph-util)
31
32 (setq est-coded-charset-priority-list
33   '(; =ucs
34     =mj
35     =adobe-japan1-0
36     =adobe-japan1-1
37     =adobe-japan1-2
38     =adobe-japan1-3
39     =adobe-japan1-4
40     =adobe-japan1-5
41     =adobe-japan1-6
42     =ucs@iso
43     =jis-x0208 =jis-x0208@1990
44     =jis-x0213-1
45     =jis-x0213-1@2000 =jis-x0213-1@2004
46     =jis-x0213-2
47     =jis-x0212
48     =gt
49     =hanyo-denshi/ks
50     =hanyo-denshi/tk
51     =ucs-itaiji-001
52     =ucs-itaiji-002
53     =ucs-itaiji-003
54     =ucs-itaiji-004
55     =ucs-itaiji-005
56     =ucs-itaiji-006
57     =ucs-itaiji-007
58     =ucs-itaiji-008
59     =ucs-itaiji-009
60     =ucs-itaiji-010
61     =ucs-itaiji-011
62     =ucs-itaiji-084
63     =ucs-var-001
64     =ucs-var-002
65     =ucs-var-003
66     =ucs-var-004
67     =ucs-var-005
68     =ucs-var-006
69     =ucs-var-008
70     =ucs-var-010
71     =cns11643-1 =cns11643-2 =cns11643-3
72     =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
73     =gb2312
74     =big5-cdp
75     =ks-x1001
76     =gt-k
77     =ucs@unicode
78     =ucs@JP/hanazono
79     =gb12345
80     =ucs@cns
81     =ucs@gb
82     =zinbun-oracle =>zinbun-oracle
83     =daikanwa
84     =ruimoku-v6
85     =cbeta =jef-china3
86     =daikanwa/+2p
87     =+>ucs@iso =+>ucs@unicode
88     =+>ucs@jis
89     =+>ucs@cns
90     =+>ucs@ks
91     =+>ucs@jis/1990
92     =>mj
93     =>jis-x0208 =>jis-x0213-1
94     =>jis-x0208@1997
95     =>ucs@iwds-1
96     =>ucs@cognate
97     =>ucs@component
98     =>iwds-1
99     =>ucs@iso
100     =>ucs@unicode
101     =>ucs@jis =>ucs@cns =>ucs@ks
102     =>gt
103     =>gt-k
104     =>>ucs@iso =>>ucs@unicode
105     =>>ucs@jis =>>ucs@cns =>>ucs@ks
106     =>>mj
107     =>>gt-k
108     =>>hanyo-denshi/ks
109     ==mj
110     ==ucs@iso
111     ==ucs@unicode
112     ==adobe-japan1-0
113     ==adobe-japan1-1
114     ==adobe-japan1-2
115     ==adobe-japan1-3
116     ==adobe-japan1-4
117     ==adobe-japan1-5
118     ==adobe-japan1-6
119     ==ks-x1001
120     ==hanyo-denshi/ks
121     ==hanyo-denshi/tk
122     ==ucs@jis
123     ==gt
124     ==cns11643-1 ==cns11643-2 ==cns11643-3
125     ==cns11643-4 ==cns11643-5 ==cns11643-6 ==cns11643-7
126     ==jis-x0212
127     ==ucs@cns
128     ==koseki
129     ==daikanwa
130     ==gt-k
131     ==ucs@gb
132     ==ucs-itaiji-001
133     ==ucs-itaiji-002
134     ==ucs-itaiji-003
135     ==ucs-itaiji-005
136     ==ucs-itaiji-006
137     ==ucs-var-002
138     ==ucs@JP/hanazono
139     ==daikanwa/+2p
140     =>>jis-x0208 =>>jis-x0213-1 =>>jis-x0213-2
141     =+>jis-x0208 =+>jis-x0213-1 =+>jis-x0213-2
142     =+>hanyo-denshi/jt
143     =+>jis-x0208@1978
144     =>>gt
145     =+>adobe-japan1
146     =>>adobe-japan1
147     =jis-x0208@1983 =jis-x0208@1978
148     =>ucs-itaiji-001
149     =>ucs-itaiji-002
150     =>ucs-itaiji-003
151     =>ucs-itaiji-004
152     =>ucs-itaiji-005
153     =>ucs-itaiji-006
154     =>ucs-itaiji-007
155     =>ucs-itaiji-001@iwds-1
156     ==>ucs@bucs
157     =big5
158     =>cbeta
159     ===mj
160     ===ucs@iso
161     ===ucs@unicode
162     ===hanyo-denshi/ks
163     ===ks-x1001
164     ===gt
165     ===gt-k
166     ===ucs@ks
167     ===ucs@gb
168     =shinjigen
169     =shinjigen@rev
170     =shinjigen@1ed
171     =shinjigen/+p@rev
172     ==shinjigen
173     ==shinjigen@rev
174     ==daikanwa/+p
175     ==shinjigen@1ed
176     ===daikanwa/+p
177     =>daikanwa/ho
178     ===daikanwa/ho
179     ))
180
181 (defvar chise-turtle-ccs-prefix-alist nil)
182
183 (defun charset-code-point-format-spec (ccs)
184   (cond ((memq ccs '(=ucs))
185          "0x%04X")
186         (t
187          (let ((ccs-name (symbol-name ccs)))
188            (cond
189             ((string-match
190               "\\(shinjigen\\|daikanwa/ho\\|=>iwds-1\\)"
191               ccs-name)
192              "%04d")
193             ((string-match
194               "\\(gt\\|daikanwa\\|adobe-japan1\\|cbeta\\|zinbun-oracle\\|hng\\)"
195               ccs-name)
196              "%05d")
197             ((string-match "\\(hanyo-denshi/ks\\|koseki\\|mj\\)" ccs-name)
198              "%06d")
199             ((string-match "hanyo-denshi/tk" ccs-name)
200              "%08d")
201             (t
202              "0x%X"))))))
203
204 (defun chise-turtle-uri-decode-feature-name (uri-feature)
205   (cond ((string= "a.ucs" uri-feature)
206          '=ucs)
207         ((string= "a.big5" uri-feature)
208          '=big5)
209         (t
210          (www-uri-decode-feature-name uri-feature))))
211
212 (defun chise-turtle-uri-encode-ccs-name (feature-name)
213   (cond
214    ((eq '=ucs feature-name)
215     "a.ucs")
216    ((eq '=big5 feature-name)
217     "a.big5")
218    ((eq '==>ucs@bucs feature-name)
219     "bucs")
220    (t
221     (mapconcat (lambda (c)
222                  (cond
223                   ((eq c ?@)
224                    "_")
225                   ((eq c ?+)
226                    "._.")
227                   ((eq c ?=)
228                    ".:.")
229                   (t
230                    (char-to-string c))))
231                (www-uri-encode-feature-name feature-name)
232                ""))))
233
234 (defun chise-turtle-uri-encode-feature-name (feature-name)
235   (cond
236    ((eq '->subsumptive feature-name)
237     ":subsume")
238    ((eq '<-denotational feature-name)
239     ":denotation-of")
240    ((eq '<-formed feature-name)
241     ":form-of")
242    ((eq '<-same feature-name)
243     "ideo:same-as")
244    ((eq '<-simplified feature-name)
245     "ideo:simplified-form-of")
246    ((eq '<-vulgar feature-name)
247     "ideo:vulgar-form-of")
248    ((eq '<-wrong feature-name)
249     "ideo:wrong-form-of")
250    ((eq '<-original feature-name)
251     "ideo:original-form-of")
252    ((eq '<-ancient feature-name)
253     "ideo:ancient-form-of")
254    ((eq '<-Small-Seal feature-name)
255     "ideo:Small-Seal-of")
256    ((eq '<-interchangeable feature-name)
257     "ideo:interchangeable-form-of")
258    ((eq '->interchangeable feature-name)
259     "ideo:interchangeable")
260    ((eq '->mistakable feature-name)
261     "ideo:mistakable")
262    ((eq 'hanyu-dazidian feature-name)
263     "ideo:hanyu-dazidian")
264    (t
265     (concat ":" (chise-turtle-uri-encode-ccs-name feature-name)))))
266
267 (defun chise-turtle-format-ccs-code-point (ccs code-point)
268   (let ((ccs-uri (chise-turtle-uri-encode-ccs-name ccs)))
269     (unless (assoc ccs-uri chise-turtle-ccs-prefix-alist)
270       (setq chise-turtle-ccs-prefix-alist
271             (cons (cons ccs-uri ccs)
272                   chise-turtle-ccs-prefix-alist)))
273     (format "%s:%s"
274             ccs-uri
275             (format (charset-code-point-format-spec ccs)
276                     code-point))))
277
278 (defun chise-turtle-encode-char (object)
279   (let ((ccs-list est-coded-charset-priority-list)
280         ccs ret ret2)
281     (if (setq ret (encode-char object '=ucs))
282         (chise-turtle-format-ccs-code-point '=ucs ret)
283       (while (and ccs-list
284                   (setq ccs (pop ccs-list))
285                   (not (setq ret (encode-char object ccs 'defined-only)))))
286       (cond (ret
287              (chise-turtle-format-ccs-code-point ccs ret)
288              )
289             ((and (setq ccs (car (split-char object)))
290                   (setq ret (encode-char object ccs)))
291              (chise-turtle-format-ccs-code-point ccs ret)
292              )
293             ((setq ret (get-char-attribute object 'ideographic-combination))
294              (format "ideocomb:%s"
295                      (mapconcat (lambda (cell)
296                                   (cond ((characterp cell)
297                                          (char-to-string cell)
298                                          )
299                                         ((setq ret2 (find-char cell))
300                                          (char-to-string ret2)
301                                          )
302                                         (t
303                                          (format "%S" cell)
304                                          )))
305                                 ret ""))
306              )
307             (t
308              (format (if est-hide-cgi-mode
309                          "system-char-id=0x%X"
310                        "system-char-id:0x%X")
311                      (encode-char object 'system-char-id))
312              )))))
313
314 (defun chise-split-feature-name (feature-name)
315   (let (base domain number meta)
316     (setq feature-name (symbol-name feature-name))
317     (if (string-match ".\\*." feature-name)
318         (setq meta (intern
319                     (format ":%s" (substring feature-name (1- (match-end 0)))))
320               feature-name (substring feature-name 0 (1+ (match-beginning 0)))))
321     (if (string-match "\\$_\\([0-9]+\\)$" feature-name)
322         (setq number (car (read-from-string (match-string 1 feature-name)))
323               feature-name (substring feature-name 0 (match-beginning 0))))
324     (if (string-match "@" feature-name)
325         (setq domain (car (read-from-string (substring feature-name (match-end 0))))
326               base (intern (substring feature-name 0 (match-beginning 0))))
327       (setq base (intern feature-name)))
328     (list base domain number meta)))
329
330 (defun chise-compose-feature-name (base domain number meta)
331   (let ((name (if domain
332                   (format "%s@%s" base domain)
333                 (symbol-name base))))
334     (if number
335         (setq name (format "%s$_%d" name number)))
336     (if meta
337         (setq name (format "%s*%s" name
338                            (substring (symbol-name meta) 1))))
339     (intern name)))
340
341 (defvar chise-feature-name-base-metadata-alist nil)
342
343 (defun chise-update-feature-name-base-metadata-alist ()
344   (interactive)
345   (let (base domain number metadata
346              bcell dcell ncell ret)
347     (setq chise-feature-name-base-metadata-alist nil)
348     (dolist (fname (sort (char-attribute-list)
349                          #'char-attribute-name<))
350       (setq ret (chise-split-feature-name fname)
351             base (car ret)
352             domain (nth 1 ret)
353             number (nth 2 ret)
354             metadata (nth 3 ret))
355       (when metadata
356         (if (setq bcell (assq base chise-feature-name-base-metadata-alist))
357             (if (setq dcell (assq domain (cdr bcell)))
358                 (if (setq ncell (assq number (cdr dcell)))
359                     (unless (memq metadata (cdr ncell))
360                       (setcdr ncell (nconc (cdr ncell)
361                                            (list metadata))))
362                   (setcdr dcell (cons (list number metadata)
363                                       (cdr dcell))))
364               (setcdr bcell (cons (list domain (list number metadata))
365                                   (cdr bcell))))
366           (setq chise-feature-name-base-metadata-alist
367                 (cons (list base (list domain (list number metadata)))
368                       chise-feature-name-base-metadata-alist))
369           )))))
370
371 (chise-update-feature-name-base-metadata-alist)
372
373 (defun chise-get-char-attribute-with-metadata (character feature-name-base domain)
374   (let ((value (get-char-attribute
375                 character
376                 (chise-compose-feature-name feature-name-base domain nil nil)
377                 '*feature-value-is-empty*))
378         dcell
379         base-metadata metadata
380         ret m i rest dest)
381     (unless (eq value '*feature-value-is-empty*)
382       (cond
383        ((and (setq ret (assq feature-name-base
384                              chise-feature-name-base-metadata-alist))
385              (setq dcell (assq domain (cdr ret))))
386         (if (setq ret (assq nil (cdr dcell)))
387             (dolist (bmn (cdr ret))
388               (when (setq m (get-char-attribute
389                              character
390                              (chise-compose-feature-name
391                               feature-name-base domain nil bmn)))
392                 (setq base-metadata
393                       (list* bmn m base-metadata)))))
394         (setq i 1
395               rest value)
396         (while (consp rest)
397           (setq dest
398                 (cons (cond
399                        ((setq ret (assq i (cdr dcell)))
400                         (setq metadata nil)
401                         (dolist (mn (cdr ret))
402                           (when (setq m (get-char-attribute
403                                          character
404                                          (chise-compose-feature-name
405                                           feature-name-base domain i mn)))
406                             (setq metadata (list* mn m metadata))))
407                         (if metadata
408                             (list* :target (car rest) metadata)
409                           (car rest))
410                         )
411                        (t (car rest)))
412                       dest))
413           (setq i (1+ i)
414                 rest (cdr rest)))
415         (list (nconc (nreverse dest) rest)
416               base-metadata)
417         )
418        (t (list value nil)))
419       )))
420           
421 (defun chise-split-ccs-name (ccs)
422   (cond ((eq ccs '=ucs)
423          '(ucs abstract-character nil)
424          )
425         ((eq ccs '=big5)
426          '(big5 abstract-character nil)
427          )
428         (t
429          (setq ccs (symbol-name ccs))
430          (let (ret)
431            (if (string-match "^\\(=[=+>]*\\)\\([^=>@*]+\\)@?" ccs)
432                (list (intern (match-string 2 ccs))
433                      (chise-decode-ccs-prefix (match-string 1 ccs))
434                      (if (string= (setq ret (substring ccs (match-end 0))) "")
435                          nil
436                        (intern ret))))
437            ))))
438
439 (defun chise-decode-ccs-prefix (ccs)
440   (or (cdr (assoc ccs '(("==>" . super-abstract-character)
441                         ("=>"  . abstract-character)
442                         ("=+>" . unified-glyph)
443                         ("="   . abstract-glyph)
444                         ("=>>" . detailed-glyph)
445                         ("=="  . abstract-glyph-form)
446                         ("===" . glyph-image))))
447       'character))
448
449 (defun chise-turtle-uri-split-ccs (uri-ccs)
450   (cond
451    ((string-match "^a2\\." uri-ccs)
452     (cons ":super-abstract-character"
453           (substring uri-ccs (match-end 0)))
454     )
455    ((string-match "^a\\." uri-ccs)
456     (cons ":abstract-character"
457           (substring uri-ccs (match-end 0)))
458     )
459    ((string-match "^o\\." uri-ccs)
460     (cons ":unified-glyph"
461           (substring uri-ccs (match-end 0)))
462     )
463    ((string-match "^rep\\." uri-ccs)
464     (cons ":abstract-glyph"
465           (substring uri-ccs (match-end 0)))
466     )
467    ((string-match "^g\\." uri-ccs)
468     (cons ":detailed-glyph"
469           (substring uri-ccs (match-end 0)))
470     )
471    ((string-match "^g2\\." uri-ccs)
472     (cons ":abstract-glyph-form"
473           (substring uri-ccs (match-end 0)))
474     )
475    ((string-match "^gi\\." uri-ccs)
476     (cons ":abstract-glyph-form"
477           (substring uri-ccs (match-end 0)))
478     )
479    ((string-match "^repi\\." uri-ccs)
480     (cons ":glyph-image"
481           (substring uri-ccs (match-end 0)))
482     )
483    (t (cons ":character" uri-ccs))))
484
485 (defun char-db-turtle-insert-relation-feature (char name value line-breaking
486                                                     ccss readable)
487   (insert (format "    %s%s        "
488                   (chise-turtle-uri-encode-feature-name name)
489                   line-breaking))
490   (char-db-turtle-insert-relations value readable)
491   (insert " ;")
492   )
493
494 (defun char-db-turtle-insert-metadata (name value)
495   (let (col indent)
496     (insert (format "%-7s " name))
497     (cond
498      ((or (eq name :sources)
499           (eq name :denied))
500       (setq col (current-column))
501       (setq indent (make-string col ?\ ))
502       (insert (format "chisebib:%s"
503                       (chise-turtle-uri-encode-ccs-name (car value))))
504       (dolist (source (cdr value))
505         (insert (format " ,\n%schisebib:%s" indent
506                         (chise-turtle-uri-encode-ccs-name source))))
507       nil)
508      (t
509       (insert (format "%S" value))
510       nil))))
511
512 (defun char-db-turtle-insert-radical (radical-number)
513   (insert (format "        %3d ; # %c"
514                   radical-number
515                   (ideographic-radical radical-number)))
516   'with-separator)
517
518 (defun char-db-turtle-insert-list (value &optional readable)
519   (let (lbs separator rest cell al cal key ret)
520     (insert "( ")
521     (setq lbs (concat "\n" (make-string (current-column) ?\ ))
522           separator nil)
523     (while (consp value)
524       (setq cell (car value))
525       (if (and (consp cell)
526                (consp (car cell))
527                (setq ret (condition-case nil
528                              (find-char cell)
529                            (error nil))))
530           (progn
531             (setq rest cell
532                   al nil
533                   cal nil)
534             (while rest
535               (setq key (car (car rest)))
536               (if (find-charset key)
537                   (setq cal (cons key cal))
538                 (setq al (cons key al)))
539               (setq rest (cdr rest)))
540             (if separator
541                 (insert lbs))
542             (char-db-turtle-insert-char-features ret
543                                                  readable
544                                                  al
545                                                  nil 'for-sub-node)
546             (setq separator lbs))
547         (setq ret (prin1-to-string cell))
548         (if separator
549             (if (< (+ (current-column)
550                       (length ret)
551                       (length separator))
552                    76)
553                 (insert separator)
554               (insert lbs)))
555         (insert ret)
556         (setq separator " "))
557       (setq value (cdr value)))
558     (insert " ) ;")
559     'with-separator))
560
561 (defun char-db-turtle-insert-source-list (value &optional readable)
562   (let (lbs separator rest cell al cal key ret)
563     (setq lbs (concat " ,\n" (make-string (current-column) ?\ ))
564           separator nil)
565     (while (consp value)
566       (setq cell (car value))
567       (if (and (consp cell)
568                (consp (car cell))
569                (setq ret (condition-case nil
570                              (find-char cell)
571                            (error nil))))
572           (progn
573             (setq rest cell
574                   al nil
575                   cal nil)
576             (while rest
577               (setq key (car (car rest)))
578               (if (find-charset key)
579                   (setq cal (cons key cal))
580                 (setq al (cons key al)))
581               (setq rest (cdr rest)))
582             (if separator
583                 (insert lbs))
584             (char-db-turtle-insert-char-features ret
585                                                  readable
586                                                  al
587                                                  nil 'for-sub-node)
588             (setq separator lbs))
589         (setq ret (prin1-to-string cell))
590         (if separator
591             (if (< (+ (current-column)
592                       (length ret)
593                       (length separator))
594                    76)
595                 (insert separator)
596               (insert lbs)))
597         (if (string-match "=" ret)
598             (insert (format "%s:%s"
599                             (substring ret 0 (match-beginning 0))
600                             (substring ret (match-end 0))))
601           (insert (format "chisebib:%s" ret)))
602         (setq separator " , "))
603       (setq value (cdr value)))
604     (insert " ;")
605     'with-separator))
606
607 (defun char-db-turtle-insert-relations (value &optional readable)
608   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
609         separator cell)
610     (if (characterp value)
611         (setq value (list value)))
612     (while (consp value)
613       (setq cell (car value))
614       (if (integerp cell)
615           (setq cell (decode-char '=ucs cell)))
616       (if separator
617           (insert separator)
618         (setq separator (format " ,%s" lbs)))
619       (if (characterp cell)
620           (insert (format "%-20s" (chise-turtle-encode-char cell)))
621         (char-db-turtle-insert-char-ref cell '<-formed))
622       (setq value (cdr value)))
623     nil))
624
625 (defun char-db-turtle-insert-target-value (value feature-name-base &optional readable)
626   (cond ((eq feature-name-base 'ideographic-radical)
627          (char-db-turtle-insert-radical value)
628          )
629         ((or (eq feature-name-base 'ideographic-combination)
630              (eq feature-name-base '=decomposition)
631              (eq feature-name-base '<-formed)
632              (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name feature-name-base)))
633          (char-db-turtle-insert-relations value readable)
634          )
635         ((eq feature-name-base 'comment)
636          (insert (format "%S" value))
637          nil)
638         ((eq feature-name-base 'sources)
639          (char-db-turtle-insert-source-list value readable)
640          )
641         ((consp value)
642          (char-db-turtle-insert-list value readable)
643          )
644         (t
645          (insert (format " %-14s" value))
646          nil)))
647
648 (defun char-db-turtle-insert-feature-value (value metadata domain feature-name-base)
649   (let (indent0 indent rest mdname mdval lb)
650     (cond
651      ((or metadata domain)
652       (setq indent0 (make-string (current-column) ?\ ))
653       (insert "[ ")
654       (setq indent (make-string (current-column) ?\ ))
655       (when domain
656         (insert (format ":context domain:%-7s ;"
657                         (chise-turtle-uri-encode-ccs-name domain)))
658         (setq lb t))
659       (setq rest metadata)
660       (while rest
661         (setq mdname (pop rest)
662               mdval  (pop rest))
663         (if lb
664             (insert (format "\n%s" indent))
665           (setq lb t))
666         (unless (char-db-turtle-insert-metadata mdname mdval)
667           (insert " ;")))
668       (if lb
669           (insert (format "\n%s" indent)))
670       (insert ":target  ")
671       (if (char-db-turtle-insert-target-value value feature-name-base)
672           (insert (format "\n%s] ;" indent0))
673         (insert " ] ;"))
674       'with-separator)
675      (t
676       (char-db-turtle-insert-target-value value feature-name-base)
677       ))))
678
679 (defun char-db-turtle-insert-char-ref (char-ref feature-name-base)
680   (let (indent0 indent rest mdname mdval lb last-sep)
681     (setq indent0 (make-string (current-column) ?\ ))
682     (insert "[ ")
683     (setq indent (make-string (current-column) ?\ ))
684     (setq rest char-ref)
685     (while rest
686       (setq mdname (pop rest)
687             mdval  (pop rest))
688       (if lb
689           (insert (format "%s\n%s"
690                           (if last-sep
691                               ""
692                             " ;")
693                           indent))
694         (setq lb t))
695       (setq last-sep
696             (cond ((eq mdname :target)
697                    (insert ":target  ")
698                    (char-db-turtle-insert-target-value mdval feature-name-base)
699                      )
700                   (t
701                    (char-db-turtle-insert-metadata mdname mdval)))))
702     (if last-sep
703         (insert (format "\n%s]" indent0))
704       (insert " ]"))
705     nil))
706   
707 (defun char-db-turtle-insert-char-features (char
708                                             &optional readable attributes column
709                                             for-sub-node)
710   (unless column
711     (setq column (current-column)))
712   (let ((est-coded-charset-priority-list est-coded-charset-priority-list)
713         (est-view-url-prefix "http://chise.org/est/view")
714         id obj-id type domain
715         name value metadata
716         name-base name-domain
717         radical strokes
718         (line-breaking (concat "\n" (make-string column ?\ )))
719         line-separator
720         ret
721         skey
722         dest-ccss ; sources required-features
723         ccss eq-cpos-list
724         uri-ccs uri-cpos ccs-base children child-ccs-list col indent)
725     (let (atr-d)
726       (setq attributes
727             (sort (if attributes
728                       (if (consp attributes)
729                           (progn
730                             (dolist (name attributes)
731                               (unless (or (memq name char-db-ignored-attributes)
732                                           (string-match "\\*" (symbol-name name)))
733                                 (if (find-charset name)
734                                     (push name ccss))
735                                 (push name atr-d)))
736                             atr-d))
737                     (dolist (name (char-attribute-list))
738                       (unless (or (memq name char-db-ignored-attributes)
739                                   (string-match "\\*" (symbol-name name)))
740                         (if (find-charset name)
741                             (push name ccss))
742                         (push name atr-d)))
743                     atr-d)
744                   #'char-attribute-name<)))
745     (setq line-separator line-breaking)
746     (setq id (chise-turtle-encode-char char))
747     (setq obj-id (file-name-nondirectory id))
748     (string-match ":" obj-id)
749     (setq uri-ccs (substring obj-id 0 (match-beginning 0))
750           uri-cpos (substring obj-id (match-end 0)))
751     (insert (format "%s" obj-id))
752     (setq ret (assoc uri-ccs chise-turtle-ccs-prefix-alist))
753     (setq dest-ccss (list (cdr ret)))
754     (setq ret (chise-split-ccs-name (cdr ret)))
755     (setq ccs-base (car ret)
756           type (nth 1 ret)
757           domain (nth 2 ret))
758     (insert (format "%s    a chisegg:%s ;" line-separator type))
759     (insert (format "%s    :%s-of" line-breaking type))
760     (if (null domain)
761         (insert (format " %s:%s ;"
762                         (chise-turtle-uri-encode-ccs-name ccs-base) uri-cpos))
763       (insert " [ ")
764       (setq col (current-column))
765       (insert (format ":context domain:%-7s ;\n%s:target %7s:%-7s ] ;"
766                       (chise-turtle-uri-encode-ccs-name domain)
767                       (make-string col ?\ )
768                       (chise-turtle-uri-encode-ccs-name ccs-base) uri-cpos)))
769     (when (memq '<-subsumptive attributes)
770       (when (or readable (not for-sub-node))
771         (when (setq value (get-char-attribute char '<-subsumptive))
772           (insert line-separator)
773           (char-db-turtle-insert-relation-feature char '<-subsumptive value
774                                                   line-breaking
775                                                   ccss readable)
776           ))
777       (setq attributes (delq '<-subsumptive attributes))
778       )
779     (when (and (memq '<-denotational attributes)
780                (setq value (get-char-attribute char '<-denotational)))
781       (insert line-separator)
782       (char-db-turtle-insert-relation-feature char '<-denotational value
783                                             line-breaking
784                                             ccss readable)
785       (setq attributes (delq '<-denotational attributes)))
786     (when (and (memq '<-denotational@component attributes)
787                (setq value
788                      (get-char-attribute char '<-denotational@component)))
789       (insert line-separator)
790       (char-db-turtle-insert-relation-feature
791        char '<-denotational@component value
792        line-breaking
793        ccss readable)
794       (setq attributes (delq '<-denotational@component attributes)))
795     (when (and (memq 'name attributes)
796                (setq value (get-char-attribute char 'name)))
797       (insert (format "%s    " line-separator))
798       (insert (format
799                (if (> (+ (current-column) (length value)) 48)
800                    ":name %S ;"
801                  ":name                 %S ;")
802                value))
803       (setq attributes (delq 'name attributes))
804       )
805     (when (and (memq 'name* attributes)
806                (setq value (get-char-attribute char 'name*)))
807       (insert line-separator)
808       (insert (format
809                (if (> (+ (current-column) (length value)) 48)
810                    " \"name*\": %S"
811                  " \"name*\":                 %S")
812                value))
813       (setq attributes (delq 'name* attributes))
814       )
815     (when (and (memq 'script attributes)
816                (setq value (get-char-attribute char 'script)))
817       (insert (format "%s    :script\t\t  ( %s ) ;"
818                       line-separator
819                       (mapconcat (lambda (cell)
820                                    (format "script:%s" cell))
821                                  value " ")))
822       (setq attributes (delq 'script attributes))
823       )
824     ;; (dolist (name '(=>ucs =>ucs*))
825     ;;   (when (and (memq name attributes)
826     ;;              (setq value (get-char-attribute char name)))
827     ;;     (insert line-separator)
828     ;;     (insert (format " \"%-20s\":  #x%04X,\t\"_comment\": \"%c\""
829     ;;                     name value (decode-char '=ucs value)))
830     ;;     (setq attributes (delq name attributes))))
831     (when (and (memq '=>ucs attributes)
832                (setq value (get-char-attribute char '=>ucs)))
833       (insert (format "%s    :to.ucs\t\t  a.ucs:0x%04X ; # %c"
834                       line-separator value (decode-char '=ucs value)))
835       (setq attributes (delq '=>ucs attributes))
836       )
837     (when (setq value (get-char-attribute char '=>ucs*))
838       (insert (format "%s    :to.canonical-ucs\ta.ucs:0x%04X ; # %c"
839                       line-separator value (decode-char '=ucs value)))
840       (setq attributes (delq '=>ucs* attributes))
841       )
842     (dolist (name '(=>ucs@gb =>ucs@big5))
843       (when (and (memq name attributes)
844                  (setq value (get-char-attribute char name)))
845         (insert line-separator)
846         (insert (format " \"%-20s\":  #x%04X,\t\"_comment\": \"%c\"%s"
847                         name value
848                         (decode-char (intern
849                                       (concat "="
850                                               (substring
851                                                (symbol-name name) 2)))
852                                      value)
853                         line-breaking))
854         (setq attributes (delq name attributes))
855         ))
856     (when (and (memq 'general-category attributes)
857                (setq value (get-char-attribute char 'general-category)))
858       (insert (format "%s    :general-category     \"%s\" ; # %s"
859                       line-separator value
860                       (cond ((rassoc value unidata-normative-category-alist)
861                              "Normative Category")
862                             ((rassoc value unidata-informative-category-alist)
863                              "Informative Category")
864                             (t
865                              "Unknown Category"))))
866       (setq attributes (delq 'general-category attributes))
867       )
868     (when (and (memq 'bidi-category attributes)
869                (setq value (get-char-attribute char 'bidi-category)))
870       (insert (format "%s    :bidi-category        %S ;"
871                       line-separator
872                       value))
873       (setq attributes (delq 'bidi-category attributes))
874       )
875     (unless (or (not (memq 'mirrored attributes))
876                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
877                     'empty))
878       (insert (format "%s    :mirrored             \"%s\" ;"
879                       line-separator
880                       value))
881       (setq attributes (delq 'mirrored attributes))
882       )
883     (cond
884      ((and (memq 'decimal-digit-value attributes)
885            (setq value (get-char-attribute char 'decimal-digit-value)))
886       (insert (format "%s    :decimal-digit-value  %2d ;"
887                       line-separator value))
888       (setq attributes (delq 'decimal-digit-value attributes))
889       (when (and (memq 'digit-value attributes)
890                  (setq value (get-char-attribute char 'digit-value)))
891         (insert (format "%s    :digit-value\t  %2d ;"
892                         line-separator value))
893         (setq attributes (delq 'digit-value attributes))
894         )
895       (when (and (memq 'numeric-value attributes)
896                  (setq value (get-char-attribute char 'numeric-value)))
897         (insert (format "%s    :numeric-value\t  %2d ;"
898                         line-separator value))
899         (setq attributes (delq 'numeric-value attributes))
900         )
901       )
902      (t
903       (when (and (memq 'digit-value attributes)
904                  (setq value (get-char-attribute char 'digit-value)))
905         (insert line-separator)
906         (insert (format "%s    :digit-value\t  %2d ;"
907                         line-separator value))
908         (setq attributes (delq 'digit-value attributes))
909         )
910       (when (and (memq 'numeric-value attributes)
911                  (setq value (get-char-attribute char 'numeric-value)))
912         (insert line-separator)
913         (insert (format "%s    :numeric-value\t  %2d ;"
914                         line-separator value))
915         (setq attributes (delq 'numeric-value attributes))
916         )))
917     (when (and (memq 'iso-10646-comment attributes)
918                (setq value (get-char-attribute char 'iso-10646-comment)))
919       (insert line-separator)
920       (insert (format "{\"iso-10646-comment\":\t %S}%s"
921                       value
922                       line-breaking))
923       (setq attributes (delq 'iso-10646-comment attributes))
924       )
925     (when (and (memq 'morohashi-daikanwa attributes)
926                (setq value (get-char-attribute char 'morohashi-daikanwa)))
927       (insert line-separator)
928       (insert (format "%s    :morohashi-daikanwa\t  %S ;"
929                       line-separator value))
930       (setq attributes (delq 'morohashi-daikanwa attributes))
931       )
932     (setq radical nil
933           strokes nil)
934     (when (and (memq 'ideographic-radical attributes)
935                (setq value (get-char-attribute char 'ideographic-radical)))
936       (setq radical value)
937       (insert (format "%s    ideo:radical         %3d ; # %c "
938                       line-separator
939                       radical
940                       (ideographic-radical radical)
941                       ))
942       (setq attributes (delq 'ideographic-radical attributes))
943       )
944     (when (and (memq 'shuowen-radical attributes)
945                (setq value (get-char-attribute char 'shuowen-radical)))
946       (insert line-separator)
947       (insert (format " \"shuowen-radical\":\t %S,\t\"_comment\": \"%c\""
948                       value
949                       (shuowen-radical value)))
950       (setq attributes (delq 'shuowen-radical attributes))
951       )
952     (let (key)
953       (dolist (domain
954                (append
955                 char-db-feature-domains
956                 (let (dest domain)
957                   (dolist (feature (char-attribute-list))
958                     (setq feature (symbol-name feature))
959                     (when (string-match
960                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
961                            feature)
962                       (setq domain (intern (match-string 2 feature)))
963                      (unless (memq domain dest)
964                        (setq dest (cons domain dest)))))
965                   (sort dest #'string<))))
966         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
967         (when (and (memq key attributes)
968                    (setq value (get-char-attribute char key)))
969           (setq radical value)
970           (insert (format "%s    ideo:radical           "
971                           line-separator))
972           (char-db-turtle-insert-feature-value value nil domain 'ideographic-radical)
973           (setq attributes (delq key attributes))
974           )
975         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
976         (when (and (memq key attributes)
977                    (setq value (get-char-attribute char key)))
978           (setq strokes value)
979           (insert (format "%s    ideo:strokes           [ "
980                           line-separator))
981           (setq col (current-column))
982           (setq indent (make-string col ?\ ))
983           (insert (format ":context domain:%-7s ;\n%s:target  %S"
984                           (chise-turtle-uri-encode-ccs-name domain)
985                           indent strokes))
986           (setq attributes (delq key attributes))
987           (setq skey (intern (format "%s*sources" key)))
988           (when (and (memq skey attributes)
989                      (setq value (get-char-attribute char skey)))
990             (insert (format " ;\n%s:sources (" indent))
991             (setq col (current-column))
992             (setq indent (make-string col ?\ ))
993             (insert (format " chisebib:%s" (car value)))
994             (dolist (cell (cdr value))
995               (insert (format "\n%s chisebib:%s" indent cell)))
996             (insert " )"))
997           (setq attributes (delq skey attributes))
998           (insert " ] ;")
999           )
1000         (setq key (intern (format "%s@%s" 'total-strokes domain)))
1001         (when (and (memq key attributes)
1002                    (setq value (get-char-attribute char key)))
1003           (insert (format "%s    ideo:total-strokes     [ "
1004                           line-separator))
1005           (setq col (current-column))
1006           (insert (format ":context domain:%-7s ;\n%s:target  %S"
1007                           (chise-turtle-uri-encode-ccs-name domain)
1008                           (make-string col ?\ )
1009                           value))
1010           (setq attributes (delq key attributes))
1011           (setq skey (intern (format "%s*sources" key)))
1012           (insert " ] ;")
1013           )
1014         (dolist (feature '(ideographic-radical
1015                            ideographic-strokes
1016                            total-strokes))
1017           (setq key (intern (format "%s@%s*sources" feature domain)))
1018           (when (and (memq key attributes)
1019                      (setq value (get-char-attribute char key)))
1020             (insert line-separator)
1021             (insert (format " \"%s\":%s" key line-breaking))
1022             (dolist (cell value)
1023               (insert (format " %s" cell)))
1024             (setq attributes (delq key attributes))
1025             ))
1026         ))
1027     (when (and (memq 'ideographic-strokes attributes)
1028                (setq value (get-char-attribute char 'ideographic-strokes)))
1029       (setq strokes value)
1030       (insert (format "%s    ideo:strokes          %2d ;"
1031                       line-separator strokes))
1032       (setq attributes (delq 'ideographic-strokes attributes))
1033       )
1034     (when (and (memq 'kangxi-radical attributes)
1035                (setq value (get-char-attribute char 'kangxi-radical)))
1036       (unless (eq value radical)
1037         (insert line-separator)
1038         (insert (format "{\"kangxi-radical\":\t%S},\t\"_comment\": \"%c\"%s"
1039                         value
1040                         (ideographic-radical value)
1041                         line-breaking))
1042         (or radical
1043             (setq radical value)))
1044       (setq attributes (delq 'kangxi-radical attributes))
1045       )
1046     (when (and (memq 'kangxi-strokes attributes)
1047                (setq value (get-char-attribute char 'kangxi-strokes)))
1048       (unless (eq value strokes)
1049         (insert line-separator)
1050         (insert (format "{\"kangxi-strokes\":\t%S}%s"
1051                         value
1052                         line-breaking))
1053         (or strokes
1054             (setq strokes value)))
1055       (setq attributes (delq 'kangxi-strokes attributes))
1056       )
1057     (when (and (memq 'japanese-strokes attributes)
1058                (setq value (get-char-attribute char 'japanese-strokes)))
1059       (unless (eq value strokes)
1060         (insert line-separator)
1061         (insert (format "{\"japanese-strokes\":\t%S}%s"
1062                         value
1063                         line-breaking))
1064         (or strokes
1065             (setq strokes value)))
1066       (setq attributes (delq 'japanese-strokes attributes))
1067       )
1068     (when (and (memq 'cns-radical attributes)
1069                (setq value (get-char-attribute char 'cns-radical)))
1070       (insert line-separator)
1071       (insert (format "{\"cns-radical\":\t%S},\t\"_comment\": \"%c\"%s"
1072                       value
1073                       (ideographic-radical value)
1074                       line-breaking))
1075       (setq attributes (delq 'cns-radical attributes))
1076       )
1077     (when (and (memq 'cns-strokes attributes)
1078                (setq value (get-char-attribute char 'cns-strokes)))
1079       (unless (eq value strokes)
1080         (insert line-separator)
1081         (insert (format "{\"cns-strokes\":\t%S}%s"
1082                         value
1083                         line-breaking))
1084         (or strokes
1085             (setq strokes value)))
1086       (setq attributes (delq 'cns-strokes attributes))
1087       )
1088     (when (and (memq 'total-strokes attributes)
1089                (setq value (get-char-attribute char 'total-strokes)))
1090       (insert (format "%s    ideo:total-strokes    %2d ;"
1091                       line-separator value))
1092       (setq attributes (delq 'total-strokes attributes))
1093       )
1094     (if (equal (get-char-attribute char '->titlecase)
1095                (get-char-attribute char '->uppercase))
1096         (setq attributes (delq '->titlecase attributes)))
1097     (unless readable
1098       (dolist (ignored '(composition
1099                          ->denotational <-subsumptive ->ucs-unified
1100                          ->ideographic-component-forms))
1101         (setq attributes (delq ignored attributes))))
1102     (while attributes
1103       (setq name (car attributes))
1104       (setq ret (chise-split-feature-name name))
1105       (setq name-base (car ret)
1106             name-domain (nth 1 ret))
1107       (when (setq value (chise-get-char-attribute-with-metadata
1108                          char name-base name-domain))
1109         (setq metadata (nth 1 value)
1110               value (car value))
1111         (cond ((setq ret (find-charset name))
1112                (setq name (charset-name ret))
1113                (when (not (memq name dest-ccss))
1114                  (setq dest-ccss (cons name dest-ccss))
1115                  (if (null value)
1116                      (insert (format "%s    :%-25s rdf:nil ;" line-separator
1117                                      (chise-turtle-uri-encode-ccs-name name)))
1118                    (setq ret (chise-turtle-format-ccs-code-point name value))
1119                    (insert (format "%s    :eq %-25s ; # %c" line-separator
1120                                    ret
1121                                    (char-db-decode-isolated-char name value)))
1122                    (setq eq-cpos-list (cons (list ret name value) eq-cpos-list))))
1123                (if (find-charset
1124                     (setq ret (if (eq name '=ucs)
1125                                   (if (< value #x10000)
1126                                       '==ucs@unicode
1127                                     '==ucs@iso)
1128                                 (intern (format "=%s" name)))))
1129                    (setq child-ccs-list (cons ret child-ccs-list)))
1130                )
1131               ((and
1132                 (not readable)
1133                 (not (eq name '->subsumptive))
1134                 (not (eq name '->uppercase))
1135                 (not (eq name '->lowercase))
1136                 (not (eq name '->titlecase))
1137                 (not (eq name '->canonical))
1138                 (not (eq name '->Bopomofo))
1139                 (not (eq name '->mistakable))
1140                 (not (eq name '->ideographic-variants))
1141                 (or (eq name '<-identical)
1142                     (eq name '<-uppercase)
1143                     (eq name '<-lowercase)
1144                     (eq name '<-titlecase)
1145                     (eq name '<-canonical)
1146                     (eq name '<-ideographic-variants)
1147                     ;; (eq name '<-synonyms)
1148                     (string-match "^<-synonyms" (symbol-name name))
1149                     (eq name '<-mistakable)
1150                     (when (string-match "^->" (symbol-name name))
1151                       (cond
1152                        ((string-match "^->fullwidth" (symbol-name name))
1153                         (not (and (consp value)
1154                                   (characterp (car value))
1155                                   (encode-char
1156                                    (car value) '=ucs 'defined-only)))
1157                         )
1158                        (t)))
1159                     ))
1160                )
1161               ((eq name 'ideographic-structure)
1162                (insert (isd-turtle-format-char nil nil value (/ column 4)
1163                                                'isd 'without-head-char))
1164                (insert " ;")
1165                )
1166               ((eq name '->subsumptive)
1167                (insert line-separator)
1168                (char-db-turtle-insert-relation-feature char name value
1169                                                        line-breaking
1170                                                        ccss readable)
1171                (setq children value)
1172                )
1173               (t
1174                (insert (format "%s    %-20s "
1175                                line-separator
1176                                (chise-turtle-uri-encode-feature-name name-base)))
1177                (unless (char-db-turtle-insert-feature-value
1178                         value metadata name-domain name-base)
1179                  (insert " ;"))
1180                )
1181               ))
1182       (setq attributes (cdr attributes)))
1183     (insert (format "%s    ." line-breaking))
1184     (dolist (eq-cpos (nreverse eq-cpos-list))
1185       (setq ret (chise-split-ccs-name (nth 1 eq-cpos)))
1186       (insert (format "%s    %s" line-breaking
1187                       (car eq-cpos)))
1188       (insert (format "%s        %25s" line-breaking
1189                       (format ":%s-of" (nth 1 ret))))
1190       (if (null (nth 2 ret))
1191           (insert (format " %14s:%-7s ."
1192                           (chise-turtle-uri-encode-ccs-name (car ret))
1193                           (nth 1 (split-string (car eq-cpos) ":"))))
1194         (insert " [ ")
1195         (setq col (current-column))
1196         (insert (format ":context domain:%-7s ;\n%s:target %7s:%-7s ] ."
1197                         (chise-turtle-uri-encode-ccs-name (nth 2 ret))
1198                         (make-string col ?\ )
1199                         (chise-turtle-uri-encode-ccs-name (car ret))
1200                         (nth 1 (split-string (car eq-cpos) ":"))))))
1201     (setq est-coded-charset-priority-list
1202           (append est-coded-charset-priority-list
1203                   (nreverse child-ccs-list)))
1204     (when children
1205       (dolist (child children)
1206         (insert (format "%s    " line-breaking))
1207         (char-db-turtle-insert-char-features child nil nil nil 'for-sub-node)))
1208     ))
1209
1210 (defun char-db-turtle-insert-char-data (char &optional readable attributes)
1211   (save-restriction
1212     (narrow-to-region (point)(point))
1213     (char-db-turtle-insert-char-features char readable attributes)
1214     (insert "\n\n")
1215     ))
1216
1217 (defun char-db-turtle-insert-prefix ()
1218   (let (base-ccs-list ret)
1219     (insert "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
1220 @prefix : <http://rdf.chise.org/rdf/property/character/main/> .
1221 @prefix ideo: <http://rdf.chise.org/rdf/property/character/ideo/> .
1222 @prefix isd: <http://rdf.chise.org/rdf/property/character/isd/> .
1223 @prefix idc: <http://rdf.chise.org/rdf/type/character/idc/> .
1224 @prefix chisegg: <http://rdf.chise.org/rdf/type/character/ggg/> .
1225 @prefix domain: <http://rdf.chise.org/data/domain/> .
1226 @prefix script: <http://rdf.chise.org/data/script/> .
1227 @prefix ideocomb: <http://rdf.chise.org/data/character/ideo/combination/> .
1228 @prefix chisebib: <http://rdf.chise.org/data/bibliography/> .
1229 @prefix ruimoku: <http://www.chise.org/est/view/article@ruimoku/rep.id=/> .
1230 @prefix zob1959: <http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/> .
1231
1232 ")
1233     (dolist (cell (sort chise-turtle-ccs-prefix-alist
1234                         (lambda (a b)
1235                           (char-attribute-name< (cdr a)(cdr b)))))
1236       (insert (format "@prefix %s: <%s/%s=> .\n"
1237                       (car cell)
1238                       "http://www.chise.org/est/view/character"
1239                       (www-uri-encode-feature-name (cdr cell))))
1240       (setq ret (chise-split-ccs-name (cdr cell)))
1241       (unless (memq (car ret) base-ccs-list)
1242         (setq base-ccs-list (cons (car ret) base-ccs-list))))
1243     (insert "\n")
1244     (dolist (base-ccs (nreverse base-ccs-list))
1245       (insert (format "@prefix %s: <%s/%s/code-point/> .\n"
1246                       (chise-turtle-uri-encode-ccs-name base-ccs)
1247                       "http://rdf.chise.org/data/ccs"
1248                       (www-uri-encode-feature-name base-ccs))))))
1249
1250 (defun char-db-turtle-insert-ideograph-radical-char-data (radical)
1251   (let ((chars
1252          (sort (copy-list (aref ideograph-radical-chars-vector radical))
1253                (lambda (a b)
1254                  (ideograph-char< a b radical))))
1255         attributes)
1256     (dolist (name (char-attribute-list))
1257       (unless (memq name char-db-ignored-attributes)
1258         (push name attributes)
1259         ))
1260     (setq attributes (sort attributes #'char-attribute-name<))
1261     (aset ideograph-radical-chars-vector radical chars)
1262     (dolist (char chars)
1263       (when (not (some (lambda (atr)
1264                          (get-char-attribute char atr))
1265                        char-db-ignored-attributes))
1266         (char-db-turtle-insert-char-data char nil attributes)))
1267     ))
1268
1269 (defun char-db-turtle-write-ideograph-radical-char-data (radical file)
1270   (if (file-directory-p file)
1271       (let ((name (char-feature (decode-char 'ucs (+ #x2EFF radical))
1272                                 'name)))
1273         (if (string-match "KANGXI RADICAL " name)
1274             (setq name (capitalize (substring name (match-end 0)))))
1275         (setq name (mapconcat (lambda (char)
1276                                 (if (eq char ? )
1277                                     "-"
1278                                   (char-to-string char))) name ""))
1279         (setq file
1280               (expand-file-name
1281                (format "Ideograph-R%03d-%s.ttl" radical name)
1282                file))))
1283   (let (chise-turtle-ccs-prefix-alist)
1284     (with-temp-buffer
1285       (char-db-turtle-insert-ideograph-radical-char-data radical)
1286       (goto-char (point-min))
1287       (char-db-turtle-insert-prefix)
1288       (insert "\n")
1289       (goto-char (point-min))
1290       (insert (format "# -*- coding: %s -*-\n"
1291                       char-db-file-coding-system))
1292       (let ((coding-system-for-write char-db-file-coding-system))
1293         (write-region (point-min)(point-max) file)))))
1294
1295
1296 ;;; @ end
1297 ;;;
1298
1299 (provide 'char-db-turtle)
1300
1301 ;;; char-db-turtle.el ends here