lib/sekka/henkan.nnd in sekka-0.8.4 vs lib/sekka/henkan.nnd in sekka-0.8.5
- old
+ new
@@ -37,10 +37,11 @@
(use rfc.json)
(use sekka.util)
(use sekka.convert-jisyo)
(use sekka.jisyo-db)
(use sekka.alphabet-lib)
+(use sekka.sharp-number)
(use sekka.google-ime)
(require "sekka/approximatesearch")
;; 曖昧検索の評価値にヒューリスティックを加える
@@ -161,10 +162,36 @@
kouho)
(if (= limit 0)
lst
(take* lst limit)))))
+
+
+;; 送り仮名なし、かつ、数字で始まるキーワードの変換
+(define (henkan-okuri-nashi-and-number userid kvs keyword limit)
+ ;; 数字部分を抜きだして '#' に変換
+ (let ([num-list (to-list (keyword.scan #/[0-9]+/))]
+ [replaced (keyword.gsub #/[0-9]+/ "#")])
+ ;; 辞書引きした結果の # 部分を 再度数値に戻す。
+ (let1 result (henkan-okuri-nashi userid kvs replaced limit)
+ (map
+ (lambda (entry)
+ (let* ([type-list (to-list (. (car entry) scan #/[#][0-9]/))]
+ [converted-list
+ (map
+ (lambda (_type _num)
+ (sekka-henkan-sharp-number _type _num))
+ type-list
+ num-list)]
+ [format-str (. (car entry) gsub #/[#][0-9]/ "%s")])
+ (cons
+ (apply sprintf
+ (cons format-str
+ converted-list))
+ (append (drop-right (cdr entry) 1)
+ (list 'n)))))
+ result))))
;; 送り仮名ありの変換
(define (henkan-okuri-ari userid kvs keyword limit roman-method)
(let* ((keyword (let1 _pair (string-split-first-and-rest keyword)
@@ -244,10 +271,20 @@
(lambda (value)
(split-henkan-kouho value keyword))
kouho)))
+;; 数字だけで構成されるキーワードの変換
+(define (henkan-number kvs keyword)
+ ;; 数字部分を抜きだして '#' に変換
+ `(
+ (,(sekka-henkan-sharp-number "#1" keyword) nil ,keyword n)
+ (,(sekka-henkan-sharp-number "#0" keyword) nil ,keyword n)
+ (,(sekka-henkan-sharp-number "#2" keyword) nil ,keyword n)
+ (,(sekka-henkan-sharp-number "#3" keyword) nil ,keyword n)))
+
+
;; keyword には ローマ字のみを受け付ける
(define (sekka-henkan userid kvs keyword limit roman-method)
;; 変換候補にindex番号を付加する
(define (append-index-number kouho-list)
(let1 count 0
@@ -282,9 +319,17 @@
(henkan-okuri-nashi userid kvs k limit)
(if (null? (gen-roman->hiragana (sekka-downcase k) roman-method))
'()
(henkan-hiragana kvs (sekka-downcase k) roman-method)))
(henkan-alphabet kvs keyword))))))
+ ;; 10進数数値のみで構成されるキーワード
+ ((rxmatch #/^[0-9]+$/ keyword)
+ (henkan-number kvs keyword))
+ ;; 10進数数値で始まるキーワード
+ ((rxmatch #/^[0-9]+[0-9a-zA-Z@-]+$/ keyword)
+ (append
+ (henkan-okuri-nashi-and-number userid kvs keyword limit)
+ (henkan-alphabet kvs keyword)))
((not (null? (gen-roman->hiragana keyword roman-method)))
(append
(append
(henkan-hiragana kvs keyword roman-method)
(henkan-alphabet kvs keyword))