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?

Janomeで日本語の詩的テキストを形態素解析する(andymori andyとrock)

Posted at

Janomeで日本語の詩的テキストを形態素解析する方法

日本語の自然言語処理では、形態素解析が非常に重要です。特に詩的な表現や歌詞など、文法が崩れていたり、口語的だったりする文章では、一般的な処理系ではうまく解析できない場合があります。

この記事では、Pythonの日本語形態素解析ライブラリ「Janome」を使って、詩的な日本語フレーズをトークンに分解し、各要素の詳細情報を出力する方法をご紹介します。


使用するライブラリ:Janome

Janomeは日本語形態素解析の軽量ライブラリで、以下のような特徴があります:

  • Pure Pythonで動作(C依存なし)
  • MeCabなどの事前インストール不要
  • 自作辞書追加なども可能

まずはインストールから始めましょう。

!pip install janome

解析する日本語フレーズ

今回対象とするのは、以下の詩的な日本語の一文です:

アンプ蹴ったらギャンギャンないた15ワットの小さな世界が アンプを蹴りとばしたんだ

andymori andyとrock という曲のフレーズです。
image.png


Pythonコードの解説

# janome_token_analysis.py

# -*- coding: utf-8 -*-
# Program: janome_token_analysis.py
# Purpose: Analyze Japanese poetic phrase using Janome Tokenizer
# 目的:Janomeを用いて日本語詩的表現の形態素解析を行う

from janome.tokenizer import Tokenizer

# Tokenizerのインスタンスを生成 / Create a Tokenizer instance
tokenizer = Tokenizer()

# 対象テキストの定義 / Define input text
text = "アンプ蹴ったらギャンギャンないた15ワットの小さな世界が アンプを蹴りとばしたんだ"

# トークン化実行 / Tokenize the text
tokens = tokenizer.tokenize(text)

# 各トークンの詳細情報を出力 / Print details of each token
for token in tokens:
    print(token)  # 全情報の出力 / Full token information
    print("読み (Reading):", token.reading)  # ヨミガナ / Pronunciation
    print("原形 (Base form):", token.base_form)  # 原形 / Base form
    print("品詞情報 (Part of Speech):", token.part_of_speech)  # 品詞情報 / Part of speech
    print("品詞リスト (POS List):", token.part_of_speech.split(','))  # リスト形式に変換 / POS as list
    print("品詞カテゴリ (POS Category):", token.part_of_speech.split(',')[0])  # 主品詞 / Main POS
    print("-----")  # 区切り線 / Separator

実行結果

image.png
image.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?