<commit_before>require 'rhymes/version'
# https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/
# wget https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/cmudict.0.7a

module Rhymes
  DEFAULTS = {:raw_dict => '/tmp/cmudict.0.7a', :compiled => '/tmp/rhymes.dat'}
  
  class << self
    attr_writer :raw_dict
    attr_writer :compied
 
    def setup(options = DEFAULTS)
      @raw_dict = options[:raw_dict] || DEFAULTS[:raw_dict]
      @compiled = options[:compiled] || DEFAULTS[:compiled]
    end

    def rhyme(word)
      wup = word.upcase
      rhymes[words[wup]] - [wup]
    end

  private

    def words
      init unless @words
      @words 
    end

    def rhymes
      init unless @rhymes
      @rhymes
    end

    def perfect_key(pron)
      first = pron.rindex{|snd| snd =~ /1$/} || 0
      pron[first..-1]
    end

    def init<commit_msg>fix for default initialization<commit_after>require 'rhymes/version'
# https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/
# wget https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/cmudict.0.7a

module Rhymes
  DEFAULTS = {:raw_dict => '/tmp/cmudict.0.7a', :compiled => '/tmp/rhymes.dat'}
  
  class << self
    attr_writer :raw_dict
    attr_writer :compied
 
    def setup(options = DEFAULTS)
      @raw_dict = options[:raw_dict] || DEFAULTS[:raw_dict]
      @compiled = options[:compiled] || DEFAULTS[:compiled]
    end

    def rhyme(word)
      wup = word.upcase
      rhymes[words[wup]] - [wup]
    end

  private

    def words
      init unless @words
      @words 
    end

    def rhymes
      init unless @rhymes
      @rhymes
    end

    def perfect_key(pron)
      first = pron.rindex{|snd| snd =~ /1$/} || 0
      pron[first..-1]
    end

    def init
      setup unless @compiled
{'fraction_non_alphanumeric': 0.12692307692307692, 'fraction_numerical': 0.007692307692307693, 'mean_word_length': 2.6202783300198806, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7168610', 'n_tokens_mistral': 709, 'n_tokens_neox': 679, 'n_words': 127}