@@ -39,8 +39,8 @@ def self.avg_sentence_length(text)
3939 0.0
4040 end
4141
42- def self . avg_syllables_per_word ( text )
43- syllable = syllable_count ( text )
42+ def self . avg_syllables_per_word ( text , language = 'en_us' )
43+ syllable = syllable_count ( text , language )
4444 words = lexicon_count ( text )
4545 begin
4646 syllables_per_word = syllable . to_f / words
@@ -64,35 +64,35 @@ def self.avg_sentence_per_word(text)
6464 0.0
6565 end
6666
67- def self . flesch_reading_ease ( text )
67+ def self . flesch_reading_ease ( text , language = 'en_us' )
6868 sentence_length = avg_sentence_length ( text )
69- syllables_per_word = avg_syllables_per_word ( text )
69+ syllables_per_word = avg_syllables_per_word ( text , language )
7070 flesch = 206.835 - 1.015 * sentence_length - 84.6 * syllables_per_word
7171 flesch . round ( 2 )
7272 end
7373
74- def self . flesch_kincaid_grade ( text )
74+ def self . flesch_kincaid_grade ( text , language = 'en_us' )
7575 sentence_length = avg_sentence_length ( text )
76- syllables_per_word = avg_syllables_per_word ( text )
76+ syllables_per_word = avg_syllables_per_word ( text , language )
7777 flesch = 0.39 * sentence_length + 11.8 * syllables_per_word - 15.59
7878 flesch . round ( 1 )
7979 end
8080
81- def self . polysyllab_count ( text )
81+ def self . polysyllab_count ( text , language = 'en_us' )
8282 count = 0
8383 text . split ( ' ' ) . each do |word |
84- w = syllable_count ( word )
84+ w = syllable_count ( word , language )
8585 count += 1 if w >= 3
8686 end
8787 count
8888 end
8989
90- def self . smog_index ( text )
90+ def self . smog_index ( text , language = 'en_us' )
9191 sentences = sentence_count ( text )
9292
9393 if sentences >= 3
9494 begin
95- polysyllab = polysyllab_count ( text )
95+ polysyllab = polysyllab_count ( text , language )
9696 smog = 1.043 * Math . sqrt ( 30.0 * polysyllab / sentences ) + 3.1291
9797 smog . round ( 1 )
9898 rescue ZeroDivisionError
@@ -125,13 +125,13 @@ def self.automated_readability_index(text)
125125 end
126126 end
127127
128- def self . linsear_write_formula ( text )
128+ def self . linsear_write_formula ( text , language = 'en_us' )
129129 easy_word = 0
130130 difficult_word = 0
131131 text_list = text . split ( ' ' ) [ 0 ..100 ]
132132
133133 text_list . each do |word |
134- if syllable_count ( word ) < 3
134+ if syllable_count ( word , language ) < 3
135135 easy_word += 1
136136 else
137137 difficult_word += 1
@@ -157,14 +157,14 @@ def self.difficult_words(text, language = 'en_us')
157157 text_list . each do |value |
158158 next if easy_words . include? value
159159
160- diff_words_set . add ( value ) if syllable_count ( value ) > 1
160+ diff_words_set . add ( value ) if syllable_count ( value , language ) > 1
161161 end
162162 diff_words_set . length
163163 end
164164
165- def self . dale_chall_readability_score ( text )
165+ def self . dale_chall_readability_score ( text , language = 'en_us' )
166166 word_count = lexicon_count ( text )
167- count = word_count - difficult_words ( text )
167+ count = word_count - difficult_words ( text , language )
168168
169169 begin
170170 per = 100.0 * count / word_count
@@ -179,8 +179,8 @@ def self.dale_chall_readability_score(text)
179179 score . round ( 2 )
180180 end
181181
182- def self . gunning_fog ( text )
183- per_diff_words = 100.0 * difficult_words ( text ) / lexicon_count ( text ) + 5
182+ def self . gunning_fog ( text , language = 'en_us' )
183+ per_diff_words = 100.0 * difficult_words ( text , language ) / lexicon_count ( text ) + 5
184184 grade = 0.4 * ( avg_sentence_length ( text ) + per_diff_words )
185185
186186 grade . round ( 2 )
@@ -209,8 +209,8 @@ def self.forcast(text, language = 'en_us')
209209 forcast
210210 end
211211
212- def self . powers_sumner_kearl ( text )
213- grade = 0.0778 * avg_sentence_length ( text ) + 0.0455 * syllable_count ( text ) - 2.2029
212+ def self . powers_sumner_kearl ( text , language = 'en_us' )
213+ grade = 0.0778 * avg_sentence_length ( text ) + 0.0455 * syllable_count ( text , language ) - 2.2029
214214 grade . round ( 2 )
215215 end
216216
0 commit comments