rhymes 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ source :rubygems
4
4
  gemspec
5
5
 
6
6
  gem 'rake'
7
+ group :test do
8
+ gem 'rspec'
9
+ end
data/README.rdoc CHANGED
@@ -15,12 +15,18 @@ Before first usage download and store the dictionary. Example below assumes
15
15
  dictionary stored by default at /tmp/cmudict.0.7a. Precompiled version will be stored
16
16
  as /tmp/rhymes.dat
17
17
 
18
- require 'rhymes'
19
- Rhymes.rhyme('word')
18
+ ruby > require 'rhymes'
19
+ => true
20
+ ruby > Rhymes.rhyme('ruby')
21
+ => ["BOOBY", "DUBHI", "DUBY", "HRUBY", "KUBY", "LOOBY", "LUBY", "NEWBY", "RUBEY", "RUBI", "RUBIE", "SCOOBY", "TRUBEY", "TRUBY"]
20
22
 
21
23
  == Configuration
22
24
 
23
- require 'rhymes'
24
- Rhymes.setup(options = {:raw_dict => '/tmp/cmudict.0.7a', :compiled => '/tmp/rhymes.dat'})
25
+ ruby > require 'rhymes'
26
+ => true
27
+ ruby > Rhymes.setup
28
+ => {:raw_dict=>"/tmp/cmudict.0.7a", :compiled=>"/tmp/rhymes.dat"}
29
+ ruby > Rhymes.setup(:compiled=>'/new/location/file')
30
+ => {:raw_dict=>"/tmp/cmudict.0.7a", :compiled=>"/new/location/file"}
25
31
 
26
32
 
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
data/lib/rhymes.rb CHANGED
@@ -1,34 +1,32 @@
1
1
  require 'rhymes/version'
2
- # https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/
3
- # wget https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/cmudict.0.7a
4
2
 
5
3
  module Rhymes
6
4
  DEFAULTS = {:raw_dict => '/tmp/cmudict.0.7a', :compiled => '/tmp/rhymes.dat'}
7
5
 
8
6
  class << self
9
7
  ##
10
- # Sets the raw dictionary location.
11
- # default - /tmp/cmudict.0.7a
8
+ # Sets the raw dictionary location. Default: /tmp/cmudict.0.7a
12
9
  attr_writer :raw_dict
10
+
13
11
  ##
14
- # Sets the location to store/retrieve precompiled dictionary
15
- # default - /tmp/rhymes.dat
12
+ # Sets the location to store/retrieve precompiled dictionary. Default: /tmp/rhymes.dat
16
13
  attr_writer :compiled
17
14
 
18
15
  ##
19
- # Sets up options
16
+ # Sets up options.
20
17
  # - :raw_dict - location of raw dictionary file. Default: /tmp/cmudict.0.7a
21
18
  # - :compiled - location to store/retrieve precompiled dictionary. Default: /tmp/rhymes.dat
22
19
  def setup(options = DEFAULTS)
23
- @raw_dict = options[:raw_dict] || DEFAULTS[:raw_dict]
24
- @compiled = options[:compiled] || DEFAULTS[:compiled]
20
+ @raw_dict = options[:raw_dict] || @raw_dict || DEFAULTS[:raw_dict]
21
+ @compiled = options[:compiled] || @compiled || DEFAULTS[:compiled]
22
+ {:raw_dict => @raw_dict, :compiled => @compiled}
25
23
  end
26
24
 
27
25
  ##
28
- # Return the list of perfect and identical rhymes to provided word
26
+ # Return the list of perfect and identical rhymes to provided word.
29
27
  def rhyme(word)
30
28
  wup = word.upcase
31
- rhymes[words[wup]] - [wup]
29
+ (rhymes[words[wup]] || []) - [wup]
32
30
  end
33
31
 
34
32
  private
@@ -42,14 +40,15 @@ module Rhymes
42
40
  init unless @rhymes
43
41
  @rhymes
44
42
  end
45
-
43
+
44
+
46
45
  def perfect_key(pron)
47
46
  first = pron.rindex{|snd| snd =~ /1$/} || 0
48
47
  pron[first..-1]
49
48
  end
50
49
 
51
50
  def init
52
- setup unless @compiled
51
+ setup unless @compiled && @raw_dict
53
52
  if File.exists?(@compiled)
54
53
  @words, @rhymes = Marshal.load(File.open(@compiled, 'rb'){|f| f.read })
55
54
  elsif File.exists?(@raw_dict)
@@ -71,7 +70,9 @@ module Rhymes
71
70
  # ????
72
71
  end
73
72
  else
74
- raise "File #{@data_dir + RAW} does not exist!"
73
+ raise "File #{@data_dir + RAW} does not exist. You can download latest dictionary " +
74
+ "from https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict and provide "
75
+ "file location with Rhymes.setup(:raw_dict => file_full_path) (/tmp/cmudict.0.7a by default)"
75
76
  end
76
77
  end
77
78
  end
@@ -1,3 +1,3 @@
1
1
  module Rhymes
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/rhymes.gemspec CHANGED
@@ -16,4 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.require_paths = ["lib"]
19
+ s.add_development_dependency 'rspec'
19
20
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rhymes do
4
+ before(:all) do
5
+ @sample = File.join(File.dirname(__FILE__), 'sample_raw.txt')
6
+ Rhymes.setup(:raw_dict => @sample)
7
+ end
8
+
9
+ it 'should save provided option' do
10
+ Rhymes.setup(:compiled => '/tmp/sample').should ==
11
+ {:raw_dict => @sample, :compiled => '/tmp/sample'}
12
+ end
13
+
14
+ it 'should rhyme ruby with newby and scooby' do
15
+ Rhymes.rhyme('ruby').should == ['NEWBY', 'SCOOBY']
16
+ Rhymes.rhyme('Scooby').should == ['NEWBY', 'RUBY']
17
+ Rhymes.rhyme('newby').should == ['RUBY', 'SCOOBY']
18
+ end
19
+
20
+ it 'should rhyme rube and cube' do
21
+ Rhymes.rhyme('RubE').should == ['CUBE']
22
+ Rhymes.rhyme('cUbE').should == ['RUBE']
23
+ end
24
+
25
+ it 'should rhyme lighter and scriptwriter' do
26
+ Rhymes.rhyme('LIGHTER').should == ['SCRIPTWRITER']
27
+ Rhymes.rhyme('SCRIPTWRITER').should == ['LIGHTER']
28
+ end
29
+
30
+ it 'should rhyme monterrey and usa' do
31
+ Rhymes.rhyme('MONTERREY').should == ['USA']
32
+ Rhymes.rhyme('USA').should == ['MONTERREY']
33
+ end
34
+
35
+ it 'should rhyme nothing with unknown word' do
36
+ Rhymes.rhyme('dabadabadaba').should == []
37
+ end
38
+
39
+ end
@@ -0,0 +1,18 @@
1
+ ;;;
2
+ ;;; NOTES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
+ ;;;
4
+ !EXCLAMATION-POINT EH2 K S K L AH0 M EY1 SH AH0 N P OY2 N T
5
+ "CLOSE-QUOTE K L OW1 Z K W OW1 T
6
+
7
+ CUBE K Y UW1 B
8
+ LIGHTER L AY1 T ER0
9
+ MONTERREY M AA2 N T ER0 EY1
10
+ MONTERREY(1) M AA2 N ER0 EY1
11
+ MONTERREY(2) M AA2 N T ER0 R EY1
12
+ MONTERREY(3) M AA2 N ER0 R EY1
13
+ NEWBY N UW1 B IY0
14
+ RUBE R UW1 B
15
+ RUBY R UW1 B IY0
16
+ SCOOBY S K UW1 B IY0
17
+ SCRIPTWRITER S K R IH1 P T R AY2 T ER0
18
+ USA Y UW1 EH1 S EY1
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'rhymes'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.formatter = 'documentation'
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhymes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-17 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2011-10-18 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &82209270 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *82209270
14
25
  description: Lookup perfect and identical rhymes
15
26
  email:
16
27
  - rubify@softover.com
@@ -26,6 +37,9 @@ files:
26
37
  - lib/rhymes.rb
27
38
  - lib/rhymes/version.rb
28
39
  - rhymes.gemspec
40
+ - spec/rhymes_spec.rb
41
+ - spec/sample_raw.txt
42
+ - spec/spec_helper.rb
29
43
  homepage: https://github.com/kalenkov/rhymes
30
44
  licenses: []
31
45
  post_install_message: