contrib/gadict.el
changeset 926 50969212d5d2
parent 925 79ac87d08976
child 934 6eea1f63443f
equal deleted inserted replaced
925:79ac87d08976 926:50969212d5d2
    38   "Remove whitespace at the beginning and end of S."
    38   "Remove whitespace at the beginning and end of S."
    39   (gadict--trim-left (gadict--trim-right s)))
    39   (gadict--trim-left (gadict--trim-right s)))
    40 
    40 
    41 
    41 
    42 
    42 
       
    43 (defconst gadict--vowels-re "[o$(O+8+:+7+9(Ba$(O+3+0,Af(Be,0#$(O+1(Bi,0!(Bu$(O+5+C+U+S+T(B]+")
       
    44 
       
    45 (defun gadict--vowel-group-count (s)
       
    46   (let ( (cnt 0) (start 0) )
       
    47     (while (string-match gadict--vowels-re s start)
       
    48       (setq cnt (1+ cnt))
       
    49       (setq start (match-end 0)))
       
    50     cnt))
       
    51 
       
    52 (defun gadict--espeak-cleanup-accent (s)
       
    53   "Remove accent if only one syllable in word."
       
    54   (if (<= (gadict--vowel-group-count s) 1)
       
    55       (replace-regexp-in-string "$,1$h(B" "" s)
       
    56     s))
       
    57 
       
    58 (defun gadict--espeak-cleanup-accent-in-sentence (s)
       
    59   "Remove accent if only one syllable in word."
       
    60   (mapconcat #'gadict--espeak-cleanup-accent (split-string s " ") " "))
       
    61 
    43 (defun gadict--espeak-cleanup (s)
    62 (defun gadict--espeak-cleanup (s)
    44   "Cleanup espeak IPA output."
    63   "Cleanup espeak IPA output."
    45   (mapc (lambda (fn) (setq s (funcall fn s)))
    64   (mapc (lambda (fn) (setq s (funcall fn s)))
    46         (list
    65         (list
    47          ;; UTF symbol between t$(O*h(B to make ligature.
    66          ;; UTF symbol between t$(O*h(B to make ligature.
    48          (lambda (str) (replace-regexp-in-string "[\x200D]" "" str))
    67          (lambda (str) (replace-regexp-in-string "[\x200D]" "" str))
    49          (lambda (str) (replace-regexp-in-string "t$(O*h(B" "$,1$G(B" str))
    68          (lambda (str) (replace-regexp-in-string "t$(O*h(B" "$,1$G(B" str))
    50          #'gadict--trim))
    69          #'gadict--trim
       
    70          #'gadict--espeak-cleanup-accent-in-sentence))
    51   s)
    71   s)
    52 
    72 
    53 (defvar gadict-espeak-enabled nil
    73 (defvar gadict-espeak-enabled nil
    54   "Is espeak used.")
    74   "Is espeak used.")
    55 
    75