Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion translated to Ruby

View Parsed - Show only message text

Received: by 10.90.113.17 with SMTP id l17mr5609809agc.14.1231353998491;
        Wed, 07 Jan 2009 10:46:38 -0800 (PST)
Return-Path: <kapel...@gmail.com>
Received: from rn-out-0910.google.com (rn-out-0910.google.com [64.233.170.190])
        by mx.google.com with ESMTP id 39si11806360yxd.15.2009.01.07.10.46.37;
        Wed, 07 Jan 2009 10:46:37 -0800 (PST)
Received-SPF: pass (google.com: domain of kapel...@gmail.com designates 64.233.170.190 as permitted sender) client-ip=64.233.170.190;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of kapel...@gmail.com designates 64.233.170.190 as permitted sender) smtp.mail=kapel...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by rn-out-0910.google.com with SMTP id k40so5786438rnd.0
        for <php-text-statistics@googlegroups.com>; Wed, 07 Jan 2009 10:46:37 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=gamma;
        h=domainkey-signature:received:received:message-id:date:from:to
         :subject:in-reply-to:mime-version:content-type:references;
        bh=o5oYEA5le56IOrE7m69B2mei0PYk/zdYlpzSCcjjDys=;
        b=kLvWu8YN8UEndbJ73xZBjdrZf1N4qwllbu80O5eaGXxS5UEvtjySLP/TzscfZSRnaX
         mXmH3IBZAczVnajP+R+Wpj0v4hvQHyN5QYdIT1kdFXwPgHxWZHpcEt7lSuUH8WZ4dhcs
         0TPYQrBQQXYkSD9Z/E8/j+Xp0105i3+L2VFMk=
DomainKey-Signature: a=rsa-sha1; c=nofws;
        d=gmail.com; s=gamma;
        h=message-id:date:from:to:subject:in-reply-to:mime-version
         :content-type:references;
        b=GH0nL9c15WfNPAhuJFmEQn9fJ6d6K1EjhJebFqy3ypNsRSR2yKjDnfHMtjlG7wpGiM
         73+F0/JuC3eKof9ks7NQaUSEIWm4KgubFlYm0zoK8KNNqPtS3yw6F9D5JGREpY2PaZ3r
         J1qkwfsC1aaXfqDpF0jgHOgUo95+5dNcS9erY=
Received: by 10.150.98.4 with SMTP id v4mr380565ybb.137.1231353997336;
        Wed, 07 Jan 2009 10:46:37 -0800 (PST)
Received: by 10.151.73.11 with HTTP; Wed, 7 Jan 2009 10:46:37 -0800 (PST)
Message-ID: <b2baff6b0901071046y24dce000t159817b43c0a668a@mail.gmail.com>
Date: Wed, 7 Jan 2009 10:46:37 -0800
From: "Adam Kapelner" <kapel...@gmail.com>
To: php-text-statistics@googlegroups.com
Subject: Re: translated to Ruby
In-Reply-To: <e8c787520901070202wc4731edwb9951bf004fec...@mail.gmail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_245913_5335230.1231353997326"
References: <45ac2e73-1edf-49a2-b265-925370aa8...@z27g2000prd.googlegroups.com>
	 <e8c787520901070202wc4731edwb9951bf004fec...@mail.gmail.com>

------=_Part_245913_5335230.1231353997326
Content-Type: text/plain; charset=ISO-8859-1

My pleasure.

I couldn't figure out how to translate that one line in the clean text
function:
#$strText = preg_replace_callback('/\. [^ ]+/', create_function
('$matches', 'return strtolower($matches[0]);'), $strText); // Lower
case all words following terminators (for gunning fog score)

So I guess that's the reason why my Gunning-Fog is off a bit.

Would you mind adding these two files to the repository? I won't have any
time for the next two months.

Thanks!
Adam


On Wed, Jan 7, 2009 at 2:02 AM, David Child <d...@addedbytes.com> wrote:

>
> Great work Adam!
>
> On Tue, Jan 6, 2009 at 11:16 PM, way4thesub <kapel...@gmail.com> wrote:
> >
> > Hello all,
> >
> > I've translated the php-text-statistics package to Ruby, you can view
> > the files below. Please note I couldn't get the Gunning Fog Score to
> > work 100%
> >
> > Regards,
> > Adam
> >
> >
> > ############### Code
> > require 'collections/sequenced_hash'
> >
> > module ReadabilityIndices
> >
> >  class Readability
> >
> >    NumDecimalPlaces = 1
> >
> >    Titles = SequencedHash.new
> >    Titles[:flesch_kincaid_grade_level] = 'Flesch-Kincaid Grade level'
> >    Titles[:flesch_kincaid_reading_ease] = 'Flesch-Kincaid Reading
> > Ease'
> >    Titles[:gunning_fog_score] = 'Gunning-Fog score'
> >    Titles[:coleman_liau_index] = 'Coleman-Liau Index'
> >    Titles[:smog_index] = 'SMOG Index'
> >    Titles[:automated_readability_index] = 'Automated Readability
> > Index'
> >
> >    attr_accessor :text
> >    def initialize(text = '')
> >      self.text = clean_text(text)
> >    end
> >
> >    def valid_index?(index)
> >      Titles[index] ? true : false
> >    end
> >
> >    def flesch_kincaid_grade_level
> >      round(0.39 * average_words_per_sentence + 11.8 *
> > average_syllables_per_word - 15.59, NumDecimalPlaces)
> >    end
> >
> >    def flesch_kincaid_reading_ease
> >      round(206.835 - 1.015 * average_words_per_sentence - 84.6 *
> > average_syllables_per_word, NumDecimalPlaces)
> >    end
> >
> >    def gunning_fog_score
> >      round((average_words_per_sentence +
> > percentage_words_with_three_syllables(false)) * 0.4, NumDecimalPlaces)
> >    end
> >
> >    def coleman_liau_index
> >      round(5.89 * letter_count / word_count - 0.3 * sentence_count /
> > word_count - 15.8, NumDecimalPlaces)
> >    end
> >
> >    def smog_index
> >      round(1.043 * Math.sqrt((words_with_three_syllables * (30 /
> > sentence_count)) + 3.1291), NumDecimalPlaces)
> >    end
> >
> >    def automated_readability_index
> >      round(4.71 * letter_count / word_count + 0.5 * word_count /
> > sentence_count - 21.43, NumDecimalPlaces)
> >    end
> >
> >    Colon = ": "
> >    Separator = ", "
> >    def get_indices_as_string(indices = [], diagnostics = true)
> >      indices = (indices.empty? ? Titles.keys : indices)
> >      str = indices.inject([]){|arr, index| arr << "#{Titles[index]}#
> > {Colon} #{self.send(index)}"; arr}.join(Separator)
> >      return diagnostics ? "words#{Colon} #{word_count}#{Separator}
> > sentences#{Colon} #{sentence_count}#{Separator} characters#{Colon} #
> > {letter_count}#{Separator}" + str : str
> >    end
> >
> > #    private
> >    def clean_text(text)
> >      text.gsub!(/[,:;()-]/, ' ') # Replace commans, hyphens etc
> > (count them as spaces)
> >      text.gsub!(/[\.!?]/, '.') # Unify terminators
> >      text = text.strip + '.' # Add final terminator, just in case
> > it's missing.
> >      text.gsub!(/[ ]*(\n|\r\n|\r)[ ]*/, ' ') # Replace new lines with
> > spaces
> >      text.gsub!(/([\.])[\.\s?]+/, ".") # Check for duplicated
> > terminators
> >      text.gsub!(/[ ]*([\.])/, "#{$1} ") # Pad sentence terminators
> >      text.gsub!(/[ ]+/, ' ') # Remove multiple spaces
> >      #$strText = preg_replace_callback('/\. [^ ]+/', create_function
> > ('$matches', 'return strtolower($matches[0]);'), $strText); // Lower
> > case all words following terminators (for gunning fog score)
> >      return text.strip
> >    end
> >
> >    def round(num, decimals)
> >      (num * 10 * decimals).round / (10 * decimals).to_f
> >    end
> >
> >    def letter_count
> >      self.text.gsub(/[^A-Za-z]+/, '').length.to_i
> >    end
> >
> >    def sentence_count
> >      [1, self.text.split(/\.!?/).length].max
> >    end
> >
> >    def word_count
> >      get_words.length
> >    end
> >
> >    def get_words
> >      @words ||= self.text.split(/\s+/)
> >    end
> >
> >    def average_words_per_sentence
> >      word_count / sentence_count.to_f
> >    end
> >
> >    def average_syllables_per_word
> >      total_syllables / get_words.length.to_f
> >    end
> >
> >    def total_syllables
> >      get_words.inject(0){|sum, word| sum + syllable_count(word)}
> >    end
> >
> >    def words_with_three_syllables(count_proper_nouns = true)
> >      get_words.inject(0) do |sum, word|
> >        if syllable_count(word) >= 3
> >          if count_proper_nouns
> >            sum += 1
> >          else
> >            sum += 1 if word[0..0] == word[0..0].downcase
> >          end
> >        end
> >        sum
> >      end
> >    end
> >
> >    def percentage_words_with_three_syllables(count_proper_nouns =
> > true)
> >      words_with_three_syllables(count_proper_nouns) / word_count.to_f
> > * 100
> >    end
> >
> >    ProblemWords = {
> >      'simile' => 3,
> >      'forever' => 3,
> >      'shoreline' => 2
> >    }
> >
> >    MultiSyllablesThatAreOne = [
> >      /cial/,
> >      /tia/,
> >      /cius/,
> >      /cious/,
> >      /giu/,
> >      /ion/,
> >      /iou/,
> >      /sia$/,
> >      /[^aeiuoyt]{2,}ed$/,
> >      /.ely$/,
> >      /[cg]h?e[rsd]?$/,
> >      /rved?$/,
> >      /[aeiouy][dt]es?$/,
> >      /[aeiouy][^aeiouydt]e[rsd]?$/,
> >      /^[dr]e[aeiou][^aeiou]+$/, #Sorts out deal, deign etc
> >      /[aeiouy]rse$/ #Purse, hears
> >    ]
> >
> >    UniSyllablesThatAreTwo = [
> >     /ia/,
> >     /riet/,
> >     /dien/,
> >     /iu/,
> >     /io/,
> >     /ii/,
> >     /[aeiouym]bl$/,
> >     /[aeiou]{3}/,
> >     /^mc/,
> >     /ism$/,
> >     /([^aeiouy])\1l$/,
> >     /[^l]lien/,
> >     /^coa[dglx]./,
> >     /[^gq]ua[^auieo]/,
> >     /dnt$/,
> >     /uity$/,
> >     /ie(r|st)$/
> >    ]
> >
> >    PrefixesAndSuffixes = [
> >      /^un/,
> >      /^fore/,
> >      /ly$/,
> >      /less$/,
> >      /ful$/,
> >      /ers?$/,
> >      /ings?$/
> >    ]
> >
> >    def syllable_count(word)
> >      word = word.downcase.strip
> >      #handle problem words first
> >      return ProblemWords[word] if ProblemWords[word]
> >
> >      #find number and delete prefixes and suffixes
> >      num_syllables = PrefixesAndSuffixes.inject(0) do |sum, prefix|
> >        word.scan(prefix){sum += 1}
> >        word.gsub!(prefix, '')
> >        sum
> >      end
> >
> >      #remove non-word chars
> >      word.gsub!(/[^a-z]/is, '')
> >
> >      #count word parts:
> >      num_syllables += word.split(/[^aeiouy]+/).inject(0){|sum,
> > word_part| sum + (word_part.blank? ? 0 : 1)}
> >
> >      #subtract out syllables that are really one:
> >      MultiSyllablesThatAreOne.each{|syl| word.scan(syl){num_syllables
> > -= 1}}
> >
> >      #add syllables that are really two:
> >      UniSyllablesThatAreTwo.each{|syl| word.scan(syl){num_syllables
> > += 1}}
> >
> >      return [1, num_syllables].max
> >    end
> >  end
> > end
> >
> > ############### RSpec tests
> >  include ReadabilityIndices
> >
> >  describe "readability indices" do
> >    before(:each) do
> >     @readability_blank = Readability.new
> >    end
> >
> >    it "should count simple syllable words correctly" do
> >      @readability_blank.syllable_count('a').should == 1
> >      @readability_blank.syllable_count('was').should == 1
> >      @readability_blank.syllable_count('the').should == 1
> >      @readability_blank.syllable_count('and').should == 1
> >      @readability_blank.syllable_count('foobar').should == 2
> >      @readability_blank.syllable_count('hello').should == 2
> >      @readability_blank.syllable_count('world').should == 1
> >      @readability_blank.syllable_count('wonderful').should == 3
> >      @readability_blank.syllable_count('simple').should == 2
> >      @readability_blank.syllable_count('easy').should == 2
> >      @readability_blank.syllable_count('hard').should == 1
> >      @readability_blank.syllable_count('quick').should == 1
> >      @readability_blank.syllable_count('brown').should == 1
> >      @readability_blank.syllable_count('fox').should == 1
> >      @readability_blank.syllable_count('jumped').should == 1
> >      @readability_blank.syllable_count('over').should == 2
> >      @readability_blank.syllable_count('lazy').should == 2
> >      @readability_blank.syllable_count('dog').should == 1
> >      @readability_blank.syllable_count('camera').should == 3
> >    end
> >
> >    it "should count syllables on programmed exceptions" do
> >      @readability_blank.syllable_count('simile').should == 3
> >      @readability_blank.syllable_count('shoreline').should == 2
> >      @readability_blank.syllable_count('forever').should == 3
> >    end
> >
> >    it "should count complex syllable words correctly" do
> >      @readability_blank.syllable_count
> > ('antidisestablishmentarianism').should == 12
> >      @readability_blank.syllable_count
> > ('supercalifragilisticexpialidocious').should == 14
> >      @readability_blank.syllable_count
> > ('chlorofluorocarbonation').should == 8
> >      @readability_blank.syllable_count('forethoughtfulness').should
> > == 4
> >      @readability_blank.syllable_count('phosphorescent').should == 4
> >      @readability_blank.syllable_count('theoretician').should == 5
> >      @readability_blank.syllable_count('promiscuity').should == 5
> >      @readability_blank.syllable_count('unbutlering').should == 4
> >      @readability_blank.syllable_count('continuity').should == 5
> >      @readability_blank.syllable_count('craunched').should == 1
> >      @readability_blank.syllable_count('squelched').should == 1
> >      @readability_blank.syllable_count('scrounge').should == 1
> >      @readability_blank.syllable_count('coughed').should == 1
> >      @readability_blank.syllable_count('smile').should == 1
> >      @readability_blank.syllable_count('monopoly').should == 4
> >      @readability_blank.syllable_count('doughey').should == 2
> >      @readability_blank.syllable_count('doughier').should == 3
> >      @readability_blank.syllable_count('leguminous').should == 4
> >      @readability_blank.syllable_count('thoroughbreds').should == 3
> >      @readability_blank.syllable_count('special').should == 2
> >      @readability_blank.syllable_count('delicious').should == 3
> >      @readability_blank.syllable_count('spatial').should == 2
> >      @readability_blank.syllable_count('pacifism').should == 4
> >      @readability_blank.syllable_count('coagulant').should == 4
> >      @readability_blank.syllable_count('shouldn\'t').should == 2
> >      @readability_blank.syllable_count('mcdonald').should == 3
> >      @readability_blank.syllable_count('audience').should == 3
> >      @readability_blank.syllable_count('finance').should == 2
> >      @readability_blank.syllable_count('prevalence').should == 3
> >      @readability_blank.syllable_count('impropriety').should == 5
> >      @readability_blank.syllable_count('alien').should == 3
> >      @readability_blank.syllable_count('dreadnought').should == 2
> >      @readability_blank.syllable_count('verandah').should == 3
> >      @readability_blank.syllable_count('similar').should == 3
> >      @readability_blank.syllable_count('similarly').should == 4
> >      @readability_blank.syllable_count('central').should == 2
> >      @readability_blank.syllable_count('cyst').should == 1
> >      @readability_blank.syllable_count('term').should == 1
> >      @readability_blank.syllable_count('order').should == 2
> >      @readability_blank.syllable_count('fur').should == 1
> >      @readability_blank.syllable_count('sugar').should == 2
> >      @readability_blank.syllable_count('paper').should == 2
> >      @readability_blank.syllable_count('make').should == 1
> >      @readability_blank.syllable_count('gem').should == 1
> >      @readability_blank.syllable_count('program').should == 2
> >      @readability_blank.syllable_count('hopeless').should == 2
> >      @readability_blank.syllable_count('hopelessly').should == 3
> >      @readability_blank.syllable_count('careful').should == 2
> >      @readability_blank.syllable_count('carefully').should == 3
> >      @readability_blank.syllable_count('stuffy').should == 2
> >      @readability_blank.syllable_count('thistle').should == 2
> >      @readability_blank.syllable_count('teacher').should == 2
> >      @readability_blank.syllable_count('unhappy').should == 3
> >      @readability_blank.syllable_count('ambiguity').should == 5
> >      @readability_blank.syllable_count('validity').should == 4
> >      @readability_blank.syllable_count('ambiguous').should == 4
> >      @readability_blank.syllable_count('deserve').should == 2
> >      @readability_blank.syllable_count('blooper').should == 2
> >      @readability_blank.syllable_count('scooped').should == 1
> >      @readability_blank.syllable_count('deserve').should == 2
> >      @readability_blank.syllable_count('deal').should == 1
> >      @readability_blank.syllable_count('death').should == 1
> >      @readability_blank.syllable_count('dearth').should == 1
> >      @readability_blank.syllable_count('deign').should == 1
> >      @readability_blank.syllable_count('reign').should == 1
> >      @readability_blank.syllable_count('bedsore').should == 2
> >      @readability_blank.syllable_count('anorexia').should == 5
> >      @readability_blank.syllable_count('anymore').should == 3
> >      @readability_blank.syllable_count('cored').should == 1
> >      @readability_blank.syllable_count('sore').should == 1
> >      @readability_blank.syllable_count('foremost').should == 2
> >      @readability_blank.syllable_count('restore').should == 2
> >      @readability_blank.syllable_count('minute').should == 2
> >      @readability_blank.syllable_count('manticores').should == 3
> >      @readability_blank.syllable_count('asparagus').should == 4
> >      @readability_blank.syllable_count('unexplored').should == 3
> >      @readability_blank.syllable_count('unexploded').should == 4
> >      @readability_blank.syllable_count('CAPITALS').should == 3
> >    end
> >
> >    it "should calculate average syllables per word" do
> >      Readability.new('and then there was
> > one').average_syllables_per_word.should == 1
> >      Readability.new('because special ducklings deserve
> > rainbows').average_syllables_per_word.should == 2
> >      Readability.new('and then there was one because special
> > ducklings deserve rainbows').average_syllables_per_word.should ==
> > 1.5
> >    end
> >
> >    it "should count words correctly" do
> >      Readability.new('The quick brown fox jumped over the lazy
> > dog').word_count.should == 9
> >      Readability.new('The quick brown fox jumped over the lazy
> > dog.').word_count.should == 9
> >      Readability.new('The quick brown fox jumped over the lazy dog.
> > ').word_count.should == 9
> >      Readability.new(' The quick brown fox jumped over the lazy dog.
> > ').word_count.should == 9
> >      Readability.new(' The  quick brown fox jumped over the lazy dog.
> > ').word_count.should == 9
> >      Readability.new('Yes. No.').word_count.should == 2
> >      Readability.new('Yes.No.').word_count.should == 2
> >      Readability.new('Yes.No.').word_count.should == 2
> >      Readability.new('Yes . No.').word_count.should == 2
> >      Readability.new('Yes - No. ').word_count.should == 2
> >    end
> >
> >    it "should get percentage of words with three syllables" do
> >      Readability.new('there is just one word with three syllables in
> > this sentence').percentage_words_with_three_syllables.round.should ==
> > 9
> >      Readability.new('there are no valid words with three Syllables
> > in this sentence').percentage_words_with_three_syllables.round.should
> > == 9
> >      Readability.new('there is one and only one word with three or
> > more syllables in this long boring sentence of twenty
> > words').percentage_words_with_three_syllables.round.should == 5
> >      Readability.new('there are two and only two words with three or
> > more syllables in this long sentence of exactly twenty
> > words').percentage_words_with_three_syllables.round.should == 10
> >      Readability.new('there is Actually only one valid word with
> > three or more syllables in this long sentence of Exactly twenty
> > words').percentage_words_with_three_syllables(false).round.should == 5
> >      Readability.new('no long words in this
> > sentence').percentage_words_with_three_syllables.round.should == 0
> >      Readability.new('no long valid words in this sentence because
> > the test ignores proper case words like this
> > Behemoth').percentage_words_with_three_syllables(false).round.should
> > == 0
> >    end
> >
> >    it "should count letters" do
> >      Readability.new('a').letter_count.should == 1
> >      Readability.new('').letter_count.should == 0
> >      Readability.new('this sentence has 30 characters, not including
> > the digits').letter_count.should == 46
> >    end
> >
> >    it "should count sentences" do
> >      Readability.new('This is a sentence').sentence_count.should == 1
> >      Readability.new('This is a sentence.').sentence_count.should ==
> > 1
> >      Readability.new('This is a sentence!').sentence_count.should ==
> > 1
> >      Readability.new('This is a sentence?').sentence_count.should ==
> > 1
> >      Readability.new('This is a sentence..').sentence_count.should ==
> > 1
> >      Readability.new('This is a sentence. So is
> > this.').sentence_count.should == 2
> >      Readability.new("This is a sentence. \n\n So is this, but this
> > is multi-line!").sentence_count.should == 2
> >      Readability.new('This is a sentence,. So is
> > this.').sentence_count.should == 2
> >      Readability.new('This is a sentence!? So is
> > this.').sentence_count.should == 2
> >      Readability.new('This is a sentence. So is this. And this one as
> > well.').sentence_count.should == 3
> >      Readability.new('This is a sentence - but just
> > one.').sentence_count.should == 1
> >      Readability.new('This is a sentence (but just
> > one).').sentence_count.should == 1
> >    end
> >
> >    it "should calculate average words per sentence" do
> >      Readability.new('This is a
> > sentence').average_words_per_sentence.should == 4
> >      Readability.new('This is a
> > sentence.').average_words_per_sentence.should == 4
> >      Readability.new('This is a sentence.
> > ').average_words_per_sentence.should == 4
> >      Readability.new('This is a sentence. This is a
> > sentence').average_words_per_sentence.should == 4
> >      Readability.new('This is a sentence. This is a
> > sentence.').average_words_per_sentence.should == 4
> >      Readability.new('This, is - a sentence . This is a sentence.
> > ').average_words_per_sentence.should == 4
> >      Readability.new('This is a sentence with extra text. This is a
> > sentence. ').average_words_per_sentence.should == 5.5
> >      Readability.new('This is a sentence with some extra text. This
> > is a sentence. ').average_words_per_sentence.should == 6
> >    end
> >
> >    describe "test indices directly" do
> >      before(:each) do
> >        @str_a = 'This. Is. A. Nice. Set. Of. Small. Words. Of. One.
> > Part. Each.'
> >        @str_b = 'The quick brown fox jumped over the lazy dog.'
> >        @str_c = 'The quick brown fox jumped over the lazy dog. The
> > quick brown fox jumped over the lazy dog.'
> >        @str_d = "The quick brown fox jumped over the lazy dog. \n\n
> > The quick brown fox jumped over the lazy dog."
> >        @str_e = 'The quick brown fox jumped over the lazy dog. The
> > quick brown fox jumped over the lazy dog'
> >        @str_f = 'Now it is time for a more complicated sentence,
> > including several longer words.'
> >        @str_g = 'Now it is time for a more Complicated sentence,
> > including Several longer words.'
> >      end
> >
> >      it "should calculate flesch-kincaid reading ease" do
> >        Readability.new(@str_a).flesch_kincaid_reading_ease.should ==
> > 121.2
> >        Readability.new(@str_b).flesch_kincaid_reading_ease.should ==
> > 94.3
> >        Readability.new(@str_c).flesch_kincaid_reading_ease.should ==
> > 94.3
> >        Readability.new(@str_d).flesch_kincaid_reading_ease.should ==
> > 94.3
> >        Readability.new(@str_e).flesch_kincaid_reading_ease.should ==
> > 94.3
> >        Readability.new(@str_f).flesch_kincaid_reading_ease.should ==
> > 50.5
> >      end
> >
> >      it "should calculate flesch-kincaid grade level" do
> >        Readability.new(@str_a).flesch_kincaid_grade_level.should ==
> > -3.4
> >        Readability.new(@str_b).flesch_kincaid_grade_level.should ==
> > 2.3
> >        Readability.new(@str_c).flesch_kincaid_grade_level.should ==
> > 2.3
> >        Readability.new(@str_d).flesch_kincaid_grade_level.should ==
> > 2.3
> >        Readability.new(@str_e).flesch_kincaid_grade_level.should ==
> > 2.3
> >        Readability.new(@str_f).flesch_kincaid_grade_level.should ==
> > 9.4
> >      end
> >
> >      it "should calculate Gunning-Fog Score" do
> >        Readability.new(@str_a).gunning_fog_score.should == 0.4
> >        Readability.new(@str_b).gunning_fog_score.should == 3.6
> >        Readability.new(@str_c).gunning_fog_score.should == 3.6
> >        Readability.new(@str_d).gunning_fog_score.should == 3.6
> >        Readability.new(@str_e).gunning_fog_score.should == 3.6
> >        Readability.new(@str_f).gunning_fog_score.should == 14.4
> >        Readability.new(@str_g).gunning_fog_score.should == 8.3
> >      end
> >
> >      it "should calculate coleman-liau index" do
> >        Readability.new(@str_a).coleman_liau_index.should == 3.0
> >        Readability.new(@str_b).coleman_liau_index.should == 7.7
> >        Readability.new(@str_c).coleman_liau_index.should == 7.7
> >        Readability.new(@str_d).coleman_liau_index.should == 7.7
> >        Readability.new(@str_e).coleman_liau_index.should == 7.7
> >        Readability.new(@str_f).coleman_liau_index.should ==
> > 13.6
> >      end
> >
> >      it "should calculate smog index" do
> >        Readability.new(@str_a).smog_index.should == 1.8
> >        Readability.new(@str_b).smog_index.should == 1.8
> >        Readability.new(@str_c).smog_index.should == 1.8
> >        Readability.new(@str_d).smog_index.should == 1.8
> >        Readability.new(@str_e).smog_index.should == 1.8
> >        Readability.new(@str_f).smog_index.should ==
> > 10.1
> >      end
> >
> >      it "should calculate automated readability index" do
> >        Readability.new(@str_a).automated_readability_index.should ==
> > -5.6
> >        Readability.new(@str_b).automated_readability_index.should ==
> > 1.9
> >        Readability.new(@str_c).automated_readability_index.should ==
> > 1.9
> >        Readability.new(@str_d).automated_readability_index.should ==
> > 1.9
> >        Readability.new(@str_e).automated_readability_index.should ==
> > 1.9
> >        Readability.new(@str_f).automated_readability_index.should ==
> > 8.6
> >      end
> >
> >      it "should index first paragraph of Moby Dick correctly" do
> >        str =<<-ENDL
> >          Call me Ishmael. Some years ago - never mind how long
> > precisely - having little or no money in my purse, and
> >          nothing particular to interest me on shore, I thought I
> > would sail about a little and see the watery part of
> >          the world. It is a way I have of driving off the spleen, and
> > regulating the circulation. Whenever I find myself
> >          growing grim about the mouth; whenever it is a damp, drizzly
> > November in my soul; whenever I find myself
> >          involuntarily pausing before coffin warehouses, and bringing
> > up the rear of every funeral I meet; and especially
> >          whenever my hypos get such an upper hand of me, that it
> > requires a strong moral principle to prevent me from
> >          deliberately stepping into the street, and methodically
> > knocking people's hats off - then, I account it high time
> >          to get to sea as soon as I can. This is my substitute for
> > pistol and ball. With a philosophical flourish Cato
> >          throws himself upon his sword; I quietly take to the ship.
> > There is nothing surprising in this. If they but knew
> >          it, almost all men in their degree, some time or other,
> > cherish very nearly the same feelings towards the ocean with me.
> >        ENDL
> >
> >        readability = Readability.new(str)
> >
> >        readability.letter_count.should == 884
> >        readability.word_count.should == 201
> >        readability.total_syllables.should == 304
> >        readability.sentence_count.should == 8
> >        readability.words_with_three_syllables.should == 23
> >
> >        readability.flesch_kincaid_grade_level.should == 12.1
> >        readability.flesch_kincaid_reading_ease.should == 53.4
> >        readability.gunning_fog_score.should == 14.2
> >        readability.coleman_liau_index.should == 10.1
> >        readability.smog_index.should == 8.9
> >        readability.automated_readability_index.should == 11.8
> >      end
> >
> >      it "should index a Kipling poem correctly" do
> >        str =<<-ENDL
> >          If you can keep your head when all about you
> >          Are losing theirs and blaming it on you,
> >          If you can trust yourself when all men doubt you
> >          But make allowance for their doubting too,
> >          If you can wait and not be tired by waiting,
> >          Or being lied about, don't deal in lies,
> >          Or being hated, don't give way to hating,
> >          And yet don't look too good, nor talk too wise:
> >
> >          If you can dream - and not make dreams your master,
> >          If you can think - and not make thoughts your aim;
> >          If you can meet with Triumph and Disaster
> >          And treat those two impostors just the same;
> >          If you can bear to hear the truth you've spoken
> >          Twisted by knaves to make a trap for fools,
> >          Or watch the things you gave your life to, broken,
> >          And stoop and build 'em up with worn-out tools:
> >
> >          If you can make one heap of all your winnings
> >          And risk it all on one turn of pitch-and-toss,
> >          And lose, and start again at your beginnings
> >          And never breath a word about your loss;
> >          If you can force your heart and nerve and sinew
> >          To serve your turn long after they are gone,
> >          And so hold on when there is nothing in you
> >          Except the Will which says to them: "Hold on"
> >
> >          If you can talk with crowds and keep your virtue,
> >          Or walk with kings - nor lose the common touch,
> >          If neither foes nor loving friends can hurt you;
> >          If all men count with you, but none too much,
> >          If you can fill the unforgiving minute
> >          With sixty seconds' worth of distance run,
> >          Yours is the Earth and everything that's in it,
> >          And - which is more - you'll be a Man, my son
> >        ENDL
> >
> >        readability = Readability.new(str)
> >
> >        readability.letter_count.should == 1125
> >        readability.word_count.should == 292
> >        readability.total_syllables.should == 338
> >        readability.sentence_count.should == 1
> >        readability.words_with_three_syllables.should == 6
> >
> >        readability.flesch_kincaid_grade_level.should == 111.9
> >        readability.flesch_kincaid_reading_ease.should == -187.5
> >        readability.gunning_fog_score.should == 117.5
> >        readability.coleman_liau_index.should == 6.9
> >        readability.smog_index.should == 14.1
> >        readability.automated_readability_index.should == 142.7
> >      end
> >    end
> >  end
> >
> > >
> >
>
> >
>

------=_Part_245913_5335230.1231353997326
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

My pleasure.<br><br>I couldn&#39;t figure out how to translate that one lin=
e in the clean text function:<br>#$strText =3D preg_replace_callback(&#39;/=
\. [^ ]+/&#39;, create_function<br>
(&#39;$matches&#39;, &#39;return strtolower($matches[0]);&#39;), $strText);=
 // Lower<br>
case all words following terminators (for gunning fog score)<br><br>So I gu=
ess that&#39;s the reason why my Gunning-Fog is off a bit.<br><br>Would you=
 mind adding these two files to the repository? I won&#39;t have any time f=
or the next two months.<br>
<br>Thanks!<br>Adam<br><br><br><div class=3D"gmail_quote">On Wed, Jan 7, 20=
09 at 2:02 AM, David Child <span dir=3D"ltr">&lt;<a href=3D"mailto:dave@add=
edbytes.com">d...@addedbytes.com</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin=
: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Great work Adam!<br>
<div><div></div><div class=3D"Wj3C7c"><br>
On Tue, Jan 6, 2009 at 11:16 PM, way4thesub &lt;<a href=3D"mailto:kapelner@=
gmail.com">kapel...@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hello all,<br>
&gt;<br>
&gt; I&#39;ve translated the php-text-statistics package to Ruby, you can v=
iew<br>
&gt; the files below. Please note I couldn&#39;t get the Gunning Fog Score =
to<br>
&gt; work 100%<br>
&gt;<br>
&gt; Regards,<br>
&gt; Adam<br>
&gt;<br>
&gt;<br>
&gt; ############### Code<br>
&gt; require &#39;collections/sequenced_hash&#39;<br>
&gt;<br>
&gt; module ReadabilityIndices<br>
&gt;<br>
&gt; &nbsp;class Readability<br>
&gt;<br>
&gt; &nbsp; &nbsp;NumDecimalPlaces =3D 1<br>
&gt;<br>
&gt; &nbsp; &nbsp;Titles =3D SequencedHash.new<br>
&gt; &nbsp; &nbsp;Titles[:flesch_kincaid_grade_level] =3D &#39;Flesch-Kinca=
id Grade level&#39;<br>
&gt; &nbsp; &nbsp;Titles[:flesch_kincaid_reading_ease] =3D &#39;Flesch-Kinc=
aid Reading<br>
&gt; Ease&#39;<br>
&gt; &nbsp; &nbsp;Titles[:gunning_fog_score] =3D &#39;Gunning-Fog score&#39=
;<br>
&gt; &nbsp; &nbsp;Titles[:coleman_liau_index] =3D &#39;Coleman-Liau Index&#=
39;<br>
&gt; &nbsp; &nbsp;Titles[:smog_index] =3D &#39;SMOG Index&#39;<br>
&gt; &nbsp; &nbsp;Titles[:automated_readability_index] =3D &#39;Automated R=
eadability<br>
&gt; Index&#39;<br>
&gt;<br>
&gt; &nbsp; &nbsp;attr_accessor :text<br>
&gt; &nbsp; &nbsp;def initialize(text =3D &#39;&#39;)<br>
&gt; &nbsp; &nbsp; &nbsp;self.text =3D clean_text(text)<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def valid_index?(index)<br>
&gt; &nbsp; &nbsp; &nbsp;Titles[index] ? true : false<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def flesch_kincaid_grade_level<br>
&gt; &nbsp; &nbsp; &nbsp;round(0.39 * average_words_per_sentence + 11.8 *<b=
r>
&gt; average_syllables_per_word - 15.59, NumDecimalPlaces)<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def flesch_kincaid_reading_ease<br>
&gt; &nbsp; &nbsp; &nbsp;round(206.835 - 1.015 * average_words_per_sentence=
 - 84.6 *<br>
&gt; average_syllables_per_word, NumDecimalPlaces)<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def gunning_fog_score<br>
&gt; &nbsp; &nbsp; &nbsp;round((average_words_per_sentence +<br>
&gt; percentage_words_with_three_syllables(false)) * 0.4, NumDecimalPlaces)=
<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def coleman_liau_index<br>
&gt; &nbsp; &nbsp; &nbsp;round(5.89 * letter_count / word_count - 0.3 * sen=
tence_count /<br>
&gt; word_count - 15.8, NumDecimalPlaces)<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def smog_index<br>
&gt; &nbsp; &nbsp; &nbsp;round(1.043 * Math.sqrt((words_with_three_syllable=
s * (30 /<br>
&gt; sentence_count)) + 3.1291), NumDecimalPlaces)<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def automated_readability_index<br>
&gt; &nbsp; &nbsp; &nbsp;round(4.71 * letter_count / word_count + 0.5 * wor=
d_count /<br>
&gt; sentence_count - 21.43, NumDecimalPlaces)<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;Colon =3D &quot;: &quot;<br>
&gt; &nbsp; &nbsp;Separator =3D &quot;, &quot;<br>
&gt; &nbsp; &nbsp;def get_indices_as_string(indices =3D [], diagnostics =3D=
 true)<br>
&gt; &nbsp; &nbsp; &nbsp;indices =3D (indices.empty? ? Titles.keys : indice=
s)<br>
&gt; &nbsp; &nbsp; &nbsp;str =3D indices.inject([]){|arr, index| arr &lt;&l=
t; &quot;#{Titles[index]}#<br>
&gt; {Colon} #{self.send(index)}&quot;; arr}.join(Separator)<br>
&gt; &nbsp; &nbsp; &nbsp;return diagnostics ? &quot;words#{Colon} #{word_co=
unt}#{Separator}<br>
&gt; sentences#{Colon} #{sentence_count}#{Separator} characters#{Colon} #<b=
r>
&gt; {letter_count}#{Separator}&quot; + str : str<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; # &nbsp; &nbsp;private<br>
&gt; &nbsp; &nbsp;def clean_text(text)<br>
&gt; &nbsp; &nbsp; &nbsp;text.gsub!(/[,:;()-]/, &#39; &#39;) # Replace comm=
ans, hyphens etc<br>
&gt; (count them as spaces)<br>
&gt; &nbsp; &nbsp; &nbsp;text.gsub!(/[\.!?]/, &#39;.&#39;) # Unify terminat=
ors<br>
&gt; &nbsp; &nbsp; &nbsp;text =3D text.strip + &#39;.&#39; # Add final term=
inator, just in case<br>
&gt; it&#39;s missing.<br>
&gt; &nbsp; &nbsp; &nbsp;text.gsub!(/[ ]*(\n|\r\n|\r)[ ]*/, &#39; &#39;) # =
Replace new lines with<br>
&gt; spaces<br>
&gt; &nbsp; &nbsp; &nbsp;text.gsub!(/([\.])[\.\s?]+/, &quot;.&quot;) # Chec=
k for duplicated<br>
&gt; terminators<br>
&gt; &nbsp; &nbsp; &nbsp;text.gsub!(/[ ]*([\.])/, &quot;#{$1} &quot;) # Pad=
 sentence terminators<br>
&gt; &nbsp; &nbsp; &nbsp;text.gsub!(/[ ]+/, &#39; &#39;) # Remove multiple =
spaces<br>
&gt; &nbsp; &nbsp; &nbsp;#$strText =3D preg_replace_callback(&#39;/\. [^ ]+=
/&#39;, create_function<br>
&gt; (&#39;$matches&#39;, &#39;return strtolower($matches[0]);&#39;), $strT=
ext); // Lower<br>
&gt; case all words following terminators (for gunning fog score)<br>
&gt; &nbsp; &nbsp; &nbsp;return text.strip<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def round(num, decimals)<br>
&gt; &nbsp; &nbsp; &nbsp;(num * 10 * decimals).round / (10 * decimals).to_f=
<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def letter_count<br>
&gt; &nbsp; &nbsp; &nbsp;self.text.gsub(/[^A-Za-z]+/, &#39;&#39;).length.to=
_i<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def sentence_count<br>
&gt; &nbsp; &nbsp; &nbsp;[1, self.text.split(/\.!?/).length].max<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def word_count<br>
&gt; &nbsp; &nbsp; &nbsp;get_words.length<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def get_words<br>
&gt; &nbsp; &nbsp; &nbsp;@words ||=3D self.text.split(/\s+/)<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def average_words_per_sentence<br>
&gt; &nbsp; &nbsp; &nbsp;word_count / sentence_count.to_f<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def average_syllables_per_word<br>
&gt; &nbsp; &nbsp; &nbsp;total_syllables / get_words.length.to_f<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def total_syllables<br>
&gt; &nbsp; &nbsp; &nbsp;get_words.inject(0){|sum, word| sum + syllable_cou=
nt(word)}<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def words_with_three_syllables(count_proper_nouns =3D tru=
e)<br>
&gt; &nbsp; &nbsp; &nbsp;get_words.inject(0) do |sum, word|<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;if syllable_count(word) &gt;=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if count_proper_nouns<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sum +=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sum +=3D 1 if word[0..0] =3D=
=3D word[0..0].downcase<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;end<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;sum<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;def percentage_words_with_three_syllables(count_proper_no=
uns =3D<br>
&gt; true)<br>
&gt; &nbsp; &nbsp; &nbsp;words_with_three_syllables(count_proper_nouns) / w=
ord_count.to_f<br>
&gt; * 100<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;ProblemWords =3D {<br>
&gt; &nbsp; &nbsp; &nbsp;&#39;simile&#39; =3D&gt; 3,<br>
&gt; &nbsp; &nbsp; &nbsp;&#39;forever&#39; =3D&gt; 3,<br>
&gt; &nbsp; &nbsp; &nbsp;&#39;shoreline&#39; =3D&gt; 2<br>
&gt; &nbsp; &nbsp;}<br>
&gt;<br>
&gt; &nbsp; &nbsp;MultiSyllablesThatAreOne =3D [<br>
&gt; &nbsp; &nbsp; &nbsp;/cial/,<br>
&gt; &nbsp; &nbsp; &nbsp;/tia/,<br>
&gt; &nbsp; &nbsp; &nbsp;/cius/,<br>
&gt; &nbsp; &nbsp; &nbsp;/cious/,<br>
&gt; &nbsp; &nbsp; &nbsp;/giu/,<br>
&gt; &nbsp; &nbsp; &nbsp;/ion/,<br>
&gt; &nbsp; &nbsp; &nbsp;/iou/,<br>
&gt; &nbsp; &nbsp; &nbsp;/sia$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/[^aeiuoyt]{2,}ed$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/.ely$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/[cg]h?e[rsd]?$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/rved?$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/[aeiouy][dt]es?$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/[aeiouy][^aeiouydt]e[rsd]?$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/^[dr]e[aeiou][^aeiou]+$/, #Sorts out deal, deign =
etc<br>
&gt; &nbsp; &nbsp; &nbsp;/[aeiouy]rse$/ #Purse, hears<br>
&gt; &nbsp; &nbsp;]<br>
&gt;<br>
&gt; &nbsp; &nbsp;UniSyllablesThatAreTwo =3D [<br>
&gt; &nbsp; &nbsp; /ia/,<br>
&gt; &nbsp; &nbsp; /riet/,<br>
&gt; &nbsp; &nbsp; /dien/,<br>
&gt; &nbsp; &nbsp; /iu/,<br>
&gt; &nbsp; &nbsp; /io/,<br>
&gt; &nbsp; &nbsp; /ii/,<br>
&gt; &nbsp; &nbsp; /[aeiouym]bl$/,<br>
&gt; &nbsp; &nbsp; /[aeiou]{3}/,<br>
&gt; &nbsp; &nbsp; /^mc/,<br>
&gt; &nbsp; &nbsp; /ism$/,<br>
&gt; &nbsp; &nbsp; /([^aeiouy])\1l$/,<br>
&gt; &nbsp; &nbsp; /[^l]lien/,<br>
&gt; &nbsp; &nbsp; /^coa[dglx]./,<br>
&gt; &nbsp; &nbsp; /[^gq]ua[^auieo]/,<br>
&gt; &nbsp; &nbsp; /dnt$/,<br>
&gt; &nbsp; &nbsp; /uity$/,<br>
&gt; &nbsp; &nbsp; /ie(r|st)$/<br>
&gt; &nbsp; &nbsp;]<br>
&gt;<br>
&gt; &nbsp; &nbsp;PrefixesAndSuffixes =3D [<br>
&gt; &nbsp; &nbsp; &nbsp;/^un/,<br>
&gt; &nbsp; &nbsp; &nbsp;/^fore/,<br>
&gt; &nbsp; &nbsp; &nbsp;/ly$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/less$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/ful$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/ers?$/,<br>
&gt; &nbsp; &nbsp; &nbsp;/ings?$/<br>
&gt; &nbsp; &nbsp;]<br>
&gt;<br>
&gt; &nbsp; &nbsp;def syllable_count(word)<br>
&gt; &nbsp; &nbsp; &nbsp;word =3D word.downcase.strip<br>
&gt; &nbsp; &nbsp; &nbsp;#handle problem words first<br>
&gt; &nbsp; &nbsp; &nbsp;return ProblemWords[word] if ProblemWords[word]<br=
>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;#find number and delete prefixes and suffixes<br>
&gt; &nbsp; &nbsp; &nbsp;num_syllables =3D PrefixesAndSuffixes.inject(0) do=
 |sum, prefix|<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;word.scan(prefix){sum +=3D 1}<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;word.gsub!(prefix, &#39;&#39;)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;sum<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;#remove non-word chars<br>
&gt; &nbsp; &nbsp; &nbsp;word.gsub!(/[^a-z]/is, &#39;&#39;)<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;#count word parts:<br>
&gt; &nbsp; &nbsp; &nbsp;num_syllables +=3D word.split(/[^aeiouy]+/).inject=
(0){|sum,<br>
&gt; word_part| sum + (word_part.blank? ? 0 : 1)}<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;#subtract out syllables that are really one:<br>
&gt; &nbsp; &nbsp; &nbsp;MultiSyllablesThatAreOne.each{|syl| word.scan(syl)=
{num_syllables<br>
&gt; -=3D 1}}<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;#add syllables that are really two:<br>
&gt; &nbsp; &nbsp; &nbsp;UniSyllablesThatAreTwo.each{|syl| word.scan(syl){n=
um_syllables<br>
&gt; +=3D 1}}<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;return [1, num_syllables].max<br>
&gt; &nbsp; &nbsp;end<br>
&gt; &nbsp;end<br>
&gt; end<br>
&gt;<br>
&gt; ############### RSpec tests<br>
&gt; &nbsp;include ReadabilityIndices<br>
&gt;<br>
&gt; &nbsp;describe &quot;readability indices&quot; do<br>
&gt; &nbsp; &nbsp;before(:each) do<br>
&gt; &nbsp; &nbsp; @readability_blank =3D Readability.new<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should count simple syllable words correctly&quo=
t; do<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;a&#39;).sho=
uld =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;was&#39;).s=
hould =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;the&#39;).s=
hould =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;and&#39;).s=
hould =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;foobar&#39;=
).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;hello&#39;)=
.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;world&#39;)=
.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;wonderful&#=
39;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;simple&#39;=
).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;easy&#39;).=
should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;hard&#39;).=
should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;quick&#39;)=
.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;brown&#39;)=
.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;fox&#39;).s=
hould =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;jumped&#39;=
).should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;over&#39;).=
should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;lazy&#39;).=
should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;dog&#39;).s=
hould =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;camera&#39;=
).should =3D=3D 3<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should count syllables on programmed exceptions&=
quot; do<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;simile&#39;=
).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;shoreline&#=
39;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;forever&#39=
;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should count complex syllable words correctly&qu=
ot; do<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count<br>
&gt; (&#39;antidisestablishmentarianism&#39;).should =3D=3D 12<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count<br>
&gt; (&#39;supercalifragilisticexpialidocious&#39;).should =3D=3D 14<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count<br>
&gt; (&#39;chlorofluorocarbonation&#39;).should =3D=3D 8<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;forethought=
fulness&#39;).should<br>
&gt; =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;phosphoresc=
ent&#39;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;theoreticia=
n&#39;).should =3D=3D 5<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;promiscuity=
&#39;).should =3D=3D 5<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;unbutlering=
&#39;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;continuity&=
#39;).should =3D=3D 5<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;craunched&#=
39;).should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;squelched&#=
39;).should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;scrounge&#3=
9;).should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;coughed&#39=
;).should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;smile&#39;)=
.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;monopoly&#3=
9;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;doughey&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;doughier&#3=
9;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;leguminous&=
#39;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;thoroughbre=
ds&#39;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;special&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;delicious&#=
39;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;spatial&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;pacifism&#3=
9;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;coagulant&#=
39;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;shouldn\&#3=
9;t&#39;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;mcdonald&#3=
9;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;audience&#3=
9;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;finance&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;prevalence&=
#39;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;impropriety=
&#39;).should =3D=3D 5<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;alien&#39;)=
.should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;dreadnought=
&#39;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;verandah&#3=
9;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;similar&#39=
;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;similarly&#=
39;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;central&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;cyst&#39;).=
should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;term&#39;).=
should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;order&#39;)=
.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;fur&#39;).s=
hould =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;sugar&#39;)=
.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;paper&#39;)=
.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;make&#39;).=
should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;gem&#39;).s=
hould =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;program&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;hopeless&#3=
9;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;hopelessly&=
#39;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;careful&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;carefully&#=
39;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;stuffy&#39;=
).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;thistle&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;teacher&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;unhappy&#39=
;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;ambiguity&#=
39;).should =3D=3D 5<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;validity&#3=
9;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;ambiguous&#=
39;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;deserve&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;blooper&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;scooped&#39=
;).should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;deserve&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;deal&#39;).=
should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;death&#39;)=
.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;dearth&#39;=
).should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;deign&#39;)=
.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;reign&#39;)=
.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;bedsore&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;anorexia&#3=
9;).should =3D=3D 5<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;anymore&#39=
;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;cored&#39;)=
.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;sore&#39;).=
should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;foremost&#3=
9;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;restore&#39=
;).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;minute&#39;=
).should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;manticores&=
#39;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;asparagus&#=
39;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;unexplored&=
#39;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;unexploded&=
#39;).should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;@readability_blank.syllable_count(&#39;CAPITALS&#3=
9;).should =3D=3D 3<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should calculate average syllables per word&quot=
; do<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;and then there was<br>
&gt; one&#39;).average_syllables_per_word.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;because special ducklings des=
erve<br>
&gt; rainbows&#39;).average_syllables_per_word.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;and then there was one becaus=
e special<br>
&gt; ducklings deserve rainbows&#39;).average_syllables_per_word.should =3D=
=3D<br>
&gt; 1.5<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should count words correctly&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;The quick brown fox jumped ov=
er the lazy<br>
&gt; dog&#39;).word_count.should =3D=3D 9<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;The quick brown fox jumped ov=
er the lazy<br>
&gt; dog.&#39;).word_count.should =3D=3D 9<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;The quick brown fox jumped ov=
er the lazy dog.<br>
&gt; &#39;).word_count.should =3D=3D 9<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39; The quick brown fox jumped o=
ver the lazy dog.<br>
&gt; &#39;).word_count.should =3D=3D 9<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39; The &nbsp;quick brown fox ju=
mped over the lazy dog.<br>
&gt; &#39;).word_count.should =3D=3D 9<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;Yes. No.&#39;).word_count.sho=
uld =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;Yes.No.&#39;).word_count.shou=
ld =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;Yes.No.&#39;).word_count.shou=
ld =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;Yes . No.&#39;).word_count.sh=
ould =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;Yes - No. &#39;).word_count.s=
hould =3D=3D 2<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should get percentage of words with three syllab=
les&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;there is just one word with t=
hree syllables in<br>
&gt; this sentence&#39;).percentage_words_with_three_syllables.round.should=
 =3D=3D<br>
&gt; 9<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;there are no valid words with=
 three Syllables<br>
&gt; in this sentence&#39;).percentage_words_with_three_syllables.round.sho=
uld<br>
&gt; =3D=3D 9<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;there is one and only one wor=
d with three or<br>
&gt; more syllables in this long boring sentence of twenty<br>
&gt; words&#39;).percentage_words_with_three_syllables.round.should =3D=3D =
5<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;there are two and only two wo=
rds with three or<br>
&gt; more syllables in this long sentence of exactly twenty<br>
&gt; words&#39;).percentage_words_with_three_syllables.round.should =3D=3D =
10<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;there is Actually only one va=
lid word with<br>
&gt; three or more syllables in this long sentence of Exactly twenty<br>
&gt; words&#39;).percentage_words_with_three_syllables(false).round.should =
=3D=3D 5<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;no long words in this<br>
&gt; sentence&#39;).percentage_words_with_three_syllables.round.should =3D=
=3D 0<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;no long valid words in this s=
entence because<br>
&gt; the test ignores proper case words like this<br>
&gt; Behemoth&#39;).percentage_words_with_three_syllables(false).round.shou=
ld<br>
&gt; =3D=3D 0<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should count letters&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;a&#39;).letter_count.should =
=3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;&#39;).letter_count.should =
=3D=3D 0<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;this sentence has 30 characte=
rs, not including<br>
&gt; the digits&#39;).letter_count.should =3D=3D 46<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should count sentences&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence&#39;).sent=
ence_count.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence.&#39;).sen=
tence_count.should =3D=3D<br>
&gt; 1<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence!&#39;).sen=
tence_count.should =3D=3D<br>
&gt; 1<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence?&#39;).sen=
tence_count.should =3D=3D<br>
&gt; 1<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence..&#39;).se=
ntence_count.should =3D=3D<br>
&gt; 1<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence. So is<br>
&gt; this.&#39;).sentence_count.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&quot;This is a sentence. \n\n So =
is this, but this<br>
&gt; is multi-line!&quot;).sentence_count.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence,. So is<br=
>
&gt; this.&#39;).sentence_count.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence!? So is<br=
>
&gt; this.&#39;).sentence_count.should =3D=3D 2<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence. So is thi=
s. And this one as<br>
&gt; well.&#39;).sentence_count.should =3D=3D 3<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence - but just=
<br>
&gt; one.&#39;).sentence_count.should =3D=3D 1<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence (but just<=
br>
&gt; one).&#39;).sentence_count.should =3D=3D 1<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;it &quot;should calculate average words per sentence&quot=
; do<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a<br>
&gt; sentence&#39;).average_words_per_sentence.should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a<br>
&gt; sentence.&#39;).average_words_per_sentence.should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence.<br>
&gt; &#39;).average_words_per_sentence.should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence. This is a=
<br>
&gt; sentence&#39;).average_words_per_sentence.should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence. This is a=
<br>
&gt; sentence.&#39;).average_words_per_sentence.should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This, is - a sentence . This =
is a sentence.<br>
&gt; &#39;).average_words_per_sentence.should =3D=3D 4<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence with extra=
 text. This is a<br>
&gt; sentence. &#39;).average_words_per_sentence.should =3D=3D 5.5<br>
&gt; &nbsp; &nbsp; &nbsp;Readability.new(&#39;This is a sentence with some =
extra text. This<br>
&gt; is a sentence. &#39;).average_words_per_sentence.should =3D=3D 6<br>
&gt; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp;describe &quot;test indices directly&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp;before(:each) do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;@str_a =3D &#39;This. Is. A. Nice. Set. Of.=
 Small. Words. Of. One.<br>
&gt; Part. Each.&#39;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;@str_b =3D &#39;The quick brown fox jumped =
over the lazy dog.&#39;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;@str_c =3D &#39;The quick brown fox jumped =
over the lazy dog. The<br>
&gt; quick brown fox jumped over the lazy dog.&#39;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;@str_d =3D &quot;The quick brown fox jumped=
 over the lazy dog. \n\n<br>
&gt; The quick brown fox jumped over the lazy dog.&quot;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;@str_e =3D &#39;The quick brown fox jumped =
over the lazy dog. The<br>
&gt; quick brown fox jumped over the lazy dog&#39;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;@str_f =3D &#39;Now it is time for a more c=
omplicated sentence,<br>
&gt; including several longer words.&#39;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;@str_g =3D &#39;Now it is time for a more C=
omplicated sentence,<br>
&gt; including Several longer words.&#39;<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;it &quot;should calculate flesch-kincaid reading e=
ase&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_a).flesch_kincaid_read=
ing_ease.should =3D=3D<br>
&gt; 121.2<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_b).flesch_kincaid_read=
ing_ease.should =3D=3D<br>
&gt; 94.3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_c).flesch_kincaid_read=
ing_ease.should =3D=3D<br>
&gt; 94.3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_d).flesch_kincaid_read=
ing_ease.should =3D=3D<br>
&gt; 94.3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_e).flesch_kincaid_read=
ing_ease.should =3D=3D<br>
&gt; 94.3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_f).flesch_kincaid_read=
ing_ease.should =3D=3D<br>
&gt; 50.5<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;it &quot;should calculate flesch-kincaid grade lev=
el&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_a).flesch_kincaid_grad=
e_level.should =3D=3D<br>
&gt; -3.4<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_b).flesch_kincaid_grad=
e_level.should =3D=3D<br>
&gt; 2.3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_c).flesch_kincaid_grad=
e_level.should =3D=3D<br>
&gt; 2.3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_d).flesch_kincaid_grad=
e_level.should =3D=3D<br>
&gt; 2.3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_e).flesch_kincaid_grad=
e_level.should =3D=3D<br>
&gt; 2.3<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_f).flesch_kincaid_grad=
e_level.should =3D=3D<br>
&gt; 9.4<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;it &quot;should calculate Gunning-Fog Score&quot; =
do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_a).gunning_fog_score.s=
hould =3D=3D 0.4<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_b).gunning_fog_score.s=
hould =3D=3D 3.6<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_c).gunning_fog_score.s=
hould =3D=3D 3.6<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_d).gunning_fog_score.s=
hould =3D=3D 3.6<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_e).gunning_fog_score.s=
hould =3D=3D 3.6<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_f).gunning_fog_score.s=
hould =3D=3D 14.4<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_g).gunning_fog_score.s=
hould =3D=3D 8.3<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;it &quot;should calculate coleman-liau index&quot;=
 do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_a).coleman_liau_index.=
should =3D=3D 3.0<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_b).coleman_liau_index.=
should =3D=3D 7.7<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_c).coleman_liau_index.=
should =3D=3D 7.7<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_d).coleman_liau_index.=
should =3D=3D 7.7<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_e).coleman_liau_index.=
should =3D=3D 7.7<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_f).coleman_liau_index.=
should =3D=3D<br>
&gt; 13.6<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;it &quot;should calculate smog index&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_a).smog_index.should =
=3D=3D 1.8<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_b).smog_index.should =
=3D=3D 1.8<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_c).smog_index.should =
=3D=3D 1.8<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_d).smog_index.should =
=3D=3D 1.8<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_e).smog_index.should =
=3D=3D 1.8<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_f).smog_index.should =
=3D=3D<br>
&gt; 10.1<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;it &quot;should calculate automated readability in=
dex&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_a).automated_readabili=
ty_index.should =3D=3D<br>
&gt; -5.6<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_b).automated_readabili=
ty_index.should =3D=3D<br>
&gt; 1.9<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_c).automated_readabili=
ty_index.should =3D=3D<br>
&gt; 1.9<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_d).automated_readabili=
ty_index.should =3D=3D<br>
&gt; 1.9<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_e).automated_readabili=
ty_index.should =3D=3D<br>
&gt; 1.9<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;Readability.new(@str_f).automated_readabili=
ty_index.should =3D=3D<br>
&gt; 8.6<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;it &quot;should index first paragraph of Moby Dick=
 correctly&quot; do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;str =3D&lt;&lt;-ENDL<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Call me Ishmael. Some years ago - ne=
ver mind how long<br>
&gt; precisely - having little or no money in my purse, and<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nothing particular to interest me on=
 shore, I thought I<br>
&gt; would sail about a little and see the watery part of<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;the world. It is a way I have of dri=
ving off the spleen, and<br>
&gt; regulating the circulation. Whenever I find myself<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;growing grim about the mouth; whenev=
er it is a damp, drizzly<br>
&gt; November in my soul; whenever I find myself<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;involuntarily pausing before coffin =
warehouses, and bringing<br>
&gt; up the rear of every funeral I meet; and especially<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;whenever my hypos get such an upper =
hand of me, that it<br>
&gt; requires a strong moral principle to prevent me from<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deliberately stepping into the stree=
t, and methodically<br>
&gt; knocking people&#39;s hats off - then, I account it high time<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;to get to sea as soon as I can. This=
 is my substitute for<br>
&gt; pistol and ball. With a philosophical flourish Cato<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throws himself upon his sword; I qui=
etly take to the ship.<br>
&gt; There is nothing surprising in this. If they but knew<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;it, almost all men in their degree, =
some time or other,<br>
&gt; cherish very nearly the same feelings towards the ocean with me.<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;ENDL<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability =3D Readability.new(str)<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.letter_count.should =3D=3D 884<=
br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.word_count.should =3D=3D 201<br=
>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.total_syllables.should =3D=3D 3=
04<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.sentence_count.should =3D=3D 8<=
br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.words_with_three_syllables.shou=
ld =3D=3D 23<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.flesch_kincaid_grade_level.shou=
ld =3D=3D 12.1<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.flesch_kincaid_reading_ease.sho=
uld =3D=3D 53.4<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.gunning_fog_score.should =3D=3D=
 14.2<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.coleman_liau_index.should =3D=
=3D 10.1<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.smog_index.should =3D=3D 8.9<br=
>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.automated_readability_index.sho=
uld =3D=3D 11.8<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;it &quot;should index a Kipling poem correctly&quo=
t; do<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;str =3D&lt;&lt;-ENDL<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can keep your head when all a=
bout you<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Are losing theirs and blaming it on =
you,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can trust yourself when all m=
en doubt you<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;But make allowance for their doubtin=
g too,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can wait and not be tired by =
waiting,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Or being lied about, don&#39;t deal =
in lies,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Or being hated, don&#39;t give way t=
o hating,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;And yet don&#39;t look too good, nor=
 talk too wise:<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can dream - and not make drea=
ms your master,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can think - and not make thou=
ghts your aim;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can meet with Triumph and Dis=
aster<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;And treat those two impostors just t=
he same;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can bear to hear the truth yo=
u&#39;ve spoken<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Twisted by knaves to make a trap for=
 fools,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Or watch the things you gave your li=
fe to, broken,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;And stoop and build &#39;em up with =
worn-out tools:<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can make one heap of all your=
 winnings<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;And risk it all on one turn of pitch=
-and-toss,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;And lose, and start again at your be=
ginnings<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;And never breath a word about your l=
oss;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can force your heart and nerv=
e and sinew<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;To serve your turn long after they a=
re gone,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;And so hold on when there is nothing=
 in you<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Except the Will which says to them: =
&quot;Hold on&quot;<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can talk with crowds and keep=
 your virtue,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Or walk with kings - nor lose the co=
mmon touch,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If neither foes nor loving friends c=
an hurt you;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If all men count with you, but none =
too much,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If you can fill the unforgiving minu=
te<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;With sixty seconds&#39; worth of dis=
tance run,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Yours is the Earth and everything th=
at&#39;s in it,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;And - which is more - you&#39;ll be =
a Man, my son<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;ENDL<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability =3D Readability.new(str)<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.letter_count.should =3D=3D 1125=
<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.word_count.should =3D=3D 292<br=
>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.total_syllables.should =3D=3D 3=
38<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.sentence_count.should =3D=3D 1<=
br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.words_with_three_syllables.shou=
ld =3D=3D 6<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.flesch_kincaid_grade_level.shou=
ld =3D=3D 111.9<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.flesch_kincaid_reading_ease.sho=
uld =3D=3D -187.5<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.gunning_fog_score.should =3D=3D=
 117.5<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.coleman_liau_index.should =3D=
=3D 6.9<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.smog_index.should =3D=3D 14.1<b=
r>
&gt; &nbsp; &nbsp; &nbsp; &nbsp;readability.automated_readability_index.sho=
uld =3D=3D 142.7<br>
&gt; &nbsp; &nbsp; &nbsp;end<br>
&gt; &nbsp; &nbsp;end<br>
&gt; &nbsp;end<br>
&gt;<br>
&gt; &gt;<br>
&gt;<br>
<br>
<br>
</div></div></blockquote></div><br>

------=_Part_245913_5335230.1231353997326--


Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google