Help us understand the problem. What is going on with this article?

【python】テキスト処理に使えるTextBlobを使う

More than 1 year has passed since last update.

はじめに

テキスト処理に使えるライブラリであるTextBlob

  • 翻訳
  • 名詞抽出
  • 感情分析
  • タグ付け

など、テキスト処理において幅広い用途で使用される。
面白そうなので遊ぶ。

翻訳

英語->日本語

translate.py
from textblob import TextBlob

analysis = TextBlob("TextBlob sure looks like it has some interesting features")
print(analysis)
print(analysis.translate(to='ja'))

結果

$ python translate.py 
TextBlob sure looks like it has some interesting features
TextBlobには興味深い機能があるようです

おぉ、きちんと翻訳されとる。。。
では逆に日本語対応しているのか??

日本語->英語

translate.py
from textblob import TextBlob

analysis = TextBlob("TextBlobには興味深い機能があるようです")
print(analysis)
print(analysis.translate(to='en'))

結果

$ python translate.py 
TextBlobには興味深い機能があるようです
TextBlob seems to have an interesting function

できてるっぽいぞ。。。

そのほか少し。

その他

test.py
# 言語抽出
analysis = TextBlob("TextBlob sure looks like it has some interesting features")
print(analysis.detect_language())
# => en

# 単語のリスト
print(analysis.words)
# => ['TextBlob', 'sure', 'looks', 'like', 'it', 'has', 'some', 'interesting', 'features']

# 単語の出現回数
print(analysis.words.count("looks"))
# => 1

# 単語のタグ付け
print(analysis.tags)
# => [('TextBlob', 'NNP'), ('sure', 'JJ'), ('looks', 'VBZ'), ('like', 'IN'), ('it', 'PRP'), ('has', 'VBZ'), ('some', 'DT'), ('interesting', 'JJ'), ('features', 'NNS')]

# 感情分析(極性分析)
print(analysis.sentiment)
# => Sentiment(polarity=0.5, subjectivity=0.6944444444444444)

結果

自然言語は表現が多様なのでいろいろ遊べそうだ。
翻訳と感情分類を深堀りしてみるのが面白そうだと感じる。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away