Sign in to follow this  
Followers 0
jaberwacky

Automated Readability Index

7 posts in this topic

#1 ·  Posted (edited)

This is still in the early stages.

Input a text from a source such as wikipedia and click calculate. The reading level should appear below.

Update: Latest version now counts syllables in words! Next update will use different syllable based formulas.

Article: https://secure.wikimedia.org/wikipedia/en/wiki/Automated_Readability_Index

Usefull for teachers?

AutoItObject required (search for it)

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Au3Check_Stop_OnWarning=y
#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -d
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstantsEx.au3>
#include <AutoItObject.au3>

Global Const $gui = GUICreate("Automated Readability Index", 400, 300)

Global Const $input = GUICtrlCreateEdit('', 10, 10, 380, 240)

Global Const $label = GUICtrlCreateLabel("Reading Level:", 10, 255, 72, 15)

Global Const $output = GUICtrlCreateLabel('', 85, 255, 50, 15)

Global Const $calculate_index = GUICtrlCreateButton("Calculate", 10, 270)

GUISetState(@SW_SHOWNORMAL)

Global $characters = 0
Global $words = 1
Global $sentences = 0
Global $paragraph
Global $char_array
Global $string_length
Global $index
Global $char

_AutoItObject_Startup()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($gui)
            Exit
        Case $calculate_index
            $paragraph = GUICtrlRead($input)

            If $paragraph = '' Then
                MsgBox(0, "Error", "No text was detected")
                ContinueLoop
            EndIf

            remove_punctuation()

            $paragraph = StringReplace($paragraph, @CRLF, ' ')

            $paragraph = StringStripWS($paragraph, 7)

            $string_length = StringLen($paragraph)

            For $i = 1 To $string_length
                $char = StringMid($paragraph, $i, 1)

                Select
                    Case $char = ' '
                        $words += 1

                    Case $char = '.'
                        $sentences += 1

                    Case StringIsAlNum($char)
                        $characters += 1
                EndSelect
            Next

            ConsoleWrite("Characters : " & $characters & @CRLF)
            ConsoleWrite("Words   : " & $words & @CRLF)
            ConsoleWrite("Sentences  : " & $sentences & @CRLF)
            ConsoleWrite("Average amount of characters per word : " & Round($characters / $words, 2) & @CRLF)
            ConsoleWrite("Average amount of words per sentence  : " & Round($words / $sentences, 2) & @CRLF)

            ; Count the syllables ----------------------------------------------------------------------------------------
            Global $temp = StringSplit($paragraph, ' ')
            Global $wordTmp
            Global Const $upbound = UBound($temp) - 1

            For $i = 1 To $upbound
                $wordTmp = Word($temp[$i])

                $wordTmp.IsSilentE()

                $wordTmp.CountVowels()

                ConsoleWrite("Word         : " & $wordTmp.Word & @CRLF)
                ConsoleWrite("Syllable Count : " & $wordTmp.VowelCount & @CRLF & @CRLF) ; & $wordTmp.Length & "   "
            Next
            ; ------------------------------------------------------------------------------------------------------------

            ; approximate the required reading level
            $index = 4.71 * ($characters / $words) + 0.5 * ($words / $sentences) - 21.43 ; by the power of magic numbers!
            $index = Round($index, 2)
            GUICtrlSetData($output, $index)
            ConsoleWrite("Index   : " & $index & @CRLF)

            $characters = 0
            $words = 1
            $sentences = 0
            $index = 0
    EndSwitch
WEnd

_AutoItObject_Shutdown()

; --------------------------------------------------------------------------------------------------------------

Func remove_punctuation()
    Local Const $punctuation_chars = """';:/?>,<]}[{|=+-_)(*&^%$#@!" ; this has every mark except: '.'

    Local Const $char_array = StringSplit($punctuation_chars, '')
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $char_array[0] = ' & $char_array[0] & @CRLF) ;### Debug Console

    For $i = 1 To $char_array[0]
        $paragraph = StringReplace($paragraph, $char_array[$i], '')
    Next
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func Word(Const $word)
    Local Const $vowels = "aeiou"
    Local Const $consonants = "bcdfghjklmnpqrstvwxyz"
    Local Const $length = StringLen($word)

    Local $this = _AutoitObject_Class()

    $this.AddProperty("Word", $elscope_readonly, $word)
    $this.AddProperty("Length", $elscope_readonly, $length)
    $this.AddProperty("Syllables", $elscope_readonly, '?')
    $this.AddProperty("Dipthongs", $elscope_readonly, '?')
    $this.AddProperty("VowelCount", $elscope_readonly)
    $this.AddProperty("Map", $elscope_private, '?')
    $this.AddProperty("SilentE", $elscope_readonly, '?')
    $this.AddProperty("Vowels", $elscope_private, $vowels)
    $this.AddProperty("Consonants", $elscope_private, $consonants)
    $this.AddProperty("", $elscope_private, '')

    $this.AddMethod("CountVowels", "Word_CountVowels")

    $this.AddMethod("SyllableMap", "Word_SyllableMap", True)
    $this.AddMethod("IsSilentE", "Word_IsSilentE")
    $this.AddMethod("", "Word_", True)

    Return $this.Object
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func Word_IsSilentE($this)
    If StringMid($this.Word, $this.Length, 1) <> 'e' Then
        $this.SilentE = False
    Else
        If $this.Map == '?' Then $this.SyllableMap()

        If StringRight($this.Map, 3) == "vcv" Then
            $this.SilentE = True
        Else
            $this.SilentE = False
        EndIf
    EndIf

    Return $this.SilentE
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func Word_SyllableMap($this)
    Local $char = ''

    Local $map = ''

    For $i = 1 To $this.Length
        $char = StringMid($this.Word, $i, 1)

        If StringInStr($this.Vowels, $char) Then
            $map &= 'v'
        ElseIf StringInStr($this.Consonants, $char) Then
            $map &= 'c'
        ElseIf $char == ' ' Then
            $map &= ' '
        EndIf
    Next

    $this.Map = $map

    Return $this.Map
EndFunc

; --------------------------------------------------------------------------------------------------------------

Func Word_CountVowels($this)
    If $this.Map == '?' Then $this.SyllableMap()

    Local $vowel_count = 0

    For $i = 1 To $this.Length
        If StringMid($this.Map, $i, 1) == 'v' Then $vowel_count += 1
    Next

    If $this.IsSilentE() Then $vowel_count -= 1

    If StringInStr($this.Map, "vv") Then $vowel_count -= 1

    $this.VowelCount = $vowel_count

    Return $this.VowelCount
EndFunc
Edited by LaCastiglione

Share this post


Link to post
Share on other sites



#5 ·  Posted (edited)

Well, it's kinda basic for now. It may get complicated in the future.

I would like to in the future see an autoit script be able to take a given corpus and determine its subject.

That would be cool.

Edited by hyperzap

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This book describes learning natural lingusitics processing; even to the point of getting a computer to understand and interpret sentence structure. At a basic level. I know someone at Sydney University who is doing NLP and is developing a system to convert any corpus into a unambigious computer structure (James Curran), with remarkable accuracy.

Here is the book,

http://www.nltk.org/book

Its language of choice is python, and it will teach you to use that along the way.

Anyways, one of the exercises in the book is determining the subject of a given corpus.

Edited by hyperzap

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0