rhymes 0.0.2
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.
- data/.gitignore +5 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.rdoc +26 -0
- data/Rakefile +1 -0
- data/lib/rhymes.rb +85 -0
- data/lib/rhymes/version.rb +3 -0
- data/rhymes.gemspec +19 -0
- metadata +53 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Eugene Kalenkovich
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Rhymes
|
2
|
+
Rhymes looks up perfect and identical rhymes using the Carnegie Mellon
|
3
|
+
Pronouncing Dictionary, or any other pronounciation dictionary with
|
4
|
+
compatible format.
|
5
|
+
|
6
|
+
Dictionary can be downloaded from https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/
|
7
|
+
(latest version - https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/cmudict.0.7a)
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
gem install rhymes
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
Before first usage download and store the dictionary. Example below assumes
|
15
|
+
dictionary stored by default at /tmp/cmudict.0.7a. Precompiled version will be stored
|
16
|
+
as /tmp/rhymes.dat
|
17
|
+
|
18
|
+
require 'rhymes'
|
19
|
+
Rhymes.rhyme('word')
|
20
|
+
|
21
|
+
== Configuration
|
22
|
+
|
23
|
+
require 'rhymes'
|
24
|
+
Rhymes.setup(options = {:raw_dict => '/tmp/cmudict.0.7a', :compiled => '/tmp/rhymes.dat'})
|
25
|
+
|
26
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/rhymes.rb
ADDED
@@ -0,0 +1,85 @@
|
|
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
|
+
|
5
|
+
module Rhymes
|
6
|
+
DEFAULTS = {:raw_dict => '/tmp/cmudict.0.7a', :compiled => '/tmp/rhymes.dat'}
|
7
|
+
|
8
|
+
class << self
|
9
|
+
##
|
10
|
+
# Sets the raw dictionary location.
|
11
|
+
# default - /tmp/cmudict.0.7a
|
12
|
+
attr_writer :raw_dict
|
13
|
+
##
|
14
|
+
# Sets the location to store/retrieve precompiled dictionary
|
15
|
+
# default - /tmp/rhymes.dat
|
16
|
+
attr_writer :compiled
|
17
|
+
|
18
|
+
##
|
19
|
+
# Sets up options
|
20
|
+
# - :raw_dict - location of raw dictionary file. Default: /tmp/cmudict.0.7a
|
21
|
+
# - :compiled - location to store/retrieve precompiled dictionary. Default: /tmp/rhymes.dat
|
22
|
+
def setup(options = DEFAULTS)
|
23
|
+
@raw_dict = options[:raw_dict] || DEFAULTS[:raw_dict]
|
24
|
+
@compiled = options[:compiled] || DEFAULTS[:compiled]
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Return the list of perfect and identical rhymes to provided word
|
29
|
+
def rhyme(word)
|
30
|
+
wup = word.upcase
|
31
|
+
rhymes[words[wup]] - [wup]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def words
|
37
|
+
init unless @words
|
38
|
+
@words
|
39
|
+
end
|
40
|
+
|
41
|
+
def rhymes
|
42
|
+
init unless @rhymes
|
43
|
+
@rhymes
|
44
|
+
end
|
45
|
+
|
46
|
+
def perfect_key(pron)
|
47
|
+
first = pron.rindex{|snd| snd =~ /1$/} || 0
|
48
|
+
pron[first..-1]
|
49
|
+
end
|
50
|
+
|
51
|
+
def init
|
52
|
+
setup unless @compiled
|
53
|
+
if File.exists?(@compiled)
|
54
|
+
@words, @rhymes = Marshal.load(File.open(@compiled, 'rb'){|f| f.read })
|
55
|
+
elsif File.exists?(@raw_dict)
|
56
|
+
@words, @rhymes = {}, {}
|
57
|
+
File.open(@raw_dict) do |f|
|
58
|
+
while l = f.gets do
|
59
|
+
next if l =~ /^[^A-Z]/
|
60
|
+
word, *pron = l.strip.split(' ')
|
61
|
+
next if word.empty? || word =~ /\d/
|
62
|
+
pron.map!{|snd| snd.sub(/2/, '1')}
|
63
|
+
key = perfect_key(pron)
|
64
|
+
@words[word] = key
|
65
|
+
(@rhymes[key] ||= []) << word
|
66
|
+
end
|
67
|
+
end
|
68
|
+
begin
|
69
|
+
File.open(@compiled, 'wb'){|f| f.write(Marshal.dump([@words, @rhymes]))}
|
70
|
+
rescue
|
71
|
+
# ????
|
72
|
+
end
|
73
|
+
else
|
74
|
+
raise "File #{@data_dir + RAW} does not exist!"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
if __FILE__ == $0
|
82
|
+
input = ARGV.empty? ? ['laughter', 'soaring', 'antelope'] : ARGV
|
83
|
+
input.each{|w| puts "# #{w} - #{Rhymes.rhyme(w).map(&:downcase).join(', ')}"}
|
84
|
+
end
|
85
|
+
|
data/rhymes.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rhymes/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rhymes"
|
7
|
+
s.version = Rhymes::VERSION
|
8
|
+
s.authors = ["Eugene Kalenkovich"]
|
9
|
+
s.email = ["rubify@softover.com"]
|
10
|
+
s.homepage = "https://github.com/kalenkov/rhymes"
|
11
|
+
s.summary = %q{Lookup perfect and identical rhymes}
|
12
|
+
s.description = %q{Lookup perfect and identical rhymes}
|
13
|
+
|
14
|
+
s.rubyforge_project = "rhymes"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rhymes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eugene Kalenkovich
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-17 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Lookup perfect and identical rhymes
|
15
|
+
email:
|
16
|
+
- rubify@softover.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
- Rakefile
|
26
|
+
- lib/rhymes.rb
|
27
|
+
- lib/rhymes/version.rb
|
28
|
+
- rhymes.gemspec
|
29
|
+
homepage: https://github.com/kalenkov/rhymes
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project: rhymes
|
49
|
+
rubygems_version: 1.8.11
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Lookup perfect and identical rhymes
|
53
|
+
test_files: []
|