Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/lib/haiku_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,28 @@ def initialize_syllable_counts

def get_cmu_syllable_count(word)
@syllable_counts ||= initialize_syllable_counts
@syllable_counts[word.downcase]
return nil if word.nil? || word.empty?

count = @syllable_counts[word]
return count if count

# british people...
if word.length > 3 && word.end_with?("ise")
word_american = word.sub(/ise$/, 'ize')
count = @syllable_counts[word_american]
return count if count
end

nil
end

def test(text)
return false unless text.is_a?(String)

# Clean up the text
text = text.downcase
text = text.gsub(/[^a-zA-Z0-9\s\.$]/, '')
text = text.gsub(/[^a-zA-Z0-9\s\.'$]/, '')
text = text.gsub(/\$/, 'dollar ')
text = text.gsub(/\bise\b/, 'ize') # british people...

# Convert numbers to words
text = text.gsub(/\d+/) { |num| num.to_i.humanize }
Expand Down