見出し画像

【Python】英文から語順整序問題を作成する ver1.7

部下の育成に悩む。落ち着いて本読もうかな。

今日は前回の続きです。

  1. 神奈川県の入試に出題された英文を用いて、語順整序問題を作成する

  2. 任意の単語数を決定し、問題を作成できるようにする

  3. 関数化し、運用しやすくする

の3点でした。プログラムは前回記事に掲載しています。

今回は作成したプログラムをもとに、複数の英文から問題を作成できるように繰り返し処理を行います。

今回作成したプログラム

# [4] in R4_2022, R3_2021
sentences = ["What did you want to be when you were a child?",
             "But I can't decide which one I should buy.",
             "But I  wish I were better at playing it.",
             "Who is the best tennis player of the five?",
             "Do you know the girl playning the  guitar and singing over there.",
             "Because it is written through the eyes of a little dog.",
             "Do you want  me to open that door?"]

# 繰り返し処理
sortby_sentences = []
for sentence in sentences:
  answer, question = sortby_words(sentence, 5)
  sortby_sentences.append([question, answer])

sortby_sentences
# 出力された内容
[['What did ( want, you, be, to, when ) you were a child?',
  'What did ( you, want, to, be, when ) you were a child?'],
 ["But I can't ( should, I, one, which, decide ) buy.",
  "But I can't ( decide, which, one, I, should ) buy."],
 ['(I, were, But, I, wish ) better at playing it.',
  '(But, I, wish, I, were ) better at playing it.'],
 ['(Who, tennis, is, the, best ) player of the five?',
  '(Who, is, the, best, tennis ) player of the five?'],
 ['Do you ( girl, the, know, playning, the ) guitar and singing over there.',
  'Do you ( know, the, girl, playning, the ) guitar and singing over there.'],
 ['Because ( is, through, the, it, written ) eyes of a little dog.',
  'Because ( it, is, written, through, the ) eyes of a little dog.'],
 ['Do you ( me, that, open, want, to ) door?',
  'Do you ( want, me, to, open, that ) door?']]

いい感じですね。実際は日本語訳も掲載できるようにした方がいいので、プログラムは改変が必要ですね。
あとは、出口を設定してどうやって使いやすく運用できるかを考えないといけません。サーバー上で出力できるようにしておけばいいかなと思っています。そうすればデータベースやWeb構築の勉強にもなりますしね。


この記事が気に入ったらサポートをしてみませんか?