#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

ENV['MECAB_PATH']='/usr/lib/x86_64-linux-gnu/libmecab.so'
require './kana_Braille.rb'     
require 'natto'
#require 'kakasi'
#require 'nkf'


def mena(tem,text,gana,kana,se,ei,al,oo,ko)
  
  #text=アルファベットならmecab使わないの設定
  natto = Natto::MeCab.new
  natto.parse(text) do |n|
    k = n.feature.split(',')
    #p n.surface
    if k[0]=="BOS/EOS" #BOSは文頭を表し、EOSは文末を表す。
      #k[0]にBOS/EOSが含まれていたら空白を表示するよう指示
      tem+=""
    else
      if k[-1]=="*"
        almo=n.surface
        if oo.include?(almo[0])==true || ko.include?(almo[0])==true
          i=0
          yousyori="#{al["外"][0]}"
          while i<almo.length
            moji=almo[i]
            if oo.include?(moji)==true
              yousyori+="#{al[moji][0]}"
              yousyori+="#{al[moji][1]}"
            else ko.include?(moji)==true
              yousyori+="#{al[moji][0]}"
            end
            i+=1
          end
        else
          sin="ヨメナイ" #要改善
          yousyori=youon(sin,gana)
        end
        
      else
        yousyori=youon(k[-1],gana)
      end
      
      for moji in yousyori.split("")
        #p moji
        if moji==(" ") #空白があったら空白を出す
          tem+=""
        elsif se.include?(moji)==false && ei.include?(moji)==false 
          tem+="#{kana[moji][1]}#{kana[moji][0]}"
        else
          tem+="#{moji}"
        end
      end
    end
  end
  tem
end

# def eika(bunsyo,temei)
#   kaka=Kakasi.kakasi('-Ja -Ha -Ka',bunsyo)
#   for aaa in kkk.split("")
#     if aaa=="^"
#       aaa="-"
#       temei+="#{aaa}"
#     else
#       temei+="#{aaa}"
#     end
#   end
#   temei="外"+"#{temei}"
#   temei
# end

def sutem(suuu,suji,sufu)
  j=0
  for retu in suuu.split("")
    j+=1
    if j==1      
      suji+="#{sufu}#{retu}"
    else
      suji+="#{retu}"
    end
  end
  suji
end  

