X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fest.git;a=blobdiff_plain;f=char-db-json.el;h=2da62e51b16a498572e8d4ea8b801d376b6c00ad;hp=c38d39a4228aaeadc22e56fcc14105370e8af0e9;hb=HEAD;hpb=ea3c57528562f9c5f2fbd10ccf8ddd230ed45766 diff --git a/char-db-json.el b/char-db-json.el index c38d39a..2da62e5 100644 --- a/char-db-json.el +++ b/char-db-json.el @@ -30,7 +30,8 @@ (setq char-db-ignored-attributes '(ideographic-products - ->HNG + composition + ;; ->HNG *instance@ruimoku/bibliography/title *instance@morpheme-entry/zh-classical)) @@ -197,9 +198,9 @@ =shinjigen/+p@rev ==shinjigen/+p@rev ===daikanwa/ho ==daikanwa/ho =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho)) - " %-18s %4d,\t\"_comment\": \"%c") + " %-20s %4d,\t\"_comment\": \"%c") ((eq name '=shinjigen@1ed/24pr) - " %-18s %4d,\t\"_comment\": \"%c") + " %-20s %4d,\t\"_comment\": \"%c") ((or (memq name '(===daikanwa @@ -244,20 +245,20 @@ ===hng-smk)) ;; (string-match "^=adobe-" (symbol-name name)) ) - " %-18s %5d,\t\"_comment\": \"%c") + " %-20s %5d,\t\"_comment\": \"%c") ((memq name '(=hanyo-denshi/ks ==hanyo-denshi/ks ===hanyo-denshi/ks =>>hanyo-denshi/ks =koseki ==koseki =mj ==mj ===mj =>>mj =>mj =zihai mojikyo)) - " %-18s %6d,\t\"_comment\": \"%c") + " %-19s %6d,\t\"_comment\": \"%c") ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk)) - " %-18s %8d,\t\"_comment\": \"%c") + " %-20s %8d,\t\"_comment\": \"%c") ((>= (charset-dimension name) 2) - " %-18s %5d,\t\"_comment\": \"%c") + " %-20s %5d,\t\"_comment\": \"%c") (t - " %-18s %3d,\t\"_comment\": \"%c")) + " %-20s %3d,\t\"_comment\": \"%c")) (format "\"%s\":" name) (if (= (charset-iso-graphic-plane name) 1) (logior value @@ -278,18 +279,20 @@ (insert "\"")) ) (t - (insert (format " %-18s %s" + (insert (format " %-20s %s" (format "\"%s\":" name) value)) )) ) (defun char-db-json-insert-relation-feature (char name value line-breaking ccss readable) - (insert (format " %-18s [%s " + (insert (format " %-20s [%s " (format "\"%s\":" name) line-breaking)) (let ((lbs (concat "\n" (make-string (current-column) ?\ ))) separator cell sources required-features ret) + (if (characterp value) + (setq value (list value))) (while (consp value) (setq cell (car value)) (if (integerp cell) @@ -367,11 +370,14 @@ (if separator (insert separator) (setq separator (format ",%s" lbs))) - (if readable - (insert (format "%S" cell)) - (char-db-json-insert-char-spec cell readable - nil - required-features)) + ;; (if readable + ;; (insert (format "%S" cell)) + ;; (char-db-json-insert-char-spec cell readable + ;; nil + ;; required-features)) + (char-db-json-insert-char-spec cell readable + nil + required-features) ) ((consp cell) (if separator @@ -395,12 +401,14 @@ for-sub-node) (unless column (setq column (current-column))) - (let (name value ; has-long-ccs-name + (let ((est-view-url-prefix "http://chise.org/est/view") + id obj-id type + name value ; has-long-ccs-name rest radical strokes (line-breaking (concat "\n" (make-string (1+ column) ?\ ))) - (line-separator nil) + line-separator lbs cell separator ret key al cal dest-ccss ; sources required-features @@ -423,22 +431,48 @@ (push name atr-d))) atr-d) #'char-attribute-name<))) - (insert "{") + (insert + (format "{ \"@context\": \"%s/genre/character/context.json\"" + est-view-url-prefix)) + (setq line-separator (format ",%s" line-breaking)) + (setq id (www-uri-make-object-url char)) + (insert (format "%s \"@id\": \"%s\"" line-separator id)) + (setq obj-id (file-name-nondirectory id)) + (setq type + (cond + ((string-match "^a2\\." obj-id) + "chise:super-abstract-character") + ((string-match "^a\\." obj-id) + "chise:abstract-character") + ((string-match "^o\\." obj-id) + "chise:unified-glyph") + ((string-match "^rep\\." obj-id) + "chise:abstract-glyph") + ((string-match "^g\\." obj-id) + "chise:detailed-glyph") + ((string-match "^g2\\." obj-id) + "chise:abstract-glyph-form") + ((string-match "^gi\\." obj-id) + "chise:abstract-glyph-form") + ((string-match "^repi\\." obj-id) + "chise:glyph-image") + (t + "chise:character") + )) + (insert (format "%s \"@type\": \"%s\"" line-separator type)) (when (memq '<-subsumptive attributes) (when (or readable (not for-sub-node)) (when (setq value (get-char-attribute char '<-subsumptive)) + (insert line-separator) (char-db-json-insert-relation-feature char '<-subsumptive value line-breaking ccss readable) - (setq line-separator (format ",%s" line-breaking)) )) (setq attributes (delq '<-subsumptive attributes)) ) (when (and (memq '<-denotational attributes) (setq value (get-char-attribute char '<-denotational))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (char-db-json-insert-relation-feature char '<-denotational value line-breaking ccss readable) @@ -446,9 +480,7 @@ (when (and (memq '<-denotational@component attributes) (setq value (get-char-attribute char '<-denotational@component))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (char-db-json-insert-relation-feature char '<-denotational@component value line-breaking @@ -456,56 +488,44 @@ (setq attributes (delq '<-denotational@component attributes))) (when (and (memq 'name attributes) (setq value (get-char-attribute char 'name))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format (if (> (+ (current-column) (length value)) 48) - "\"name\": %S" - "\"name\": %S") + " \"name\": %S" + " \"name\": %S") value)) (setq attributes (delq 'name attributes)) ) (when (and (memq 'name* attributes) (setq value (get-char-attribute char 'name*))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format (if (> (+ (current-column) (length value)) 48) - "\"name*\": %S" - "{\"name*\": %S") + " \"name*\": %S" + " \"name*\": %S") value)) (setq attributes (delq 'name* attributes)) ) (when (and (memq 'script attributes) (setq value (get-char-attribute char 'script))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"script\":\t\t%s}%s" + (insert line-separator) + (insert (format " \"script\":\t\t %s" (mapconcat (function prin1-to-string) - value " ") - line-breaking)) + value " "))) (setq attributes (delq 'script attributes)) ) (dolist (name '(=>ucs =>ucs*)) (when (and (memq name attributes) (setq value (get-char-attribute char name))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"%-18s\": #x%04X},\t\"_comment\": \"%c\"%s" - name value (decode-char '=ucs value) - line-breaking)) + (insert line-separator) + (insert (format " \"%-20s\": #x%04X,\t\"_comment\": \"%c\"" + name value (decode-char '=ucs value))) (setq attributes (delq name attributes)))) (dolist (name '(=>ucs@gb =>ucs@big5)) (when (and (memq name attributes) (setq value (get-char-attribute char name))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"%-18s\": #x%04X},\t\"_comment\": \"%c\"%s" + (insert line-separator) + (insert (format " \"%-20s\": #x%04X,\t\"_comment\": \"%c\"%s" name value (decode-char (intern (concat "=" @@ -517,11 +537,9 @@ )) (when (and (memq 'general-category attributes) (setq value (get-char-attribute char 'general-category))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format - "{\"general-category\":\t%s} // %s%s" + " \"general-category\":\t [ %s ], \"_comment\": \"%s\"" (mapconcat (lambda (cell) (format "%S" cell)) value " ") @@ -531,87 +549,64 @@ "Informative Category") (t "Unknown Category")) - line-breaking)) + )) (setq attributes (delq 'general-category attributes)) ) (when (and (memq 'bidi-category attributes) (setq value (get-char-attribute char 'bidi-category))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"bidi-category\":\t %S}%s" - value - line-breaking)) + (insert line-separator) + (insert (format " \"bidi-category\":\t %S" + value)) (setq attributes (delq 'bidi-category attributes)) ) (unless (or (not (memq 'mirrored attributes)) (eq (setq value (get-char-attribute char 'mirrored 'empty)) 'empty)) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"mirrored\":\t\t %S}%s" - value - line-breaking)) + (insert line-separator) + (insert (format " \"mirrored\":\t\t %S" + value)) (setq attributes (delq 'mirrored attributes)) ) (cond ((and (memq 'decimal-digit-value attributes) (setq value (get-char-attribute char 'decimal-digit-value))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"decimal-digit-value\": %S}%s" - value - line-breaking)) + (insert line-separator) + (insert (format " \"decimal-digit-value\": %S" + value)) (setq attributes (delq 'decimal-digit-value attributes)) (when (and (memq 'digit-value attributes) (setq value (get-char-attribute char 'digit-value))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"digit-value\":\t %S}%s" - value - line-breaking)) + (insert line-separator) + (insert (format " \"digit-value\":\t %S" + value)) (setq attributes (delq 'digit-value attributes)) ) (when (and (memq 'numeric-value attributes) (setq value (get-char-attribute char 'numeric-value))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"numeric-value\":\t %S}%s" - value - line-breaking)) + (insert line-separator) + (insert (format " \"numeric-value\":\t %S" + value)) (setq attributes (delq 'numeric-value attributes)) ) ) (t (when (and (memq 'digit-value attributes) (setq value (get-char-attribute char 'digit-value))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"digit-value\":\t %S}%s" - value - line-breaking)) + (insert line-separator) + (insert (format " \"digit-value\":\t %S" + value)) (setq attributes (delq 'digit-value attributes)) ) (when (and (memq 'numeric-value attributes) (setq value (get-char-attribute char 'numeric-value))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"numeric-value\":\t %S}%s" - value - line-breaking)) + (insert line-separator) + (insert (format " \"numeric-value\":\t %S" + value)) (setq attributes (delq 'numeric-value attributes)) ))) (when (and (memq 'iso-10646-comment attributes) (setq value (get-char-attribute char 'iso-10646-comment))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format "{\"iso-10646-comment\":\t %S}%s" value line-breaking)) @@ -619,9 +614,7 @@ ) (when (and (memq 'morohashi-daikanwa attributes) (setq value (get-char-attribute char 'morohashi-daikanwa))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format "{\"morohashi-daikanwa\":\t%s}%s" (mapconcat (function prin1-to-string) value " ") line-breaking)) @@ -632,9 +625,7 @@ (when (and (memq 'ideographic-radical attributes) (setq value (get-char-attribute char 'ideographic-radical))) (setq radical value) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format " \"ideographic-radical\": %S,\t\"_comment\": \"%c\"" radical (ideographic-radical radical) @@ -643,13 +634,10 @@ ) (when (and (memq 'shuowen-radical attributes) (setq value (get-char-attribute char 'shuowen-radical))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"shuowen-radical\":\t %S},\t\"_comment\": \"%c\"%s" + (insert line-separator) + (insert (format " \"shuowen-radical\":\t %S,\t\"_comment\": \"%c\"" value - (shuowen-radical value) - line-breaking)) + (shuowen-radical value))) (setq attributes (delq 'shuowen-radical attributes)) ) (let (key) @@ -670,9 +658,7 @@ (when (and (memq key attributes) (setq value (get-char-attribute char key))) (setq radical value) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format "{\"%s\": %S},\t\"_comment\": \"%c\"%s" key radical @@ -684,9 +670,7 @@ (when (and (memq key attributes) (setq value (get-char-attribute char key))) (setq strokes value) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format " \"%s\": %S" key strokes)) @@ -695,9 +679,7 @@ (setq key (intern (format "%s@%s" 'total-strokes domain))) (when (and (memq key attributes) (setq value (get-char-attribute char key))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format " \"%s\": %S" key value @@ -710,9 +692,7 @@ (setq key (intern (format "%s@%s*sources" feature domain))) (when (and (memq key attributes) (setq value (get-char-attribute char key))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format " \"%s\":%s" key line-breaking)) (dolist (cell value) (insert (format " %s" cell))) @@ -722,9 +702,7 @@ (when (and (memq 'ideographic-strokes attributes) (setq value (get-char-attribute char 'ideographic-strokes))) (setq strokes value) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format " \"ideographic-strokes\": %S" strokes )) @@ -733,9 +711,7 @@ (when (and (memq 'kangxi-radical attributes) (setq value (get-char-attribute char 'kangxi-radical))) (unless (eq value radical) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format "{\"kangxi-radical\":\t%S},\t\"_comment\": \"%c\"%s" value (ideographic-radical value) @@ -747,9 +723,7 @@ (when (and (memq 'kangxi-strokes attributes) (setq value (get-char-attribute char 'kangxi-strokes))) (unless (eq value strokes) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format "{\"kangxi-strokes\":\t%S}%s" value line-breaking)) @@ -757,26 +731,10 @@ (setq strokes value))) (setq attributes (delq 'kangxi-strokes attributes)) ) - (when (and (memq 'japanese-radical attributes) - (setq value (get-char-attribute char 'japanese-radical))) - (unless (eq value radical) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"japanese-radical\":\t%S},\t\"_comment\": \"%c\"%s" - value - (ideographic-radical value) - line-breaking)) - (or radical - (setq radical value))) - (setq attributes (delq 'japanese-radical attributes)) - ) (when (and (memq 'japanese-strokes attributes) (setq value (get-char-attribute char 'japanese-strokes))) (unless (eq value strokes) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format "{\"japanese-strokes\":\t%S}%s" value line-breaking)) @@ -786,9 +744,7 @@ ) (when (and (memq 'cns-radical attributes) (setq value (get-char-attribute char 'cns-radical))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format "{\"cns-radical\":\t%S},\t\"_comment\": \"%c\"%s" value (ideographic-radical value) @@ -798,9 +754,7 @@ (when (and (memq 'cns-strokes attributes) (setq value (get-char-attribute char 'cns-strokes))) (unless (eq value strokes) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format "{\"cns-strokes\":\t%S}%s" value line-breaking)) @@ -808,69 +762,14 @@ (setq strokes value))) (setq attributes (delq 'cns-strokes attributes)) ) - (when (and (memq 'ideographic- attributes) - (setq value (get-char-attribute char 'ideographic-))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert "{\"ideographic-\": ") - (setq lbs (concat "\n" (make-string (current-column) ?\ )) - separator nil) - (while (consp value) - (setq cell (car value)) - (if (integerp cell) - (setq cell (decode-char '=ucs cell))) - (cond ((characterp cell) - (if separator - (insert lbs)) - (if readable - (insert (format "%S" cell)) - (char-db-json-insert-char-spec cell readable)) - (setq separator lbs)) - ((consp cell) - (if separator - (insert lbs)) - (if (consp (car cell)) - (char-db-json-insert-char-spec cell readable) - (char-db-json-insert-char-reference cell readable)) - (setq separator lbs)) - (t - (if separator - (insert separator)) - (insert (prin1-to-string cell)) - (setq separator " "))) - (setq value (cdr value))) - (insert " }") - (insert line-breaking) - (setq attributes (delq 'ideographic- attributes))) (when (and (memq 'total-strokes attributes) (setq value (get-char-attribute char 'total-strokes))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (insert (format " \"total-strokes\": %S" value )) (setq attributes (delq 'total-strokes attributes)) ) - (when (and (memq '->ideograph attributes) - (setq value (get-char-attribute char '->ideograph))) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"->ideograph\":\t%s}%s" - (mapconcat (lambda (code) - (cond ((symbolp code) - (symbol-name code)) - ((integerp code) - (format "#x%04X" code)) - (t - (format "%s %S" - line-breaking code)))) - value " ") - line-breaking)) - (setq attributes (delq '->ideograph attributes)) - ) (if (equal (get-char-attribute char '->titlecase) (get-char-attribute char '->uppercase)) (setq attributes (delq '->titlecase attributes))) @@ -887,24 +786,18 @@ (setq name (charset-name ret)) (when (not (memq name dest-ccss)) (setq dest-ccss (cons name dest-ccss)) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (char-db-json-insert-ccs-feature name value line-breaking)) ) ((string-match "^=>ucs@" (symbol-name name)) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"%-18s\": #x%04X},\t\"_comment\": \"%c\"%s" + (insert line-separator) + (insert (format "{\"%-20s\": #x%04X},\t\"_comment\": \"%c\"%s" name value (decode-char '=ucs value) line-breaking)) ) ((eq name 'jisx0208-1978/4X) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"%-18s\": #x%04X}%s" + (insert line-separator) + (insert (format "{\"%-20s\": #x%04X}%s" name value line-breaking)) ) @@ -946,7 +839,7 @@ ) ((or (eq name 'ideographic-structure) (eq name 'ideographic-combination) - (eq name 'ideographic-) + ;; (eq name 'ideographic-) (eq name '=decomposition) (char-feature-base-name= '=decomposition name) (char-feature-base-name= '=>decomposition name) @@ -956,48 +849,14 @@ (string-match "^\\(->\\|<-\\)[^*]*\\*sources$" (symbol-name name)) ) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) + (insert line-separator) (char-db-json-insert-relation-feature char name value line-breaking ccss readable)) - ((memq name '(ideograph= - original-ideograph-of - ancient-ideograph-of - vulgar-ideograph-of - wrong-ideograph-of - ;; simplified-ideograph-of - ideographic-variants - ;; ideographic-different-form-of - )) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"%-18s\":%s " name line-breaking)) - (setq lbs (concat "\n" (make-string (current-column) ?\ )) - separator nil) - (while (consp value) - (setq cell (car value)) - (if (and (consp cell) - (consp (car cell))) - (progn - (if separator - (insert lbs)) - (char-db-json-insert-alist cell readable) - (setq separator lbs)) - (if separator - (insert separator)) - (insert (prin1-to-string cell)) - (setq separator " ")) - (setq value (cdr value))) - (insert " }") - (insert line-breaking)) ((consp value) - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"%-18s\": " name)) + (insert line-separator) + (insert (format " %-20s [ " + (format "\"%s\":" name))) (setq lbs (concat "\n" (make-string (current-column) ?\ )) separator nil) (while (consp value) @@ -1035,27 +894,23 @@ (insert ret) (setq separator " ")) (setq value (cdr value))) - (insert " }") - (insert line-breaking)) + (insert " ]") + ) (t - (if line-separator - (insert line-separator) - (setq line-separator (format ",%s" line-breaking))) - (insert (format "{\"%-18s\":" name)) + (insert line-separator) + (insert (format " %-20s " + (format "\"%s\":" name))) (setq ret (prin1-to-string value)) (unless (< (+ (current-column) (length ret) 3) 76) (insert line-breaking)) - (insert ret " }" line-breaking) - ;; (insert (format "(%-18s . %S)%s" - ;; name value - ;; line-breaking)) + (insert ret) ) )) (setq attributes (cdr attributes))) - (insert " }"))) + (insert "\n" (make-string column ?\ ) "}"))) (defun char-db-json-char-data (char &optional readable attributes column) @@ -1136,7 +991,8 @@ ;;;###autoload (defun what-char-definition-json (char) (interactive (list (char-after))) - (let ((buf (get-buffer-create "*Character Description*")) + (let ((est-hide-cgi-mode t) + (buf (get-buffer-create "*Character Description*")) (the-buf (current-buffer)) (win-conf (current-window-configuration))) (pop-to-buffer buf) @@ -1146,7 +1002,7 @@ (erase-buffer) (condition-case err (progn - (char-db-json-char-data-with-variant char nil) + (char-db-json-char-data-with-variant char 'printable) (unless (char-attribute-alist char) (insert (format "// = %c\n" (let* ((rest (split-char char))