rhymes 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/lib/rhymes.rb +9 -27
- data/lib/rhymes/version.rb +1 -1
- metadata +5 -5
data/Gemfile
CHANGED
data/lib/rhymes.rb
CHANGED
@@ -1,25 +1,15 @@
|
|
1
1
|
require 'rhymes/version'
|
2
2
|
|
3
3
|
module Rhymes
|
4
|
-
|
4
|
+
@@options = {:raw_dict => '/tmp/cmudict.0.7a', :compiled => '/tmp/rhymes.dat'}
|
5
5
|
|
6
6
|
class << self
|
7
|
-
##
|
8
|
-
# Sets the raw dictionary location. Default: /tmp/cmudict.0.7a
|
9
|
-
attr_writer :raw_dict
|
10
|
-
|
11
|
-
##
|
12
|
-
# Sets the location to store/retrieve precompiled dictionary. Default: /tmp/rhymes.dat
|
13
|
-
attr_writer :compiled
|
14
|
-
|
15
7
|
##
|
16
8
|
# Sets up options.
|
17
9
|
# - :raw_dict - location of raw dictionary file. Default: /tmp/cmudict.0.7a
|
18
10
|
# - :compiled - location to store/retrieve precompiled dictionary. Default: /tmp/rhymes.dat
|
19
|
-
def setup(options
|
20
|
-
|
21
|
-
@compiled = options[:compiled] || @compiled || DEFAULTS[:compiled]
|
22
|
-
{:raw_dict => @raw_dict, :compiled => @compiled}
|
11
|
+
def setup(options)
|
12
|
+
@@options.merge!(options)
|
23
13
|
end
|
24
14
|
|
25
15
|
##
|
@@ -48,12 +38,11 @@ module Rhymes
|
|
48
38
|
end
|
49
39
|
|
50
40
|
def init
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
elsif File.exists?(@raw_dict)
|
41
|
+
if File.exists?(@@options[:compiled])
|
42
|
+
@words, @rhymes = Marshal.load(File.open(@@options[:compiled], 'rb'){|f| f.read })
|
43
|
+
elsif File.exists?(@@options[:raw_dict])
|
55
44
|
@words, @rhymes = {}, {}
|
56
|
-
File.open(
|
45
|
+
File.open(@@options[:raw_dict]) do |f|
|
57
46
|
while l = f.gets do
|
58
47
|
next if l =~ /^[^A-Z]/
|
59
48
|
word, *pron = l.strip.split(' ')
|
@@ -65,22 +54,15 @@ module Rhymes
|
|
65
54
|
end
|
66
55
|
end
|
67
56
|
begin
|
68
|
-
File.open(
|
57
|
+
File.open(@@options[:compiled], 'wb'){|f| f.write(Marshal.dump([@words, @rhymes]))}
|
69
58
|
rescue
|
70
59
|
# ????
|
71
60
|
end
|
72
61
|
else
|
73
|
-
raise "File #{
|
62
|
+
raise "File #{@@options[:raw_dict]} does not exist. You can download latest dictionary " +
|
74
63
|
"from https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict and provide "
|
75
64
|
"file location with Rhymes.setup(:raw_dict => file_full_path) (/tmp/cmudict.0.7a by default)"
|
76
65
|
end
|
77
66
|
end
|
78
67
|
end
|
79
68
|
end
|
80
|
-
|
81
|
-
|
82
|
-
if __FILE__ == $0
|
83
|
-
input = ARGV.empty? ? ['laughter', 'soaring', 'antelope'] : ARGV
|
84
|
-
input.each{|w| puts "# #{w} - #{Rhymes.rhyme(w).map(&:downcase).join(', ')}"}
|
85
|
-
end
|
86
|
-
|
data/lib/rhymes/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &79065380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *79065380
|
25
25
|
description: Lookup perfect and identical rhymes
|
26
26
|
email:
|
27
27
|
- rubify@softover.com
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project: rhymes
|
63
|
-
rubygems_version: 1.8.
|
63
|
+
rubygems_version: 1.8.15
|
64
64
|
signing_key:
|
65
65
|
specification_version: 3
|
66
66
|
summary: Lookup perfect and identical rhymes
|