Install mecab on Sakura shared server and call it from python

Overview

In this article Install mecab with UTF-8 on Sakura shared server. After that, call mecab from python and try morphological analysis. Sakura rental server is not granted root privileges, so Install in the user directory.

Prerequisites

-The commands in the procedure are described in bash. How to change to bash Check the supplement "Standardize bash on Sakura rental server"!

What to install

・ Mecab body (mecab-0.996) ・ Mecab dictionary -Python package management system pip ・ Mecab-python

procedure

Installation of mecab body

(1) Download mecab from the following site. http://taku910.github.io/mecab/#download

(2) Unzip the mecab body Unzip the body with the tar command tar xvfz ./mecab-0.996.tar.gz

(3) Move to the unzipped directory cd mecab-0.996

(4) Compile and build Type the following command to install in the user directory ./configure --prefix=$HOME/local --with-charset=utf8 --enable-utf8-only

make make install

In my environment, it was installed in the following location. ~/local/bin/mecab

(5) Check if it is installed mecab -v If it is installed normally, you can type the above command to "mecab of 0.996" A log like this is displayed.

Insert the ipa dictionary

(1) Download the mecab dictionary and ipa dictionary from the following sites. http://taku910.github.io/mecab/#download

(2) Unzip the ipa dictionary tar xvzf mecab-ipadic-2.7.0-20070801.tar.gz

(3) Move to the dictionary folder cd mecab-ipadic-2.7.0-20070801

(4) Type the following command to install in the user directory The character code of the dictionary is utf-8. The reason for using utf-8 is to call it on the WEB. ./configure --with-charset=utf8

However, even if you set it to utf-8 here, after running mecab, The character code of the output result may remain EUC.

In that case, in "mecab-ipadic-2.7.0-20070801" Converts files with "csv" and "def" extensions to UTF-8 and overwrites them.

Command to convert to UTF-8 and command to confirm it nkf -w --overwrite *.csv nkf -w --overwrite *.def nkf --guess *.*

reference How to use mecab with Sakura shared server, UTF-8 dictionary http://nymemo.com/sakura/258/

(5) Compile and build Type the following command to install in the user directory

make make install

In my environment, the dictionary was installed in the following location. ~/local/lib/mecab/dic/ipadic

Operation check of mecab

Specify the dictionary as shown below and start mecab.

mecab -d ~/local/lib/mecab/dic/ipadic The terminal setting is UTF-8.

If successful, the following will be displayed.

[home@www1635 ~/local/etc]$ mecab -d ~/local/lib/mecab/dic/ipadic Of the thighs and thighs Plum noun, general, *, *, *, *, plum, plum, plum Mo particle, particle, *, *, *, *, mo, mo, mo Peach noun, general, *, *, *, *, peach, peach, peach Mo particle, particle, *, *, *, *, mo, mo, mo Peach noun, general, *, *, *, *, peach, peach, peach Particles, adnominal forms, *, *, *, *, of, no, no Of which nouns, non-independent, adverbs possible, *, *, *, of which, Uchi, Uchi EOS

Install the python library

Install pip.

The reason for installing pip is to install mecab-python using pip.

easy_install --prefix=~/.local pip

Confirm that pip is installed

[home@www1635 ~/local/etc]$ pip --version pip 9.0.1 from /home/homedir/.local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)

install mecab-python

pip install mecab-python --user The reason why --user is attached is that the Sakura server does not have root privileges, so install it in the user directory.

Run mecab with python

Write this source code.

sample.py


# coding: UTF-8

import MeCab

#Specify the location of the dictionary (for some reason it will not work unless you specify it with the full path)
userdic_path="-d /home/homedir/local/lib/mecab/dic/ipadic"
t = MeCab.Tagger("-Ochasen " + userdic_path)

text = u'Of the thighs and thighs'
encoded_text = text.encode('utf-8')# 
meData = t.parse(encoded_text )
print meData

When executed, the following statement will be output ʻA Plum Plum Noun-General Momo particle-particle Peach Peach Noun-General Momo particle-particle Peach Peach Noun-General Nono particle-attributive form Uchi Uchi Noun-Non-independence-Adverb possible EOS `

that's all! Next, I will write an article on how to display the execution result of MeCab on a WEB browser.

Supplement

Standardize bash on Sakura rental server http://note.sicafe.net/sakuraVPS/sakura_vimInstall.html

Recommended Posts

Install mecab on Sakura shared server and call it from python
Install lp_solve on Mac OS X and call it with python.
Install Mecab and CaboCha on ubuntu16.04LTS so that it can be used from python3 series
Install selenium on Mac and try it with python
Install django on python + anaconda and start the server
Install CaboCha in Ubuntu environment and call it with Python.
Install Mecab and mecab-python3 on Ubuntu 14.04
Notes on using MeCab from Python
Call C / C ++ from Python on Mac
How to install OpenCV on Cloud9 and run it in Python
From Python to using MeCab (and CaboCha)
Install and Configure TigerVNC server on Linux
Install Python3 on mixhost server [Currently NG]
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Deploy Python face recognition model on Heroku and use it from Flutter ②
Deploy Python face recognition model on Heroku and use it from Flutter ①
Set cron from 1 on Ubuntu 16.04 (Sakura VPS) and execute python program regularly
[python] Send the image captured from the webcam to the server and save it
Install Python3 and Django on Amazon Linux (EC2) and run your web server
MeCab from Python
Install Chrome on the command line on Sakura VPS (Ubuntu) and launch Chrome with python from virtual display and selenium
I want to pass an argument to a python function and execute it from PHP on a web server
Install and run Python3.5 + NumPy + SciPy on Windows 10
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
PHP and Python integration from scratch on Laravel
Building a Python environment on a Sakura VPS server
Install MongoDB on Ubuntu 16.04 and operate via python
Install Python and libraries for Python on MacOS Catalina
Install ZIP version Python and pip on Windows 10
Until you install Python with pythonbrew and run Flask on a WSGI server
Install mecab on Marvericks
Install python on WSL
Install Python3 on Mac and build environment [Definitive Edition]
[Python3] Take a screenshot of a web page on the server and crop it further
Install Python on Pidora.
Install Scrapy on python3
Install Python on Mac
Install Python 3 on Mac
Install python from source
Install Python3.4 on CentOS 6.6
Install PyCall on Raspberry PI and try using GPIO's library for Python from Ruby
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Install python on windows
Get mail from Gmail and label it with Python3
Compile and install MySQL-python for python2.7 on amazon linux
Install Python 2.7.3 on CentOS 5.4
Install Docker on Arch Linux and run it remotely
Install Python 3.3 on Ubuntu 12.04
Install pyenv on Raspberry Pi and version control Python
Install Python 3.4 on Mac
Install mecab on mac
Install Python 3.6 on Docker
Call the API of Hatena Blog from Python and save your blog articles individually on your PC
I made a server with Python socket and ssl and tried to access it from a browser
Put Ubuntu in Raspi, put Docker on it, and control GPIO with python from the container
Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)
Install pyenv on MacBook Air and switch python to use
[Python] I installed the game from pip and played it
Install python and Visual Studio Code on windows10 (April 2020 version)
Go language to see and remember Part 8 Call GO language from Python
Call CPLEX from Python (DO cplex)