私は次のことに苦労しています。
特定の形式でmoodle(オンライン質問サイト)にインポートする必要がある質問と回答を含むWordファイルがあります。すべてが黒で、正しい答えを受け入れます。これらは緑です。開始形式は次のとおりです。
1. Question example
a. Wrong
b. Wrong
C. Wrong
D. Right
出力は次のようになります。
:Question example
:Question example
{
~ Wrong
~ Wrong
~ Wrong
= Right
}
Word でファイルを開き、赤い段落記号をすべて * に置き換えます (グループで置き換えることはできません)。その後、.docx ファイルをテキストにエクスポートします。Linux コンピューターで開き、次の正規表現をスローします。
sed -i -e 's/^\r/\n/g' tmp #OS X white line replacement
sed -i -e 's/\r//g' tmp #remove white lines
sed -i -e 's:^[a-z]\.:~:' tmp #Replace Leading question letters with tilde
sed -i -e 's/\(^[0-9]*\.\ \)\(.*\)/}\n::\2\n::\2\n{/' tmp #regenerate tittle
sed -i -n '${p;q};N;/\n\*/{s/"\?\n//p;b};P;D' tmp #next line starts with * append to front of current
sed -i -e 's:^~\(.*\)\(\*.*\)$:=\1:' tmp #move * from back to = to front
sed -i -e 's:^\*:=:' tmp #replace any remaining * with =
sed '/^$/d' tmp #delete any remaining white lines
これは素晴らしいものではありませんが、うまく機能します。質問は手作りで、多くのエラーがあるため、これを手動で処理する必要があります。難しいのは、複数の正解がある場合です。出力は次のようになります。
:Question example
:Question example
{
~%-100% Wrong
~%-100% Wrong
~%50% Right
~%50% Right
}
理想的には、{ の間の = の数をカウントし、それらを ~%50% に置き換える sed または perl 正規表現があります。そして、すべての ~ は %-100% で歌います。このコードは、すべての正解が ~%33% になる 3 つの正解に対しても使用できます。
これは実行可能ですか?1000 を超える質問がありますが、これを自動化すると確実に役立ちます。sed による複数行の置換は 2 行ではややこしいので、4 行以上は perl が必要になると思いますか? 私はPerlの経験がありません。
誰かがこれで私を助けてくれますか? 私の悪い英語を許してください。私は非ネイティブ スピーカーです。