diff --git a/j2106_intro.csv b/j2106_intro.csv new file mode 100644 index 0000000..f9b5fb9 --- /dev/null +++ b/j2106_intro.csv @@ -0,0 +1,4 @@ +単語,意味 +終焉,命の終わり +刹那,きわめて短い時間。瞬間。 +輪廻,生きかわり死にかわりすること。 diff --git a/j2106_intro.rb b/j2106_intro.rb index 4898607..8a23003 100755 --- a/j2106_intro.rb +++ b/j2106_intro.rb @@ -1,9 +1,7 @@ #! usr/bin/env ruby # -*- coding: utf-8 -*- -ziten = ["yah","gg"] -imi = [" "," "] -i = 1 +require 'csv' def loading(time) if time == 2 @@ -27,29 +25,35 @@ end end -def levenshtein_distance(x) +def levenshtein_distance(divide_input) + place = 0 ziten = ["aweuiygf","aewf","waefgyu"] - if x.length == 0 #1.もし入力した文字が空なら、 - shortest = ziten.sort_by(&:length).first # 配列zitenの要素の中で最も文字数が - # 少ないものを変数shortestに代入し - distance =+ shortest.length # その単語の長さを編集距離に足す。 - p distance - else #2.もし入力した文字数が1以上なら、 - for divide in ziten - comparison_ziten = divide.split("") - comparison_input = x.split("") - for hikaku1 in comparison_ziten - if hikaku1 == comparison_input - p hikaku1 - else - distance =+ 1 - end + if divide_input.length == 0 #1.もし入力した文字が空なら、 + shortest = ziten.sort_by(&:length).first # 配列zitenの要素の中で + # 最も文字数が + # 少ないものを変数shortestに代入し + distance =+ shortest.length # その単語の長さを編集距離に足す。 + else #2.もし入力した文字数が1以上なら、 + for divide_ziten in ziten # 配列zitenの要素を順に + sleep(3) + # 変数divide_zitenに代入し, + comparison_ziten = divide_ziten.split("")# その文字を1文字ごとに分割し、 + p comparison_ziten + sleep(3) + comparison_input = divide_input.split("")# 入力した文字も分割する。 + p comparison_input + sleep(3) + if comparison_ziten.length - comparison_input.length > 0 + comparison_ziten.length - comparison_input.length > 0 + elsif comparison_input.length - comparison_ziten.length > 0 + distance =+ comparison_input.length - comparison_ziten.length end + printf("ちがうのは%sだよ\n",different) end - p distance end + printf("辞典にある単語との遠さ:%d",distance) end - + p "土門侑生とは" print "何について見る?\n" puts "番号を入力してね." @@ -64,21 +68,24 @@ puts "2やね。" elsif choice == "3" loading(3) - puts "my語辞典" - puts "my語辞典とは?\n---土門侑生に関連する単語が載ってるで。" - printf("現在の語数・・・%d\n",ziten.length) + puts "my中二病語辞典" + puts "my中二病語辞典とは?\n---私の好きな中二病語が載ってるで。" puts "1.語とその意味を見る\n2.語だけ見る\n3.調べる\n番号を入力してな。" choice2 = gets.chomp if choice2 == "1" - for n in ziten - printf("%d:%s\n---\n",i,n) - i += 1 - end + data = CSV.read("j2106_intro.csv", :headers => true) + data.each{|row| + printf("%s\n",row["単語"]) + sleep(1) + printf("---%s\n",row["意味"]) + sleep(1) + } elsif choice2 == "2" - for n in ziten - printf("%d:%s\n---\n",i,n) - i += 1 - end + data = CSV.read("j2106_intro.csv", :headers => true) + data.each{|row| + printf("%s\n",row["単語"]) + sleep(1) + } elsif choice2 == "3" print "入力してください:" search_word = gets.chomp @@ -86,6 +93,6 @@ else puts "そか。" end -elsif - puts "そか。" +else end +