<commit_before>require "string_to_ipa/version"
require "sqlite3"

module StringToIpa
  DATABASE = SQLite3::Database.new(File.join(File.expand_path(File.dirname(__FILE__)), "..", "ipagem.db"))

  DATABASE.results_as_hash = true
  DATABASE.execute( "PRAGMA encoding = \"UTF-16\"" );
  
  class Phonetic
    attr_accessor :word, :phonetic
    attr_reader :id
  
    def initialize(options)
      @word = options["word"]
      @phonetic = options["phonetic"]
      @id = options["id"]
    end
  
    def insert
      DATABASE.execute("INSERT INTO phonetics (word, phonetic) VALUES (?, ?)", @word, @phonetic)
      @id = DATABASE.last_insert_row_id
    end
  
    def save      
      attributes = []
                                                                                 
      instance_variables.each do |i|                                               
        attributes << i.to_s.delete("@")                                           
      end     
                                                                         
                                                                                 
      query_hash = {}                                                 
                                                                                 
      attributes.each do |a|                                             
        value = self.send(a)
        query_hash[a] = value                                                       
      end                                                                

      query_hash.each do |key, value|
        DATABASE.execute("UPDATE phonetics SET #{key} = ? WHERE id = #{@id}", value)
      end                                                                          
    end
  
    def delete
      DATABASE.execute("DELETE FROM phonetics WHERE id = #{@id}")
    end
  
  
    def self.find(s_id)
      result = DATABASE.execute("SELECT * FROM phonetics WHERE id = #{s_id}")[0]
    
      self.new(result)
    end
  
  end

end

class String
  def to_ipa
    phonetic = StringToIpa::DATABASE.execute("SELECT phonetic from phonetics where word = ?", self.upcase)
    
    if phonetic == []
      return self
    else
      return phonetic[0]["phonetic"]
    end
  
  end

end<commit_msg>Added the 'to_word' method This takes an IPA as input and returns the corresponding word.<commit_after>require "string_to_ipa/version"
require "sqlite3"

module StringToIpa
  DATABASE = SQLite3::Database.new(File.join(File.expand_path(File.dirname(__FILE__)), "..", "ipagem.db"))

  DATABASE.results_as_hash = true
  DATABASE.execute( "PRAGMA encoding = \"UTF-16\"" );
  
  class Phonetic
    attr_accessor :word, :phonetic
    attr_reader :id
  
    def initialize(options)
      @word = options["word"]
      @phonetic = options["phonetic"]
      @id = options["id"]
    end
  
    def insert
      DATABASE.execute("INSERT INTO phonetics (word, phonetic) VALUES (?, ?)", @word, @phonetic)
      @id = DATABASE.last_insert_row_id
    end
  
    def save      
      attributes = []
                                                                                 
      instance_variables.each do |i|                                               
        attributes << i.to_s.delete("@")                                           
      end     
                                                                         
                                                                                 
      query_hash = {}                                                 
                                                                                 
      attributes.each do |a|                                             
        value = self.send(a)
        query_hash[a] = value                                                       
      end                                                                

      query_hash.each do |key, value|
        DATABASE.execute("UPDATE phonetics SET #{key} = ? WHERE id = #{@id}", value)
      end                                                                          
    end
  
    def delete
      DATABASE.execute("DELETE FROM phonetics WHERE id = #{@id}")
    end
  
  
    def self.find(s_id)
      result = DATABASE.execute("SELECT * FROM phonetics WHERE id = #{s_id}")[0]
    
      self.new(result)
    end
  
  end

end

class String
  def to_ipa
    phonetic = StringToIpa::DATABASE.execute("SELECT phonetic from phonetics where word = ?", self.upcase)
    
    if phonetic == []
      return self
    else
      return phonetic[0]["phonetic"]
    end
  end

  def to_word
    word = StringToIpa::DATABASE.execute("SELECT word from phonetics where phonetic = ?", self)

    if word == []
      return self
    else
      return word[0]["word"]
    end
  end

end
{'fraction_non_alphanumeric': 0.08390732623669381, 'fraction_numerical': 0.0027134209977040286, 'mean_word_length': 1.027072758037225, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2716988', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1139, 'n_words': 272}