odyssey 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/formulas/{formula.rb → _formula.rb} +6 -2
- data/lib/formulas/ari.rb +11 -1
- data/lib/formulas/coleman_liau.rb +10 -1
- data/lib/formulas/fake_formula.rb +5 -1
- data/lib/formulas/flesch_kincaid_gl.rb +11 -1
- data/lib/formulas/flesch_kincaid_re.rb +10 -1
- data/lib/formulas/gunning_fog.rb +11 -1
- data/lib/formulas/smog.rb +10 -1
- data/lib/odyssey.rb +2 -2
- data/lib/odyssey/engine.rb +53 -0
- data/lib/odyssey/version.rb +1 -1
- data/odyssey.gemspec +7 -7
- metadata +23 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d1fb3f77a3fa0deeb56730cde4d76909cd1dcad
|
4
|
+
data.tar.gz: 6bc10bc82cf9665f760eea3c71e6337d69187924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 506c2480075aa8ba7c415cd556ca934b4c9d39eb5490513495c3b9cb8832b2d1dbaadaa9081d3a992582f6039280fe993785883b3dcbfc2254a2dbec4e8f1d80
|
7
|
+
data.tar.gz: 35d1c55e66c12f547c381586d7d8ff1140ccb25e040208aff1bf237ec90fc594eb11a232ec34f4d9c0f7a707e263923eb8592a90dae7da46b2e5a920dd03aeef
|
data/README.md
CHANGED
@@ -70,7 +70,7 @@ if all_stats is true, this returns a Hash, similar to the Hash above:
|
|
70
70
|
'average_syllables_per_word' => Float
|
71
71
|
}
|
72
72
|
|
73
|
-
##Extending Odyssey
|
73
|
+
## Extending Odyssey
|
74
74
|
|
75
75
|
To extend Odyssey, you can create a class that inherits from Formula.
|
76
76
|
|
@@ -107,11 +107,11 @@ stats will be a Hash like so:
|
|
107
107
|
}
|
108
108
|
|
109
109
|
That is all you need.
|
110
|
-
To call your formula you just use
|
110
|
+
To call your formula you just use
|
111
111
|
|
112
112
|
Odyssey.cool_new_formula('See Spot run.', true)
|
113
113
|
|
114
|
-
Because you have access to the formula's class (when the
|
114
|
+
Because you have access to the formula's class (when the `all_stats` flag is true),
|
115
115
|
you have access to any other methods or class variables.
|
116
116
|
|
117
117
|
## Contributing
|
@@ -7,7 +7,7 @@ class Formula
|
|
7
7
|
# 'sentences' => Array,
|
8
8
|
# 'syllables' => Array
|
9
9
|
# }
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# stats will be a Hash like so:
|
12
12
|
# {
|
13
13
|
# 'string_length' => Fixnum,
|
@@ -23,7 +23,11 @@ class Formula
|
|
23
23
|
0
|
24
24
|
end
|
25
25
|
|
26
|
+
def score_by_sentence(text, stats_split)
|
27
|
+
0
|
28
|
+
end
|
29
|
+
|
26
30
|
def name
|
27
31
|
'Generic'
|
28
32
|
end
|
29
|
-
end
|
33
|
+
end
|
data/lib/formulas/ari.rb
CHANGED
@@ -4,6 +4,16 @@ class Ari < Formula
|
|
4
4
|
calc_score(stats['letter_count'], stats['word_count'], stats['sentence_count'])
|
5
5
|
end
|
6
6
|
|
7
|
+
def score_by_sentence(text, stats_split)
|
8
|
+
res = []
|
9
|
+
for i in 0..text['sentences'].length-1
|
10
|
+
res.push(calc_score(stats_split['letter_count'][i],
|
11
|
+
stats_split['word_count'][i],
|
12
|
+
1))
|
13
|
+
end
|
14
|
+
res
|
15
|
+
end
|
16
|
+
|
7
17
|
def calc_score(letter_count, word_count, sentence_count)
|
8
18
|
(((4.71 * (letter_count.to_f / word_count.to_f)) + (0.5 * (word_count.to_f / sentence_count.to_f))) - 21.43).round(1)
|
9
19
|
end
|
@@ -11,4 +21,4 @@ class Ari < Formula
|
|
11
21
|
def name
|
12
22
|
'Automated Readability Index'
|
13
23
|
end
|
14
|
-
end
|
24
|
+
end
|
@@ -4,6 +4,15 @@ class ColemanLiau < Formula
|
|
4
4
|
calc_score(stats['letter_count'], stats['word_count'], stats['sentence_count'])
|
5
5
|
end
|
6
6
|
|
7
|
+
def score_by_sentence(text, stats_split)
|
8
|
+
res = []
|
9
|
+
for i in 0..text['sentences'].length-1
|
10
|
+
res.push(calc_score(stats_split['letter_count'][i],
|
11
|
+
stats_split['word_count'][i],
|
12
|
+
1))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
7
16
|
def calc_score(letter_count, word_count, sentence_count)
|
8
17
|
((5.89 * (letter_count.to_f / word_count.to_f)) - (0.3 * (sentence_count.to_f / word_count.to_f)) - 15.8).round(1)
|
9
18
|
end
|
@@ -11,4 +20,4 @@ class ColemanLiau < Formula
|
|
11
20
|
def name
|
12
21
|
'Coleman-Liau Index'
|
13
22
|
end
|
14
|
-
end
|
23
|
+
end
|
@@ -4,6 +4,16 @@ class FleschKincaidGl < Formula
|
|
4
4
|
calc_score(stats['average_words_per_sentence'], stats['average_syllables_per_word'])
|
5
5
|
end
|
6
6
|
|
7
|
+
def score_by_sentence(text, stats_split)
|
8
|
+
res = []
|
9
|
+
for i in 0..text['sentences'].length-1
|
10
|
+
res.push(calc_score(stats_split['word_count'][i],
|
11
|
+
stats_split['average_syllables_per_word'][i]))
|
12
|
+
end
|
13
|
+
res
|
14
|
+
end
|
15
|
+
|
16
|
+
|
7
17
|
def calc_score(avg_words, avg_syllables)
|
8
18
|
(((0.39 * avg_words) + (11.8 * avg_syllables)) - 15.59).round(1)
|
9
19
|
end
|
@@ -11,4 +21,4 @@ class FleschKincaidGl < Formula
|
|
11
21
|
def name
|
12
22
|
'Flesch-Kincaid Grade Level'
|
13
23
|
end
|
14
|
-
end
|
24
|
+
end
|
@@ -4,6 +4,15 @@ class FleschKincaidRe < Formula
|
|
4
4
|
calc_score(stats['average_words_per_sentence'], stats['average_syllables_per_word'])
|
5
5
|
end
|
6
6
|
|
7
|
+
def score_by_sentence(text, stats_split)
|
8
|
+
res = []
|
9
|
+
for i in 0..text['sentences'].length-1
|
10
|
+
res.push(calc_score(stats_split['word_count'][i],
|
11
|
+
stats_split['average_syllables_per_word'][i]))
|
12
|
+
end
|
13
|
+
res
|
14
|
+
end
|
15
|
+
|
7
16
|
def calc_score(avg_words, avg_syllables)
|
8
17
|
((206.835 - (1.015 * avg_words)) - (84.6 * avg_syllables)).round(1)
|
9
18
|
end
|
@@ -11,4 +20,4 @@ class FleschKincaidRe < Formula
|
|
11
20
|
def name
|
12
21
|
'Flesch-Kincaid Reading Ease'
|
13
22
|
end
|
14
|
-
end
|
23
|
+
end
|
data/lib/formulas/gunning_fog.rb
CHANGED
@@ -5,6 +5,16 @@ class GunningFog < Formula
|
|
5
5
|
calc_score(stats['average_words_per_sentence'], percent)
|
6
6
|
end
|
7
7
|
|
8
|
+
def score_per_sentence(text, stats_split)
|
9
|
+
res = []
|
10
|
+
for i in 0..text['sentences'].length-1
|
11
|
+
percent = three_syllables(stats_split['word_count'][i],
|
12
|
+
text['syllables_by_sentence'][i])
|
13
|
+
res.push(calc_score(stats_split['word_count'][i], percent))
|
14
|
+
end
|
15
|
+
res
|
16
|
+
end
|
17
|
+
|
8
18
|
#percentage of words with three syllables
|
9
19
|
def three_syllables(word_count, syllables)
|
10
20
|
with_three = 0
|
@@ -21,4 +31,4 @@ class GunningFog < Formula
|
|
21
31
|
def name
|
22
32
|
'Gunning-Fog Score'
|
23
33
|
end
|
24
|
-
end
|
34
|
+
end
|
data/lib/formulas/smog.rb
CHANGED
@@ -5,6 +5,15 @@ class Smog < Formula
|
|
5
5
|
calc_score(stats['sentence_count'], with_three)
|
6
6
|
end
|
7
7
|
|
8
|
+
def score_per_sentence(text, stats_split)
|
9
|
+
res = []
|
10
|
+
for i in 0..text['sentences'].length-1
|
11
|
+
with_three = three_syllables(text['syllables_per_sentence'][i])
|
12
|
+
res.push(calc_score(1, with_three))
|
13
|
+
end
|
14
|
+
res
|
15
|
+
end
|
16
|
+
|
8
17
|
def three_syllables(syllables)
|
9
18
|
with_three = 0
|
10
19
|
syllables.each do |s|
|
@@ -20,4 +29,4 @@ class Smog < Formula
|
|
20
29
|
def name
|
21
30
|
'SMOG Index'
|
22
31
|
end
|
23
|
-
end
|
32
|
+
end
|
data/lib/odyssey.rb
CHANGED
@@ -7,10 +7,10 @@ module Odyssey
|
|
7
7
|
#main method
|
8
8
|
def self.analyze(text, formula_name = DEFAULT_FORMULA, all_stats = false)
|
9
9
|
formula_name ||= DEFAULT_FORMULA
|
10
|
-
|
10
|
+
|
11
11
|
@engine = Odyssey::Engine.new(formula_name)
|
12
12
|
score = @engine.score(text)
|
13
|
-
|
13
|
+
|
14
14
|
#return all stats?
|
15
15
|
if all_stats
|
16
16
|
output = @engine.get_stats
|
data/lib/odyssey/engine.rb
CHANGED
@@ -4,10 +4,12 @@ module Odyssey
|
|
4
4
|
#instance variables
|
5
5
|
@formula
|
6
6
|
@score
|
7
|
+
@score_by_sentence
|
7
8
|
@stats
|
8
9
|
@words
|
9
10
|
@sentences
|
10
11
|
@syllables
|
12
|
+
@syllables_by_sentence
|
11
13
|
@data
|
12
14
|
|
13
15
|
#regex
|
@@ -57,9 +59,21 @@ module Odyssey
|
|
57
59
|
'sentences' => @sentences,
|
58
60
|
'syllables' => @syllables
|
59
61
|
}
|
62
|
+
@data['words_per_sentence'] = words_by_sentence()
|
63
|
+
@data['syllables_per_sentence'] = syllables_by_sentence(@sentences)
|
64
|
+
|
65
|
+
@stats_by_sentence = {
|
66
|
+
'string_length' => @sentences.map { |a| string_length(a) },
|
67
|
+
'letter_count' => @sentences.map { |a| letter_count(a) },
|
68
|
+
'word_count' => @sentences.map { |a| word_count(a) },
|
69
|
+
'syllable_count' => @sentences.map { |a| syllable_count(a) },
|
70
|
+
'sentence_count' => Array.new(@sentences.length, 1),
|
71
|
+
}
|
72
|
+
@stats_by_sentence['average_syllables_per_word'] = average_syllables_per_word_per_sentence(text)
|
60
73
|
end
|
61
74
|
|
62
75
|
#now run all that through the formula
|
76
|
+
@score_by_sentence = @formula.score_by_sentence(@data, @stats_by_sentence)
|
63
77
|
@score = @formula.score(@data, @stats)
|
64
78
|
end
|
65
79
|
|
@@ -82,11 +96,28 @@ module Odyssey
|
|
82
96
|
count
|
83
97
|
end
|
84
98
|
|
99
|
+
def syllables_by_sentence(words)
|
100
|
+
res = []
|
101
|
+
words.each do |w|
|
102
|
+
num = analyze_syllables(w)
|
103
|
+
res << num
|
104
|
+
end
|
105
|
+
res
|
106
|
+
end
|
107
|
+
|
85
108
|
def word_count(text)
|
86
109
|
@words = text.scan WORD_REGEX
|
87
110
|
@words.size
|
88
111
|
end
|
89
112
|
|
113
|
+
def words_by_sentence()
|
114
|
+
res = []
|
115
|
+
for i in 0..@sentences.length-1
|
116
|
+
res.push(@sentences[i].scan WORD_REGEX)
|
117
|
+
end
|
118
|
+
res
|
119
|
+
end
|
120
|
+
|
90
121
|
def sentence_count(text)
|
91
122
|
@sentences = text.scan SENTENCE_REGEX
|
92
123
|
@sentences.size
|
@@ -100,6 +131,14 @@ module Odyssey
|
|
100
131
|
@stats['syllable_count'].to_f / @stats['word_count'].to_f
|
101
132
|
end
|
102
133
|
|
134
|
+
def average_syllables_per_word_per_sentence(text)
|
135
|
+
res = []
|
136
|
+
for i in 0..@stats_by_sentence['string_length'].length-1
|
137
|
+
res.push(@stats_by_sentence['syllable_count'][i].to_f / @stats_by_sentence['word_count'][i].to_f)
|
138
|
+
end
|
139
|
+
res
|
140
|
+
end
|
141
|
+
|
103
142
|
# for now this just removes html tags
|
104
143
|
# but it could do more in the future
|
105
144
|
def sanitize(text)
|
@@ -139,13 +178,27 @@ module Odyssey
|
|
139
178
|
all_stats['name'] = @formula.name
|
140
179
|
all_stats['formula'] = @formula
|
141
180
|
all_stats['score'] = @score
|
181
|
+
all_stats['score_by_sentence'] = merge_scores_with_sentences()
|
142
182
|
end
|
143
183
|
all_stats
|
144
184
|
end
|
145
185
|
|
186
|
+
def merge_scores_with_sentences()
|
187
|
+
res = []
|
188
|
+
ro = Struct.new(:score, :sentence)
|
189
|
+
for i in 0..@score_by_sentence.length-1
|
190
|
+
r = ro.new
|
191
|
+
r.sentence = @sentences[i]
|
192
|
+
r.score = @score_by_sentence[i]
|
193
|
+
res.push(r)
|
194
|
+
end
|
195
|
+
res
|
196
|
+
end
|
197
|
+
|
146
198
|
def reset
|
147
199
|
@formula = nil
|
148
200
|
@score = 0
|
201
|
+
@score_by_sentence = []
|
149
202
|
@stats = {}
|
150
203
|
@words = nil
|
151
204
|
@sentences = nil
|
data/lib/odyssey/version.rb
CHANGED
data/odyssey.gemspec
CHANGED
@@ -6,14 +6,14 @@ require 'odyssey/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "odyssey"
|
8
8
|
spec.version = Odyssey::VERSION
|
9
|
-
spec.authors = ["Cameron Sutter"]
|
10
|
-
spec.email = ["cameronsutter0@gmail.com"]
|
9
|
+
spec.authors = ["Cameron Sutter", "Michael Lahnert", "Daniel Jethro"]
|
10
|
+
spec.email = ["cameronsutter0@gmail.com", "", "jethrodaniel@gmail.com"]
|
11
11
|
spec.description = %q{Odyssey is an extendible text analyzing gem that outputs the readability score of text. It has several of the common readability formulas available, but defaults to the Flesch-Kincaid Reading Ease score.}
|
12
12
|
spec.summary = %q{Text readability analyzer using Flesch-Kincaid and others}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/cameronsutter/odyssey"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.add_dependency "require_all"
|
16
|
+
spec.add_dependency "require_all", "~> 2.0"
|
17
17
|
|
18
18
|
spec.files = `git ls-files`.split($/)
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
-
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.1.0"
|
26
|
-
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "rake", "~> 0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.1", ">= 3.1.0"
|
26
|
+
spec.add_development_dependency "pry", "~> 0"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,29 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odyssey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Sutter
|
8
|
+
- Michael Lahnert
|
9
|
+
- Daniel Jethro
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2019-07-31 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: require_all
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
16
18
|
requirements:
|
17
|
-
- - "
|
19
|
+
- - "~>"
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
21
|
+
version: '2.0'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- - "
|
26
|
+
- - "~>"
|
25
27
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
28
|
+
version: '2.0'
|
27
29
|
- !ruby/object:Gem::Dependency
|
28
30
|
name: bundler
|
29
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,14 +44,14 @@ dependencies:
|
|
42
44
|
name: rake
|
43
45
|
requirement: !ruby/object:Gem::Requirement
|
44
46
|
requirements:
|
45
|
-
- - "
|
47
|
+
- - "~>"
|
46
48
|
- !ruby/object:Gem::Version
|
47
49
|
version: '0'
|
48
50
|
type: :development
|
49
51
|
prerelease: false
|
50
52
|
version_requirements: !ruby/object:Gem::Requirement
|
51
53
|
requirements:
|
52
|
-
- - "
|
54
|
+
- - "~>"
|
53
55
|
- !ruby/object:Gem::Version
|
54
56
|
version: '0'
|
55
57
|
- !ruby/object:Gem::Dependency
|
@@ -57,6 +59,9 @@ dependencies:
|
|
57
59
|
requirement: !ruby/object:Gem::Requirement
|
58
60
|
requirements:
|
59
61
|
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.1'
|
64
|
+
- - ">="
|
60
65
|
- !ruby/object:Gem::Version
|
61
66
|
version: 3.1.0
|
62
67
|
type: :development
|
@@ -64,20 +69,23 @@ dependencies:
|
|
64
69
|
version_requirements: !ruby/object:Gem::Requirement
|
65
70
|
requirements:
|
66
71
|
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '3.1'
|
74
|
+
- - ">="
|
67
75
|
- !ruby/object:Gem::Version
|
68
76
|
version: 3.1.0
|
69
77
|
- !ruby/object:Gem::Dependency
|
70
78
|
name: pry
|
71
79
|
requirement: !ruby/object:Gem::Requirement
|
72
80
|
requirements:
|
73
|
-
- - "
|
81
|
+
- - "~>"
|
74
82
|
- !ruby/object:Gem::Version
|
75
83
|
version: '0'
|
76
84
|
type: :development
|
77
85
|
prerelease: false
|
78
86
|
version_requirements: !ruby/object:Gem::Requirement
|
79
87
|
requirements:
|
80
|
-
- - "
|
88
|
+
- - "~>"
|
81
89
|
- !ruby/object:Gem::Version
|
82
90
|
version: '0'
|
83
91
|
description: Odyssey is an extendible text analyzing gem that outputs the readability
|
@@ -85,6 +93,8 @@ description: Odyssey is an extendible text analyzing gem that outputs the readab
|
|
85
93
|
defaults to the Flesch-Kincaid Reading Ease score.
|
86
94
|
email:
|
87
95
|
- cameronsutter0@gmail.com
|
96
|
+
- ''
|
97
|
+
- jethrodaniel@gmail.com
|
88
98
|
executables: []
|
89
99
|
extensions: []
|
90
100
|
extra_rdoc_files: []
|
@@ -94,12 +104,12 @@ files:
|
|
94
104
|
- LICENSE.txt
|
95
105
|
- README.md
|
96
106
|
- Rakefile
|
107
|
+
- lib/formulas/_formula.rb
|
97
108
|
- lib/formulas/ari.rb
|
98
109
|
- lib/formulas/coleman_liau.rb
|
99
110
|
- lib/formulas/fake_formula.rb
|
100
111
|
- lib/formulas/flesch_kincaid_gl.rb
|
101
112
|
- lib/formulas/flesch_kincaid_re.rb
|
102
|
-
- lib/formulas/formula.rb
|
103
113
|
- lib/formulas/gunning_fog.rb
|
104
114
|
- lib/formulas/smog.rb
|
105
115
|
- lib/odyssey.rb
|
@@ -108,7 +118,7 @@ files:
|
|
108
118
|
- odyssey.gemspec
|
109
119
|
- spec/odyssey_spec.rb
|
110
120
|
- spec/spec_helper.rb
|
111
|
-
homepage:
|
121
|
+
homepage: https://github.com/cameronsutter/odyssey
|
112
122
|
licenses:
|
113
123
|
- MIT
|
114
124
|
metadata: {}
|
@@ -128,11 +138,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
138
|
version: '0'
|
129
139
|
requirements: []
|
130
140
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.2.
|
141
|
+
rubygems_version: 2.5.2.3
|
132
142
|
signing_key:
|
133
143
|
specification_version: 4
|
134
144
|
summary: Text readability analyzer using Flesch-Kincaid and others
|
135
145
|
test_files:
|
136
146
|
- spec/odyssey_spec.rb
|
137
147
|
- spec/spec_helper.rb
|
138
|
-
has_rdoc:
|