# HG changeset patch # User Oleksandr Gavenko # Date 1507142797 -10800 # Node ID 50969212d5d235a093c48c72e2b9cc35f43752d1 # Parent 79ac87d089764f583630b987d1b4f140fcdc41f4 Remove accent if only one syllable in word. diff -r 79ac87d08976 -r 50969212d5d2 contrib/gadict.el --- a/contrib/gadict.el Wed Oct 04 21:22:27 2017 +0300 +++ b/contrib/gadict.el Wed Oct 04 21:46:37 2017 +0300 @@ -40,6 +40,25 @@ +(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]+") + +(defun gadict--vowel-group-count (s) + (let ( (cnt 0) (start 0) ) + (while (string-match gadict--vowels-re s start) + (setq cnt (1+ cnt)) + (setq start (match-end 0))) + cnt)) + +(defun gadict--espeak-cleanup-accent (s) + "Remove accent if only one syllable in word." + (if (<= (gadict--vowel-group-count s) 1) + (replace-regexp-in-string "$,1$h(B" "" s) + s)) + +(defun gadict--espeak-cleanup-accent-in-sentence (s) + "Remove accent if only one syllable in word." + (mapconcat #'gadict--espeak-cleanup-accent (split-string s " ") " ")) + (defun gadict--espeak-cleanup (s) "Cleanup espeak IPA output." (mapc (lambda (fn) (setq s (funcall fn s))) @@ -47,7 +66,8 @@ ;; UTF symbol between t$(O*h(B to make ligature. (lambda (str) (replace-regexp-in-string "[\x200D]" "" str)) (lambda (str) (replace-regexp-in-string "t$(O*h(B" "$,1$G(B" str)) - #'gadict--trim)) + #'gadict--trim + #'gadict--espeak-cleanup-accent-in-sentence)) s) (defvar gadict-espeak-enabled nil