Pythonで辞書に単語を入れる際、mecab 、辞書はNeologdで単語を抽出しています。
実現したいこと
プログラミング自体は動いているのですが、日本語でどう動いているのか表現するのが難しいので、説明してほしいです。
該当のソースコード
#-- coding: utf-8 --
from os import path
import numpy as np
import MeCab
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
current_dir = path.dirname(file)
#input_text = open(path.join(current_dir, 'titles1.txt'), 'r').read()
input_text = open(path.join(current_dir, 'documents2.txt'), 'r').read()
documents2 = input_text.split("|")
def words(text):
"""
文章から単語を抽出
"""
out_words = []
tagger = MeCab.Tagger('-Ochasen -d /usr/local/lib/mecab/dic/mecab-ipadic-neologd -t UTF8')
tagger.parse('')
node = tagger.parseToNode(text)
while node: word_type = node.feature.split(",")[0] if word_type in ["名詞"]: out_words.append(node.surface) print(node.feature) node = node.next return out_words
試したこと
辞書を作り、mecabで単語を切ろうとして、開いているのはわかるのですが、while node;あたりの名詞を特徴?というのがよくわかってないです。ここを重点的に説明してほしいです。
補足情報(FW/ツールのバージョンなど)
macを使っています
あなたの回答
tips
プレビュー