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

ubuntu 18.10 に mecab をインストール

More than 1 year has passed since last update.
sudo apt install mecab
sudo apt install libmecab-dev
sudo apt install mecab-ipadic-utf8

この段階で動作確認

$ mecab
特急はくたか
特急    名詞,一般,*,*,*,*,特急,トッキュウ,トッキュー
は      助詞,係助詞,*,*,*,*,は,ハ,ワ
く      動詞,自立,*,*,カ変・クル,体言接続特殊2,くる,ク,ク
た      助動詞,*,*,*,特殊・タ,基本形,た,タ,タ
か      助詞,副助詞/並立助詞/終助詞,*,*,*,*,か,カ,カ
EOS

neologd をインストール

git clone https://github.com/neologd/mecab-ipadic-neologd.git
cd mecab-ipadic-neologd
sudo bin/install-mecab-ipadic-neologd

/etc/mecabrc を編集する

dicdir = /usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd

この段階で動作確認

$ mecab
特急はくたか
特急    名詞,一般,*,*,*,*,特急,トッキュウ,トッキュー
はくたか        名詞,固有名詞,一般,*,*,*,はくたか,ハクタカ,ハクタカ
EOS

python3 で使えるようにする

sudo apt install swig
sudo apt install python3-pip
sudo pip3 install mecab-python3

サンプルのプログラム

mecab_sample.py
#! /usr/bin/python3
# -*- coding: utf-8 -*-
#
#   mecab_sample.py
#
#                       Jun/02/2018
#
# ----------------------------------------------------------------------
import sys
import MeCab
#
mt = MeCab.Tagger("mecabrc")
str_in="特急はくたかで富山に向かいます。それから、金沢に行って、兼六園に行きます。"
res = mt.parseToNode(str_in)

while res:
#    print (res.surface)
    arr = res.feature.split(",")
    if (arr[1] == "固有名詞"):
        print(res.feature)
        print(arr[6])
    res = res.next
#
# ----------------------------------------------------------------------

実行結果

$ ./mecab_sample.py 
名詞,固有名詞,一般,*,*,*,はくたか,ハクタカ,ハクタカ
はくたか
名詞,固有名詞,地域,一般,*,*,富山,トヤマ,トヤマ
富山
名詞,固有名詞,地域,一般,*,*,金沢,カナザワ,カナザワ
金沢
名詞,固有名詞,地域,一般,*,*,兼六園,ケンロクエン,ケンロクエン
兼六園

次の環境で確認しました。

$ uname -a
Linux iwata 4.18.0-13-generic #14-Ubuntu SMP Wed Dec 5 09:04:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.10 (Cosmic Cuttlefish)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.10"
VERSION_ID="18.10"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=cosmic
UBUNTU_CODENAME=cosmic
Why not register and get more from Qiita?
  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
No 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
ユーザーは見つかりませんでした