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?

More than 3 years have passed since last update.

WindowにおけるMecabのコマンドプロンプトについて。

Last updated at Posted at 2021-06-23

##問題点

コマンドプロンプトでMeCabを実行すると...。

SS_2021-6-23_17-48-32_No-00.png

まあ、文字化けします。

対策としてはコマンドプロンプトの文字コードを変更するとかありますが、いちいちやるのがめんどくさい。

#対応策

以下の mecab_cmd.py と mecab_cmd.bat を作成します。

mecab_cmd.py
import MeCab
tagger = MeCab.Tagger()

def CMD():
    while True:
        sentence = input("> ")
        parsed_items = tagger.parse(sentence).split("\n")[:-2]
        for parse_item in parsed_items:
            token, positions = parse_item.split("\t")
            print(token + "\t" + "".join(positions))

if __name__=="__main__":
    CMD()
mecab_cmd.py
python mecab_cmd.py

あとは、このBatchファイルのショートカットを作るだけ。

実行すると、

SS_2021-6-23_17-55-37_No-00.png

以上!

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?