[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/writegood-mode 40c4733cde 25/47: Flesch-Kincaid refactor/c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/writegood-mode 40c4733cde 25/47: Flesch-Kincaid refactor/cleanup |
Date: |
Mon, 12 Dec 2022 21:01:41 -0500 (EST) |
branch: elpa/writegood-mode
commit 40c4733cde09c968caeae7f74da420805d335410
Author: Benjamin Beckwith <bnbeckwith@gmail.com>
Commit: Benjamin Beckwith <bnbeckwith@gmail.com>
Flesch-Kincaid refactor/cleanup
---
writegood-mode.el | 79 ++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 52 insertions(+), 27 deletions(-)
diff --git a/writegood-mode.el b/writegood-mode.el
index e79feef220..54b573830f 100755
--- a/writegood-mode.el
+++ b/writegood-mode.el
@@ -23,6 +23,7 @@
;;
;;; Change Log:
;;
+;; 2.0 Fleisch-Kincaid scoring added to functionality
;; 1.3 Several pull requests added, comments checked, passive voice regexp
fixed
;; 1.2 Fixed weasel-words regexp to have word boundaries
;; 1.1 Fixed regexps to be multiline.
@@ -138,6 +139,18 @@
:group 'writegood
:type 'list)
+(defcustom writegood-sentence-punctuation
+ '(?. ?? ?!)
+ "List of punctuation denoting sentence end"
+ :group 'writegood
+ :type '(repeat character))
+
+(defcustom writegood-vowels
+ '(?a ?e ?i ?o ?u ?y)
+ "List of punctuation denoting sentence end"
+ :group 'writegood
+ :type '(repeat character))
+
(defvar writegood-passive-voice-font-lock-keywords-regexp
(concat
"\\b\\(am\\|are\\|were\\|being\\|is\\|been\\|was\\|be\\)\\b\\([[:space:]]\\|\\s<\\|\\s>\\)+\\([[:word:]]+ed\\|"
(regexp-opt writegood-passive-voice-irregulars)
@@ -210,40 +223,54 @@
(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-count-words (rstart rend)
+ "Count the words specified by the region bounded by RSTART and REND."
+ (if (boundp 'count-words)
+ (count-words rstart rend)
+ (how-many "[[:word:]]+" rstart rend)))
+
+(defun writegood-count-sentences (rstart rend)
+ "Count the sentences specified by the region bounded by RSTART and REND."
+ (how-many (regexp-opt-charset writegood-sentence-punctuation) rstart rend))
+
+(defun writegood-count-syllables (rstart rend)
+ "Count the number of syllables in the region bounded by RSTART and REND."
+ (how-many (regexp-opt-charset writegood-vowels) rstart rend))
+
+(defun writegood-fk-parameters (&optional rstart rend)
+ "Flesch-Kincaid reading parameters"
+ (let* ((start (cond (rstart rstart)
+ ((and transient-mark-mode mark-active)
(region-beginning))
+ ('t (point-min))))
+ (end (cond (rend rend)
+ ((and transient-mark-mode mark-active) (region-end))
+ ('t (point-max))))
+ (words (float (writegood-count-words start end)))
+ (syllables (float (writegood-count-syllables start end)))
+ (sentences (float (writegood-count-sentences start end))))
+ (list sentences words syllables)))
+;;;###autoload
(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)))))
+ (let* ((params (writegood-fk-parameters start end))
+ (sentences (nth 0 params))
+ (words (nth 1 params))
+ (syllables (nth 2 params))
+ (score (- 206.835 (* 1.015 (/ words sentences)) (* 84.6 (/
syllables words)))))
(message "Flesch-Kincaid reading ease score: %.2f" score)))
+;;;###autoload
(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)))
+ (let* ((params (writegood-fk-parameters start end))
+ (sentences (nth 0 params))
+ (words (nth 1 params))
+ (syllables (nth 2 params))
(score (+ (* 0.39 (/ words sentences)) (* 11.8 (/ syllables
words)) -15.59)))
- (message "Flesh-Kincaid grade level score: %.2f" score)))
+ (message "Flesch-Kincaid grade level score: %.2f" score)))
;;;###autoload
(define-minor-mode writegood-mode
@@ -255,8 +282,6 @@
(writegood-turn-off))
(font-lock-mode 1)))
-(provide 'writegood-mode
- 'writegood-reading-ease
- 'writegood-grade-level)
+(provide 'writegood-mode)
;;; writegood-mode.el ends here
- [nongnu] branch elpa/writegood-mode created (now d54eadeedb), ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode a14fbf7852 05/47: Updated colors and modeline string, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode ea11b93bf8 14/47: Fixed the link text., ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode b412798c19 16/47: Merge pull request #2 from dwcramer/localchanges, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 4302169c15 32/47: Fix font lock issues in org-mode. Update faces., ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 2537107022 34/47: Merge pull request #13 from jjasghar/whitespace, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 416453af5a 38/47: Merge pull request #18 from sten0/master, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode ecb888b659 01/47: Initial version, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 40c4733cde 25/47: Flesch-Kincaid refactor/cleanup,
ELPA Syncer <=
- [nongnu] elpa/writegood-mode 62fa034d08 19/47: Merge pull request #4 from morphling/patch-1, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 3db1a3bbf1 08/47: Added version const and function, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 1dba5de892 29/47: Updated README to highlight new functionality, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode d42e8f5500 37/47: Remove executable bit from README.org and writegood-mode.el, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode d54eadeedb 47/47: Add tooltips to detected text sections, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 599aed98f5 03/47: Fixed the link in the README to the original scripts, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 41d8a193c1 24/47: Flesch-Kincaid tests, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode c772829f30 10/47: Blocks of comments are now checked as well. (See Test Text for examples), ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 07275921a1 22/47: Merge pull request #6 from frankshearar/fix-nits, ELPA Syncer, 2022/12/12
- [nongnu] elpa/writegood-mode 2dcba94eb2 33/47: Whitespaces, ELPA Syncer, 2022/12/12