LoginSignup
1
0

英文を読むときに,単語帳を作ります。

1 文字飾りのない,文字ファイル(text file)を作る。

ソフトウェアによっては,文字ファイル出力ができないものがあります。
そういう場合には,文字を複写し,貼付ける方法を取ることがあります。
貼付ける際に,対応する文字コードが違うと,文字化けすることがあります。

2 大文字を小文字に変換する。

固有名詞かどうかはひとまず気にせずに,綴りだけを識別したいので,大文字を小文字に変換します。

tr(translate characters)コマンドを使います。unix, linux, mac osxに標準同梱しています。
Windowsの場合はcygwinを導入します。

  1. ファイル内の大文字・小文字を変換するには
    http://www.atmarkit.co.jp/flinux/rensai/linuxtips/237cngl2s.html

  2. 【 tr 】 文字を一括変換する
    http://itpro.nikkeibp.co.jp/article/COLUMN/20060227/230906/

  3. OS Xとかで"tr: Illegal byte sequence"とか怒られちゃう場合
    http://d.hatena.ne.jp/pasela/20120710/random

1 tr [:upper:] [:lower:] T.txt
説明が出る。

2 tr [:upper:] [:lower:] t2.txt
tr: Illegal byte sequence

3 tr A-Z a-z t2.txt

4 LC_CTYPE=C tr -A-Z a-z t2.txt
tr: illegal option -- A

5 LC_TYPE=C tr A-Z a-z t2.txt

3. 不要な文字を除去しながら単語を計数

プログラミング言語AWK
プログラミング言語AWK (新紀元社情報工学シリーズ)
http://www.amazon.co.jp/dp/4775302493
51T83XNMG7L.SL160.jpg

A. V. エイホ, P. J. ワインバーガー, B. W. カーニハン, Alfred V. Aho, Peter J. Weinberger, Brian W. Kernighan, 足立 高徳
新紀元社(2004/01)

fw.awk
{ 
gsub(/[`'&%$-/.,:;!?^*_~=|@\\\#<>(){}0123456789\[\]"]/," ") 
for (i=1;i<=NF;i++) 
count[$i]++ 
} 
END {for (w in count) 
print w,count[w] | "sort -f" 
}

wf.awkというファイルに保存。

$ awk -f wf.awk t2.txt
  1. awk -f wf.awk t2.txt
awk: nonterminated character class [`'&%$-
 source line number 2 source file wf.awk
 context is
>>> gsub(/[`'&%$-/. <<< ,:;!?^*_~=|@\\\#<>(){}0123456789\[\]"]/," ") 
  1. /を削除(/.を削除とかいていたそれだと.が残る)
awk -f wf.awk t2.txt 
sort: string comparison failed: Illegal byte sequence
sort: Set LC_ALL='C' to work around the problem.
  1. LC_TYPE=C awk -f wf.awk t2.txt

  2. more t2.txt
    で,制御文字を見て,削るか変換する。
    例えば,'が制御文字であれば,'に置換する。
    "が制御文字の場合に"に空白を入れて置換する。

^Mがついた文字がある。
エディタで保存をMacintosh CR から
Windows CR LF
に変更して保存。

参考文献(reference)

文字列の出現回数を調べるawk
https://qiita.com/oshiro/items/11b6833aa41627723059

英語論文・規格・特許を読むときの作業記録
https://researchmap.jp/jorteykhj-51292/

GCC コメント除去、単語計算
https://researchmap.jp/joo4thhg9-1778110/

文書分析 出現頻度と共出現率
https://researchmap.jp/jo34x0vvk-45644/

文書履歴(document history)

ver. 0.01 初稿 20190430 昼x
ver. 0.02 参考文献追記 20190430 午後
ver. 0.03 ありがとう追記   20230529

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

1
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
1
0