emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/writegood-mode 41d8a193c1 24/47: Flesch-Kincaid tests


From: ELPA Syncer
Subject: [nongnu] elpa/writegood-mode 41d8a193c1 24/47: Flesch-Kincaid tests
Date: Mon, 12 Dec 2022 21:01:41 -0500 (EST)

branch: elpa/writegood-mode
commit 41d8a193c13eca43e037c25bd23e70fbf627e964
Author: Ben <ben@rentenna.com>
Commit: Ben <ben@rentenna.com>

    Flesch-Kincaid tests
---
 writegood-mode.el | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/writegood-mode.el b/writegood-mode.el
index ff0f7964b4..e79feef220 100755
--- a/writegood-mode.el
+++ b/writegood-mode.el
@@ -210,6 +210,41 @@
   (writegood-passive-voice-turn-off)
   (writegood-duplicates-turn-off))
 
+(defun writegood-count-syllables (str)
+  "Approximate the number of sentences in a string by counting vowels 
(including 'y')."
+  (max 1 (length (mapconcat (lambda (x) (if (member x (list 97 101 105 111 117 
121)) "." "")) str ""))))
+
+(defun writegood-count-sentences (str)
+  "Approximate the number of sentences in a string by counting '.', '!', and 
'?'."
+  (max 1 (length (mapconcat (lambda (x) (if (member x (list 33 46 63)) "." 
"")) str ""))))
+
+(defun writegood-count-words (str)
+  (max 1 (/ (length str) 5)))
+
+(defun writegood-reading-ease (&optional start end)
+  "Flesch-Kincaid reading ease test. Scores roughly between 0 and 100."
+   (interactive)
+   (let* ((start     (if mark-active (region-beginning) (point-min)))
+          (end       (if mark-active (region-end) (point-max)))
+          (text      (buffer-substring-no-properties start end))
+          (words     (float (writegood-count-words text)))
+          (sentences (float (writegood-count-sentences text)))
+          (syllables (float (writegood-count-syllables text)))
+          (score     (- 206.835 (* 1.015 (/ words sentences)) (* 84.6 (/ 
syllables words)))))
+     (message "Flesch-Kincaid reading ease score: %.2f" score)))
+
+(defun writegood-grade-level (&optional start end)
+  "Flesch-Kincaid grade level test. Converts reading ease score to a grade 
level (Score ~ years of school needed to read passage)."
+   (interactive)
+   (let* ((start     (if mark-active (region-beginning) (point-min)))
+          (end       (if mark-active (region-end) (point-max)))
+          (text      (buffer-substring-no-properties start end))
+          (words     (float (writegood-count-words text)))
+          (sentences (float (writegood-count-sentences text)))
+          (syllables (float (writegood-count-syllables text)))
+          (score     (+ (* 0.39 (/ words sentences)) (* 11.8 (/ syllables 
words)) -15.59)))
+     (message "Flesh-Kincaid grade level score: %.2f" score)))
+
 ;;;###autoload
 (define-minor-mode writegood-mode
   "Colorize issues with the writing in the buffer."
@@ -220,6 +255,8 @@
       (writegood-turn-off))
     (font-lock-mode 1)))
 
-(provide 'writegood-mode)
+(provide 'writegood-mode
+         'writegood-reading-ease
+         'writegood-grade-level)
 
 ;;; writegood-mode.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]