GiNZA - Japanese NLP Library
の使い方です。
インストール
pip install -U ginza ja-ginza
パスを通す
export PATH=$PATH:/home/uchida/.local/bin
固有名詞の抽出を行いました。
こちらと同じプログラムです。
ubuntu 21.10 に mecab をインストール
pickup_propn.py
#! /usr/bin/python
#
# pickup_propn.py
# Nov/26/2021
#
import spacy
nlp = spacy.load('ja_ginza')
text_in = "特急はくたかで富山に向かいます。それから、金沢に行って、兼六園に行きます。"
doc = nlp(text_in)
for sent in doc.sents:
for token in sent:
if token.pos_ == "PROPN":
print(token.orth_, token.tag_)
#
実行結果
$ ./pickup_propn.py
富山 名詞-固有名詞-地名-一般
金沢 名詞-固有名詞-地名-一般