### データーから特定(回答)のデーターを抜き出し別のデーターを出力する方法を探しています。
The time will soon come {{c1::(文字)}} we can enjoy space travel. 1. when 2. where 3. what 4. whic 1.私たちが宇宙旅行を楽しむことができる時が程なくやってくるだろう。
こういうデータから
① The time will soon come {{c1::(1.when)}} we can enjoy space travel. 1. when 2. where 3. what 4. whic ② The time will soon come we can enjoy space
こういう二つのでデータを出力したいのですがうまくいきません。
Ruby
1require 'csv' 2 3def clean_text(text) 4 text.gsub(/\{\{c1::([0-9].\s?(?=[a-z])/,"").gsub(/)\}\}/,"") 5end 6 7output = [] 8 9CSV.foreach("karaage.csv", liberal_parsing: true, encoding:'iso-8859-1:utf-8') do |row| 10 card = [] 11 12 answer = row[1][0] 13 full_prompt = row[0] 14 question = full_prompt[/.*?(?=\s1)/] 15 16 # skip if already solved 17 if /c1::([0-9]/.match?(question) 18 card << full_prompt 19 card << clean_text(question) 20 else 21 puts "full prompt: #{full_prompt}\n" 22 puts "answer: #{answer}\n" 23 puts full_prompt[/#{answer}.*#{Integer(answer)+1}/] 24 puts "\n" 25 answer_text = full_prompt[/#{answer}.*#{Integer(answer)+1}/][0...-2] 26 subbed = full_prompt.gsub(/(?<=().*?(?=))/, answer_text) 27 subbed_question = question.gsub(/(?<=().*?(?=))/, answer_text) 28 card << subbed 29 card << clean_text(subbed_question) 30 31 end 32 33 # puts full_prompt.gsub(/\{\{.*\}}/, answer_text) 34 puts "\n" 35 output << card 36end 37 38File.write("output.csv", output.map(&:to_csv).join) 39
I was tired after the test last Friday, because I {{c1::(文字)}} all, day long every day for a week., 1.had been working 2. have been working, 3. have worked 4. was working 1.私は先週の金曜日にテストが終わると疲れてしまった。というのもそれまで1週間毎日一日中勉強していたからだ。
試しに上のデーターをかけると下のようになってしまいます。
① I was tired after the test last Friday, because I {{c1::(1::(æå)}} all, day long every day for a week., 1.had been working )}} all, day long every day for a week., 1.had been working 2. have been working, 3. have worked 4. was working ② I was tired after the test last Friday, because I {{c1::(1::(æå all, day long every day for a week., 1.had been working all, day long every day for a week.,
あなたの回答
tips
プレビュー