Flesch-Kincaid Readability Tests

Implements the Flesch Reading Ease and Flesch-Kincaid Grade Level tests, which are designed to indicate comprehension difficulty when reading a passage of contemporary academic English.

Author: Sketch@M*U*S*H
Category: Functions
Commands: @create, @describe, @lock, @set.
Compatibility: PennMUSH.

Instructions

Copy and paste the below code into a compatible MUSH or MUX.

MUSHCode for Flesch-Kincaid Readability Tests

@create syllables
@desc syllables=th u\([num(me)]/GRADELEVEL,<text>)%rth u\([num(me)]/READABILITY,<text>)
@lock syllables==me
&ADDSYLLABLES syllables=ia|riet|dien|ien|iet|iu|iest|io|ii|ily|.oala$|.iara$|.ying$|.earest|.arer|.aress|.eate$|.eation$|[aeiouym]bl$|[aeiou]{3}|'ism|^mc|'asm|([^aeiouy])\1l$|[^l]lien|^coa[dglx].|[^gq]ua[^auieo]|dnt$
@set syllables/ADDSYLLABLES=veiled
&CREDITS syllables=Syllable counter adapted from http://www.russellmcveigh.info/ajax-syllable-counter, which is based on Greg Fast's Perl module Lingua::EN::Syllables (as of 2010-10-11). Flesch-Kincaid formulas from pretty much anywhere, but taken from Wikipedia. Code by Sketch@M*U*S*H.
&GRADELEVEL syllables=[@@(Flesch-Kincaid grade level)][add(mul(0.39,fdiv(u(words,%0),u(sentences,%0))),mul(11.8,fdiv(u(syllables,%0),u(words,%0))),-15.59)]
&READABILITY syllables=[@@(Flesch-Kincaid readability)][add(206.876,mul(-1.015,fdiv(u(words,%0),u(sentences,%0))),mul(-84.6,fdiv(u(syllables,%0),u(words,%0))))]
&SENTENCES syllables=max([letq(0,,null(regeditall(%0,\[\\.;\]+,setq(0,%q01)<-->))[strlen(%q0)])],1)
&SUBSYLLABLES syllables=cial|tia|cius|cious|uiet|gious|geous|priest|giu|dge|ion|iou|sia$|.che$|.ched$|.abe$|.ace$|.ade$|.age$|.aged$|.ake$|.ale$|.aled$|.ales$|.ane$|.ame$|.ape$|.are$|.ase$|.ashed$|.asque$|.ate$|.ave$|.azed$|.awe$|.aze$|.aped$|.athe$|.athes$|.ece$|.ese$|.esque$|.esques$|.eze$|.gue$|.ibe$|.ice$|.ide$|.ife$|.ike$|.ile$|.ime$|.ine$|.ipe$|.iped$|.ire$|.ise$|.ished$|.ite$|.ive$|.ize$|.obe$|.ode$|.oke$|.ole$|.ome$|.one$|.ope$|.oque$|.ore$|.ose$|.osque$|.osques$|.ote$|.ove$|.pped$|.sse$|.ssed$|.ste$|.ube$|.uce$|.ude$|.uge$|.uke$|.ule$|.ules$|.uled$|.ume$|.une$|.upe$|.ure$|.use$|.ushed$|.ute$|.ved$|.we$|.wes$|.wed$|.yse$|.yze$|.rse$|.red$|.rce$|.rde$|.ily$|.ely$|.des$|.gged$|.kes$|.ced$|.ked$|.med$|.mes$|.ned$|.sed$|.nce$|.rles$|.nes$|.pes$|.tes$|.res$|.ves$|ere$
@set syllables/SUBSYLLABLES=veiled
&SUBSYLLABLES_2 syllables=abe ace ade age ale are use ate
&SYLLABLES syllables=lmath(add,map(syllables_in_word,squish(%0)) 0)
&SYLLABLES_IN_WORD syllables=u(syllables_in_word_real,regeditall(lcstr(%0),\[^a-z\]+,))
&SYLLABLES_IN_WORD_REAL syllables=switch(lmath(add, [letq(0,,null(regeditall(%0,v(subsyllables),setq(0,%q01)))-[strlen(%q0)])] [letq(0,,null(regeditall(%0,v(addsyllables),setq(0,%q01)))[strlen(%q0)])] -[t(member(v(subsyllables_2),%0))] [words(regeditall(%0,\[^aeiouy\]+,%b))]),0,1,#$)
&WORDS syllables=words(edit(%0,/,%b))

look syllables