Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (40 sloc) 1.2 KB
require './lib/cockney'
namespace :build do
task :all => [:rhymes, :associations]
task :rhymes do
REDIS.multi do
File.read("./data/cmudict").each_line do |line|
next unless /^\w/ === line
word, *phonemes = line.strip.split(/\s+/)
scheme = []
last_phoneme_was_stressed_vowel = false
phonemes.each do |phoneme|
if /(\d)$/ === phoneme
last_phoneme_was_stressed_vowel = $1.to_i > 0
scheme << phoneme
end
if last_phoneme_was_stressed_vowel
scheme << phoneme
end
end
rhyme = scheme.join(":")
REDIS.sadd "schemes:#{rhyme}", word
REDIS.set "words:#{word}:scheme", rhyme
end
end
end
task :associations do
REDIS.multi do
words = {}
word, associations = nil, nil
File.read("./data/eat-associations").each_line do |line|
word = line.strip and next unless word
associations = Hash[*line.strip.split(/\|/)]
associations.each do |association, score|
REDIS.zadd "words:#{word}:associations", score, association
end
word, associations = nil, nil
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.