0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

英語学習者必見!PowerShellで穴埋め問題を自動生成する簡単スクリプト

Posted at

実行イメージ

こんな感じで、よくつかわれる英単語を空欄に変換して、穴埋め問題風にするスクリプトです。

変換前

image.png

変換後

動詞を空欄にした例:

image.png

必要な環境

・Windowsパソコン
・PowerShell

ステップ

  1. あらかじめ「よくつかわれるトップ300の英単語」をCSVで保存しときます。
  2. 任意の英語のテキストファイルを読み込みます。日本語まじっててもOK。
  3. トップ300の頻出英単語が(  )に変換されます。
  4. プリントアウトしたら自分オリジナルの穴埋め問題集のできあがり。

CSVファイル

・「C:\英語おべんきょ\Common300words.csv」などに保存してください。

よくつかわれるトップ300の英単語
Common300words.csv
Verbs	Adjectives	Adverbs	Prepositions
be	good	absolutely	about
have	new	actually	above
do	first	always	across
say	last	angrily	after
go	long	anxiously	against
get	great	badly	along
make	little	beautifully	among
know	own	boldly	around
think	other	bravely	at
take	old	brightly	before
see	right	calmly	behind
come	big	carefully	below
want	high	certainly	beneath
use	different	cheerfully	beside
find	small	clearly	between
give	large	closely	beyond
tell	next	completely	by
work	young	constantly	despite
call	important	correctly	down
try	few	courageously	during
ask	public	daily	except
need	bad	deeply	for
feel	same	definitely	from
become	able	deliberately	in
leave	happy	differently	inside
put	sad	easily	into
mean	kind	effectively	like
keep	generous	elegantly	near
let	lucky	equally	of
begin	strong	especially	off
seem	weak	eventually	on
help	unusual	exactly	onto
talk	quick	excitedly	out
turn	slow	extremely	outside
start	bright	fairly	over
show	dark	faithfully	past
hear	warm	fast	since
play	cold	fatally	through
run	hard	finally	throughout
move	soft	firmly	to
like	beautiful	frequently	toward
live	clean	fully	under
believe	dirty	gently	underneath
hold	calm	gladly	until
bring	angry	gracefully	up
happen	easy	greatly	upon
write	difficult	happily	with
provide	clear	hard	within
sit	blurry	hastily	without
stand	free	healthily	can
lose	expensive	heavily	could
pay	cheap	honestly	may
meet	rich	hurriedly	might
include	poor	immediately	must
continue	polite	importantly	shall
set	rude	intelligently	should
learn	modern	intensely	will
change	ancient	interestingly	would
lead	quiet	kindly	ought
understand	noisy	lazily	
watch	safe	lightly	
follow	dangerous	likely	
stop	famous	loudly	
create	unknown	madly	
speak	happy	magically	
read	sad	mainly	
allow	intelligent	merrily	
add	stupid	naturally	
spend	tall	nearly	
grow	short	neatly	
open	heavy	nervously	
walk	light	nicely	
win	brave	noisily	
offer	shy	normally	
remember	confident	obviously	
love	able	occasionally	
consider	active	openly	
appear	actual	optimistically	
buy	afraid	partially	
wait	amazing	patiently	
serve	angry	perfectly	
die	anxious	politely	
send	beautiful	positively	
expect	better	powerfully	
build	big	precisely	
stay	bitter	properly	
fall	black	quickly	
cut	blue	quietly	
reach	brave	rapidly	
kill	bright	rarely	
remain	busy	readily	
suggest	calm	really	
raise	careful	regularly	
pass	certain	relatively	
sell	cheap	reliably	
require	clear	remarkably	
report	clever	respectfully	
decide	close	roughly	
pull	cold	rudely	
return	common	sadly	
explain	complete	safely	
hope	confident	satisfactorily	
develop	cool	seldom	
carry	crazy	sensibly	
break	cute	seriously	
receive	dangerous	sharply	
agree	dark	shyly	
support	dead	silently	
hit	deep	similarly	
produce	delicious	simply	
eat	different	slowly	
cover	difficult	smoothly	
catch	dirty	softly	
draw	dry	specially	
choose	early	specifically	
deal	easy	speedily	
face	electric	strongly	
achieve	empty	stupidly	
point	entire	successfully	
listen	equal	suddenly	
mark	excellent	sufficiently	
form	expensive	surprisingly	
join	fair	suspiciously	
reduce	famous	sweetly	
save	fast	swiftly	
cost	fat	technically	
involve	fine	thankfully	
improve	flat	thoughtfully	
increase	fresh	thoroughly	
protect	friendly	tightly	
visit	full	totally	
close	funny	truthfully	
finish	general	typically	
imagine	gentle	unexpectedly	
study	good	unfortunately	
enjoy	great	unhappily	
apply	green	unusually	
prepare	happy	urgently	
control	hard	usefully	
manage	healthy	usually	
avoid	heavy	vaguely	
determine	helpful	vastly	
encourage	high	vividly	
maintain	honest	warmly	
prove	hot	weakly	
design	huge	well	
deliver	hungry	widely	
affect	important	wildly	
prevent	interesting	wisely	
describe	kind	wonderfully	
respond	large		
solve	late		
adapt	lazy		
argue	light		
identify	likely		
assume	little		
direct	long		
recognize	loud		
accept	lovely		
examine	low		
employ	lucky		
attend	modern		
introduce	narrow		
explore	natural		
observe	necessary		
present	new		
review	nice		
select	normal		
advise	old		
comment	open		
define	ordinary		
refer	pale		
discuss	perfect		
enhance	personal		
illustrate	pleasant		
participate	poor		
recommend	possible		
analyze	pretty		
attempt	proud		
clarify	quick		
conclude	quiet		
connect	ready		
consult	real		
contrast	red		
demonstrate	regular		
expand	rich		
focus	right		
integrate	round		
interpret	safe		
justify	salty		
outline	serious		
reflect	sharp		
relate	short		
simplify	silent		
summarize	similar		
translate	simple		
utilize	slow		
appreciate	small		
assess	soft		
compile	special		
comprehend	strange		
concentrate	strong		
criticize	sudden		
distinguish	sweet		
estimate	tall		
organize	thick		
prioritize	thin		
transform	tight		
validate	tiny		
collaborate	tired		
coordinate	TRUE		
innovate	useful		
negotiate	usual		
synthesize	warm		
mediate	weak		
modify	wet		
operate	white		
resolve	wide		
designate	wild		
strategize	wise		
hypothesize	wonderful		
model	wrong		
categorize	yellow		
exemplify	young		
legitimize	amusing		
quantify	attractive		
specify	average		
theorize	basic		
narrate	boring		
predict	brilliant		
classify	broken		
propose	charming		
regulate	classical		
revise	clever		
simulate	complex		
evaluate	creative		
emphasize	cruel		
oversee	curious		
rectify	dangerous		
augment	delightful		
configure	different		
execute	direct		
facilitate	distinct		
influence	dynamic		
motivate	efficient		
inspire	elegant		
monitor	energetic		
revolutionize	essential		
implement	exact		
empower	exclusive		
advocate	exciting		
advance	fantastic		
initiate	fascinating		
sustain	favorable		
supervise	flexible		
administer	formal		
delegate	frequent		
mentor	genuine		
	giant		
	global		
	graceful		
	hilarious		
	historic		
	honorable		
	ideal		
	illegal		
	immediate		
	impressive		
	innocent		
	intelligent		
	international		
	intuitive		
	invisible		
	logical		
	loyal		
	magical		
	mysterious		
	noble		
	obvious		
	official		
	original		
	outstanding		
	perfect		
	polite		
	positive		
	powerful		
	precise		
	progressive		
	prompt		
	proper		
	reliable		
	relevant		
	remarkable		
	responsive		
	romantic		
	sensitive		
	shy		
	significant		
	smart		
	solid		
	specific		
	spiritual		
	stable		
	stunning		
	supportive		
	systematic		
	temporary		
	typical		
	unique		
	valuable		
	vital		
	visible		
	visual		
	wonderful		

テキストファイル

・「C:\英語おべんきょ\Original.txt」などで保存してください。

読み込む英語テキストファイル
Original.txt
Oda Nobunaga:


1. 理想を持ち、信念に生きよ。理想や信念を見失った者は、戦う前から負けているといえよう。そのような者は廃人と同じだ。  
   - "Hold onto your ideals and live by your beliefs. Those who lose their ideals and beliefs have already lost before the battle begins. Such people are no different from the walking dead."

2. 生まれながらに才能のある者は、それを頼んで鍛錬を怠る、自惚れる。しかし、生まれつき才能がない者は、何とか技術を身につけようと日々努力する。心構えがまるで違う。これが大事だ。  
   - "Those born with talent often rely on it, neglect training, and become conceited. On the other hand, those born without talent strive daily to acquire skills. Their mindset is entirely different, and that is what truly matters."

3. 必死に生きてこそ、その生涯は光を放つ。  
   - "Only by living desperately does one's life shine brightly."

4. 攻撃を一点に集約せよ、無駄な事はするな。  
   - "Focus your attacks on a single point; do not waste effort on unnecessary things."

5. 臆病者の目には、敵は常に大軍に見える。  
   - "To the eyes of a coward, the enemy always appears as a massive army."

6. 恃(たの)むところにある者は、恃むもののために滅びる。  
   - "Those who rely on something will ultimately be destroyed by what they rely upon."

7. 人を用ふるの者は、能否を択ぶべし、何ぞ新故を論ぜん。  
   - "Those who employ others should choose based on ability, not on whether they are new or old."

Tokugawa Ieyasu:

1. 人生は重荷を負うて遠き道を行くが如し  
   - "Life is like carrying a heavy load on a long journey."  
   → Take life step by step; don’t rush.

2. 勝つことばかり知って、負けることを知らざれば害その身に至る  
   - "If you only know how to win and not how to lose, it will harm you."  
   → Learn from failure, not just success.

3. 耐えて忍べば憂いなし  
   - "Endure and persevere, and you’ll have no worries."  
   → Patience brings good outcomes.

4. 過ちを改めるに遅すぎることはない  
   - "It’s never too late to correct your mistakes."  
   → Fix your mistakes as soon as you notice them.

5. 夢中に生きよ、夢中に学べ  
   - "Live passionately and keep learning with enthusiasm."  
   → Be fully dedicated to what you love and keep learning.

Takeda Shingen:

1. 信頼してこそ人は尽くしてくれるものだ  
   - "People will do their best only if you trust them."  
   → Building trust encourages others to commit fully.

2. 人は城、人は石垣、人は堀、情けは味方、仇は敵なり  
   - "Men are your castle, men are your stone walls, men are your moat. Kindness makes allies, resentment makes enemies."  
   → Value people and treat them kindly to build a strong support system.

3. 苦しい時は自分を磨く好機  
   - "Difficult times are an opportunity to improve yourself."  
   → Use hardships as a chance for self-growth.

PowerShellスクリプト

・フォルダ名やファイル名は適宜変更してください。
・とくべつなモジュールはいりません。

穴埋め問題自動作成スクリプト
Create_FillinBlank_Questions.ps1
# ファイルパスを定義
$csvFilePath = "C:\英語おべんきょ\Common300words.csv"
$textFilePath = "C:\英語おべんきょ\Original.txt"
$outputDirectory = "C:\英語おべんきょ"

# 出力ファイルのために現在の日付を取得
$date = (Get-Date).ToString("yyyy-MM-dd")

# CSVファイルの存在を確認
if (-Not (Test-Path -Path $csvFilePath)) {
    Write-Host "エラー: CSVファイルが見つかりません: $csvFilePath"
    exit
}

# テキストファイルの存在を確認
if (-Not (Test-Path -Path $textFilePath)) {
    Write-Host "エラー: テキストファイルが見つかりません: $textFilePath"
    exit
}

# CSVを変数にインポート
$words = Import-Csv -Path $csvFilePath

# ユーザーにカラムを選ばせる
Write-Host "穴埋め(  )部分へと変換したい品詞を選び、数字を入力してください。:" -ForegroundColor Cyan
Write-Host "1: 動詞" -ForegroundColor Yellow
Write-Host "2: 形容詞" -ForegroundColor Yellow
Write-Host "3: 副詞" -ForegroundColor Yellow
Write-Host "4: 前置詞・助詞" -ForegroundColor Yellow
$selectedColumn = Read-Host "番号を入力 (1~4)"

# ユーザーの入力を対応するカラムにマッピング
$columns = @("Verbs", "Adjectives", "Adverbs", "Prepositions")
if ($selectedColumn -match "^[1-4]$") {
    $columnName = $columns[$selectedColumn - 1]
} else {
    Write-Host "無効な選択です! 1から4までの番号を入力してください。" -ForegroundColor Red
    exit
}

# 選択したカラムから単語を取得
if (-Not ($words | Select-Object -ExpandProperty $columnName -ErrorAction SilentlyContinue)) {
    Write-Host "エラー: CSVファイル内に '$columnName' カラムが見つかりません。" -ForegroundColor Red
    exit
}
$selectedWords = $words | Select-Object -ExpandProperty $columnName

# 元のテキストファイルの内容をバイトエンコーディングで読み込む
$bytes = Get-Content -Path $textFilePath -Raw -Encoding Byte
$textContent = [System.Text.Encoding]::UTF8.GetString($bytes)

# テキスト内の各単語を空白として置き換える (   ) 形式
foreach ($word in $selectedWords) {
    if ([string]::IsNullOrWhiteSpace($word)) {
        continue # 空または null の単語をスキップ
    }
    $escapedWord = [regex]::Escape($word)
    $blank = '(' + (' ' * $word.Length) + ')'
    $textContent = $textContent -replace "\b$escapedWord\b", $blank
}

# 出力ファイルパスを準備
$outputFilePath = Join-Path -Path $outputDirectory -ChildPath "${columnName}_$date.txt"

# 新しい内容をUTF-8エンコーディングで出力ファイルに保存
try {
    [System.IO.File]::WriteAllText($outputFilePath, $textContent, [System.Text.Encoding]::UTF8)
    Write-Host "出力が保存されました: $outputFilePath" -ForegroundColor Green
} catch {
    Write-Host "エラー: 出力ファイルを保存できませんでした。 $_" -ForegroundColor Red
}

つかいかた

・1から4の数字を入力して、空欄にしたい品詞をえらびます。
・指定したフォルダに出力されます。
image.png

ポエム

・穴埋め問題は、おそらく、英語力をみがくのにもっともてっとり早い方法です。
・おっさんが高校生のとき、問題集をアナログコピーして修正ペンで穴埋めをつくって、それをさらにコピーして印刷、という方法で同じことやってました。
・放課後に女子といっしょにコピー機をつかって勉強したり。アナログ作業ならではの甘酸っぱい青春。そして振られるまでがセット。
・いまはペンつきiPadでできるし良い時代になったものですね。
・おっさんはもう必要ありませんが若い皆様の未来のためになればと思い作成いたしました。

追記

DeepL APIなどで、自動翻訳の処理を最初に入れても面白いかも。
・高校の先生とかでガッツリ必要な方はためしてみてはいかがでしょうか。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?