syllabize 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/README.md +13 -0
- data/lib/exceptions.yml +5 -0
- data/lib/syllabize.rb +35 -4
- data/lib/syllabize/version.rb +1 -1
- data/spec/lib/syllabize_spec.rb +26 -1
- data/syllabize.gemspec +1 -1
- metadata +20 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 56788468c28095e3f88b10b704433da0986c5285
|
4
|
+
data.tar.gz: 93bd2460d2213bfd7ff39fe7e0becb8a2c4842b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce3e6a6143bfc887a6bc42015788b698568493bcf998cbfe83df01ea5e0b5249f4accacfbc9f1092907caad9728d1883a507c6ecd830b6afc0b4910acf606bea
|
7
|
+
data.tar.gz: 8c2106ac2bddf51e86070a367995d4f8fdc2f719cb4eae22a5922758b5a5eb390c33c30fe8de032f28fe92758cd0ed55c6a81b96d358a004a66ed586ed6afbc8
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
## 0.8.0
|
2
|
+
Correctly count words with single or multiple suffixes (purely, menacingly)
|
3
|
+
|
4
|
+
## 0.7.0
|
5
|
+
Correctly count words with syllabic and non-syllabic -ed suffix (herded vs worked)
|
6
|
+
- by [@catstavi](https://github.com/catstavi)
|
7
|
+
|
8
|
+
## 0.6.0
|
9
|
+
Support numbers and multiword strings
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Syllabize
|
2
2
|
|
3
|
+
[](https://codeclimate.com/github/thenickcox/syllabize)
|
4
|
+
|
3
5
|
Syllabize is a simple syllable counter written in Ruby.
|
4
6
|
|
5
7
|
## Installation
|
@@ -25,10 +27,21 @@ require 'syllabize'
|
|
25
27
|
# => true
|
26
28
|
'Ruby'.count_syllables
|
27
29
|
# => 2
|
30
|
+
'500'.count_syllables
|
31
|
+
# => 3
|
32
|
+
'this gem is cool'.count_syllables
|
33
|
+
# => 4
|
28
34
|
```
|
29
35
|
|
36
|
+
## Changes
|
37
|
+
See [changelog](https://github.com/thenickcox/syllabize/changelog.md).
|
38
|
+
|
30
39
|
## Contributing
|
31
40
|
|
41
|
+
### File an issue
|
42
|
+
The English language is full of exceptions to rules. One of the best ways to contribute is to [file an issue](https://github.com/thenickcox/syllabize/issues) with any exceptions you find.
|
43
|
+
|
44
|
+
### Hack on the gem
|
32
45
|
1. Fork it
|
33
46
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
47
|
3. Write tests and run them (`rake` or `rspec`)
|
data/lib/exceptions.yml
CHANGED
data/lib/syllabize.rb
CHANGED
@@ -10,6 +10,7 @@ module Syllabize
|
|
10
10
|
@str = strip_punctuation(str)
|
11
11
|
handle_non_string_input
|
12
12
|
load_exceptions
|
13
|
+
@syllables = 0
|
13
14
|
end
|
14
15
|
|
15
16
|
CONSONANTS = /[bcdfghjklmnpqrstvwxz]/i
|
@@ -18,12 +19,14 @@ module Syllabize
|
|
18
19
|
DIPHTHONGS = /ou|ie|io|oa|oo|oi|ea|ee|ai|ae|ay/i
|
19
20
|
Y_AS_VOWEL = /[^yY][yY]/
|
20
21
|
RE_VOWEL = /(^re[aeiou])/i
|
22
|
+
SUFFIXES = /(?<=.)(able|ible|al|ial|ed|en|er|est|ful|ic|ing|ion|ing|less|ly|ment|nes|ous)\z/
|
21
23
|
|
22
24
|
def count_syllables
|
23
25
|
@str = str.to_i.to_words if is_int_in_string_form?
|
24
26
|
return break_into_words if str.split(' ').length > 1
|
25
27
|
return handle_exceptions if exceptions.keys.include?(str)
|
26
|
-
|
28
|
+
count_suffixes if str.scan(SUFFIXES).any?
|
29
|
+
@syllables += count_vowels
|
27
30
|
handle_additions
|
28
31
|
handle_subtractions
|
29
32
|
@syllables <= 1 ? 1 : @syllables
|
@@ -31,12 +34,21 @@ module Syllabize
|
|
31
34
|
|
32
35
|
private
|
33
36
|
|
37
|
+
def count_suffixes
|
38
|
+
@syllables -= 1 if ends_in_non_syllablic_ed?
|
39
|
+
while str.scan(SUFFIXES).any?
|
40
|
+
suffix = str.scan(SUFFIXES).flatten.last
|
41
|
+
str.sub! /(?<=.)#{suffix}/, ''
|
42
|
+
@syllables += 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
34
46
|
def break_into_words
|
35
47
|
str.split(' ').collect(&:count_syllables).reduce(:+)
|
36
48
|
end
|
37
49
|
|
38
50
|
def strip_punctuation(string)
|
39
|
-
string.gsub(
|
51
|
+
string.gsub(/[[:punct:]]/,'')
|
40
52
|
end
|
41
53
|
|
42
54
|
def is_int_in_string_form?
|
@@ -62,7 +74,7 @@ module Syllabize
|
|
62
74
|
end
|
63
75
|
|
64
76
|
def handle_exceptions
|
65
|
-
exceptions[str
|
77
|
+
exceptions[str]
|
66
78
|
end
|
67
79
|
|
68
80
|
def handle_additions
|
@@ -82,7 +94,7 @@ module Syllabize
|
|
82
94
|
end
|
83
95
|
|
84
96
|
def ends_in_silent_e?
|
85
|
-
str.
|
97
|
+
str.end_with?('e')
|
86
98
|
end
|
87
99
|
|
88
100
|
def contains_le_vowel_sound?
|
@@ -113,6 +125,25 @@ module Syllabize
|
|
113
125
|
str.end_with?('sm')
|
114
126
|
end
|
115
127
|
|
128
|
+
def has_more_than_one_syllable?
|
129
|
+
(count_vowels - count_diphthongs) > 1
|
130
|
+
end
|
131
|
+
|
132
|
+
def ends_in_ed?
|
133
|
+
str.end_with?('ed')
|
134
|
+
end
|
135
|
+
|
136
|
+
def ending_ed_is_not_syllablic?
|
137
|
+
str.scan(/(t|d|tr|dr|tl|dl)ed\b/).empty?
|
138
|
+
end
|
139
|
+
|
140
|
+
def ends_in_non_syllablic_ed?
|
141
|
+
if has_more_than_one_syllable? && ends_in_ed? && ending_ed_is_not_syllablic?
|
142
|
+
true
|
143
|
+
else
|
144
|
+
false
|
145
|
+
end
|
146
|
+
end
|
116
147
|
|
117
148
|
# for Ruby 1.9
|
118
149
|
def __dir__
|
data/lib/syllabize/version.rb
CHANGED
data/spec/lib/syllabize_spec.rb
CHANGED
@@ -151,11 +151,37 @@ describe Syllabize::Counter do
|
|
151
151
|
'I really think so' => 5,
|
152
152
|
'500' => 3,
|
153
153
|
'1,000,000' => 3,
|
154
|
+
'Anne of' => 2,
|
155
|
+
'purely' => 2,
|
156
|
+
'menacingly' => 4,
|
154
157
|
}.each do |word, actual|
|
155
158
|
count = Syllabize::Counter.new(word).count_syllables
|
156
159
|
expect(count).to eq(actual), "'#{word}' was not the correct number of syllables; expected #{actual}, was #{count}"
|
157
160
|
end
|
158
161
|
end
|
162
|
+
|
163
|
+
context 'with suffix /ed/' do
|
164
|
+
context '/ed/ is after /t/, /d/, /tr/, /tl/, /dr/, /dl/' do
|
165
|
+
it 'counts /ed/ as a syllable' do
|
166
|
+
expect(Syllabize::Counter.new('herded').count_syllables).to eq(2)
|
167
|
+
expect(Syllabize::Counter.new('carted').count_syllables).to eq(2)
|
168
|
+
expect(Syllabize::Counter.new('hundred').count_syllables).to eq(2)
|
169
|
+
expect(Syllabize::Counter.new('hatred').count_syllables).to eq(2)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
context '/ed/ is after sounds unrelated to /t/ and /d/' do
|
173
|
+
it 'does not count /ed/ as a syllable' do
|
174
|
+
expect(Syllabize::Counter.new('worked').count_syllables).to eq(1)
|
175
|
+
expect(Syllabize::Counter.new('flapped').count_syllables).to eq(1)
|
176
|
+
expect(Syllabize::Counter.new('sneered').count_syllables).to eq(1)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
context '/ed/ is the only syllable of a word' do
|
180
|
+
it 'it does count /ed/ as a syllable' do
|
181
|
+
expect(Syllabize::Counter.new('bed').count_syllables).to eq(1)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
159
185
|
end
|
160
186
|
context 'other data' do
|
161
187
|
it 'raises an error' do
|
@@ -168,5 +194,4 @@ describe Syllabize::Counter do
|
|
168
194
|
subject { 'hello'.count_syllables }
|
169
195
|
it { should == 2 }
|
170
196
|
end
|
171
|
-
|
172
197
|
end
|
data/syllabize.gemspec
CHANGED
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.0"
|
24
24
|
spec.add_development_dependency "numbers_and_words"
|
25
25
|
end
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syllabize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.8.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- thenickcox
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.3'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.3'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
47
|
+
version: '2.0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
54
|
+
version: '2.0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: numbers_and_words
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: A syllable counter written in Ruby
|
@@ -82,7 +73,8 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
77
|
+
- CHANGELOG.md
|
86
78
|
- Gemfile
|
87
79
|
- LICENSE.txt
|
88
80
|
- README.md
|
@@ -96,28 +88,28 @@ files:
|
|
96
88
|
homepage: http://github.com/thenickcox/syllabize
|
97
89
|
licenses:
|
98
90
|
- MIT
|
91
|
+
metadata: {}
|
99
92
|
post_install_message:
|
100
93
|
rdoc_options: []
|
101
94
|
require_paths:
|
102
95
|
- lib
|
103
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
-
none: false
|
105
97
|
requirements:
|
106
|
-
- -
|
98
|
+
- - ">="
|
107
99
|
- !ruby/object:Gem::Version
|
108
100
|
version: '0'
|
109
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
102
|
requirements:
|
112
|
-
- -
|
103
|
+
- - ">="
|
113
104
|
- !ruby/object:Gem::Version
|
114
105
|
version: '0'
|
115
106
|
requirements: []
|
116
107
|
rubyforge_project:
|
117
|
-
rubygems_version:
|
108
|
+
rubygems_version: 2.2.2
|
118
109
|
signing_key:
|
119
|
-
specification_version:
|
110
|
+
specification_version: 4
|
120
111
|
summary: Syllabize counts the number of syllables in a gem
|
121
112
|
test_files:
|
122
113
|
- spec/lib/syllabize_spec.rb
|
123
114
|
- spec/spec_helper.rb
|
115
|
+
has_rdoc:
|