syllable_counter 0.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTI2Njc1ODA3Yzk4Yzk5MGNkOGJkOTMyNjI5MmZjYTczZjgzOTIzMg==
5
+ data.tar.gz: !binary |-
6
+ NGZjZTFkMjhhODIwMGIwZjAxNTRkYTlhMzQxZDhmYmU2M2M1ZmRjOQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NjYwMTVkNjZhZTEwODljOTkyOTlkN2I1OTZmMjg2ZmY4ZThhODhiMjdhN2Zh
10
+ MjBjNzc1M2ZmYzAzNjI3ODI2N2UzMGJlMDhiMTM3N2M3OWU1ZDIyNTFmMWM3
11
+ MjEzYjcyMjFkYTg4OWNmMDAzNzNjY2UwZDgzNDRkNWU2NGRiN2I=
12
+ data.tar.gz: !binary |-
13
+ ODdiNWMzMTc4OTkxY2ZiYmVmMWEyZTBkYTFmZWNjMTMxNTI3MDljMmExZWJj
14
+ ZmY2MWVkMWViNDQ5MzU5Yjc3MWUzNDgzMjcwZTc3ZWExZmEyZjFjMmZiNmRm
15
+ Y2ZkZjQ0OWE5NmVkMDY5YWU5NjU4NjQxMTIwMzg1MzVhM2M1NTg=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kelsey Mok
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # SyllableCounter
2
+
3
+ Takes a string and returns the number of syllables.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'syllable_counter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install syllable_counter
18
+
19
+ ## Usage
20
+
21
+ To get the number of syllables for a string:
22
+
23
+ SyllableCounter.get_syllables("Text to be evaluated goes here")
24
+ #=> 10
25
+
26
+ ## Algorithm
27
+
28
+ The algorithm is not corpus-based but based upon
29
+ phonemic complementary distributions as they exist in American
30
+ English. This is an introductory set that will keep growing.
31
+ Suggestions for additions are absolutely welcome! Email me at kelseymok@gmail.com.
32
+
33
+ 1. Assumes at least one obligatory vowel per syllable
34
+ 2. Final /e/ is not realized unless the final /e/ is preceded by an /l/
35
+ or /r/ and a consonant (ie. -dle, -cre).
36
+ 3. Final /ed/ suffix is not realized when preceeded by a /t/ or
37
+ /d/
38
+ 4. Final /es/ plural suffix is realized after /s/ /z/ /sh/ /dg/ /ch/
39
+ /[aeiou]g/
40
+ 5. Two consecutive vowels outside of /[aeiouy]o/ are combined as one
41
+ syllable
42
+
43
+ Pending
44
+
45
+ 1. /[aeiuy]o/ does not get merged as one syllable (ie. aon, ion, eon)
46
+ 2. /iu/ combinations are two syllables
47
+ 2. Exceptions: "maybe", "Wednesday"
48
+ 3. Dialect-specific versions for English
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module SyllableCounter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require "syllable_counter/version"
2
+
3
+ module SyllableCounter
4
+ class << self
5
+ def get_syllables(string)
6
+ words = string.split()
7
+ count = 0
8
+ words.each do |word|
9
+ if word =~ /e$/
10
+ if word =~ /[aeiouy][lr]e$/ || word =~ /[^lr]e$/
11
+ word.sub!(/e$/,"")
12
+ end
13
+ end
14
+ word =~ /[^td]ed$/ ? word.sub!(/ed$/,"") : word
15
+ word =~ /(s||z||sh||dg||[aeiouy]g||ch)es$/ ? word.sub!(/ed$/,"") : word
16
+ word =~ /[aeiouy][aeiouy]/ ? word.sub!(/[aeiouy][aeiouy]/,"a") : word
17
+ vowel_count = word.scan(/[aeiouy]/).count
18
+ if vowel_count == 0
19
+ vowel_count = 1
20
+ end
21
+ count = count + vowel_count
22
+ end
23
+ return count
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'syllable_counter'
3
+
4
+ def configure_syllable_counter
5
+ Rspec.configure do |config|
6
+ end
7
+ end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Syllables" do
4
+ describe "#get_syllables" do
5
+ it "returns number of vowels" do
6
+ SyllableCounter.get_syllables("test").should == 1
7
+ end
8
+
9
+ context "has two vowels" do
10
+ it "returns 2" do
11
+ SyllableCounter.get_syllables("cabin").should == 2
12
+ end
13
+ end
14
+
15
+ context "has a vowel"
16
+
17
+ context "and an /e/ at the end of the word" do
18
+ it "returns 1" do
19
+ SyllableCounter.get_syllables("here").should == 1
20
+ SyllableCounter.get_syllables("age").should == 1
21
+ end
22
+ end
23
+
24
+ context "and then consecutive vowels" do
25
+ it "returns 2" do
26
+ SyllableCounter.get_syllables("meaty").should == 2
27
+ end
28
+ end
29
+
30
+ context "and has an /es/ suffix preceeded by /s z sh dg g ch/" do
31
+ it "is realized" do
32
+ SyllableCounter.get_syllables("kansas").should == 2
33
+ SyllableCounter.get_syllables("sizes").should == 2
34
+ SyllableCounter.get_syllables("fishes").should == 2
35
+ SyllableCounter.get_syllables("judges").should == 2
36
+ SyllableCounter.get_syllables("advantages").should == 4
37
+ SyllableCounter.get_syllables("churches").should == 2
38
+ end
39
+ end
40
+
41
+ context "and has an /ed/ suffix preceded by a /t/ or /d/" do
42
+ it "the /ed/ is realized" do
43
+ SyllableCounter.get_syllables("coughed").should == 1
44
+ SyllableCounter.get_syllables("kneaded").should == 2
45
+ end
46
+ end
47
+
48
+ context "and is one syllable with one trailing /e/" do
49
+ it "returns 1" do
50
+ SyllableCounter.get_syllables("the").should == 1
51
+ SyllableCounter.get_syllables("he").should == 1
52
+ end
53
+ end
54
+
55
+ context "and has a consonant + /le/ or /re/ ending" do
56
+ it "the final /e/ is realized" do
57
+ SyllableCounter.get_syllables("uncomfortable").should == 5
58
+ end
59
+ end
60
+ end
61
+
62
+ context "has a sentence" do
63
+ it "returns 11" do
64
+ SyllableCounter.get_syllables("the quick brown fox jumped over the lazy dog").should == 11
65
+ SyllableCounter.get_syllables("please call stella").should == 4
66
+ SyllableCounter.get_syllables("ask her to bring these things with her from the store").should == 11
67
+ SyllableCounter.get_syllables("six spoons of fresh snow peas").should == 6
68
+ SyllableCounter.get_syllables("five thick slabs of blue cheese").should == 6
69
+ #SyllablesCounter.get_syllables("and maybe a snack for her brother bob").should == 10
70
+ SyllableCounter.get_syllables("we also need a small plastic snake for the kids").should == 12
71
+ SyllableCounter.get_syllables("she can scoop these things into three red bags").should == 10
72
+ #SyllableCounter.get_syllables("and we will go meet her Wednesday at the train station").should == 13
73
+ end
74
+ end
75
+
76
+ #context "exceptions" do
77
+ #it "returns" do
78
+ #syllables("maybe").should == 2
79
+ #end
80
+ #end
81
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'syllable_counter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "syllable_counter"
8
+ spec.version = SyllableCounter::VERSION
9
+ spec.authors = ["Kelsey Mok"]
10
+ spec.email = ["kelseymok@gmail.com"]
11
+ spec.description = %q{Returns number of syllables (American English) given a string}
12
+ spec.summary = %q{Returns number of syllables (American English) given a string}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syllable_counter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kelsey Mok
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Returns number of syllables (American English) given a string
56
+ email:
57
+ - kelseymok@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/syllable_counter.rb
68
+ - lib/syllable_counter/version.rb
69
+ - spec/spec_helper.rb
70
+ - spec/syllable_counter_spec.rb
71
+ - syllable_counter.gemspec
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Returns number of syllables (American English) given a string
96
+ test_files:
97
+ - spec/spec_helper.rb
98
+ - spec/syllable_counter_spec.rb