sudo apt install -y \
mecab mecab-ipadic-utf8
Enter characters at the mecab prompt and press Enter
$ mecab
I am hungry#Press Enter
result
Tummy noun,General,*,*,*,*,Stomach,Onaka,Onaka
Sui verb,Independence,*,*,Five-dan / Ka line,Continuous connection,Suku,Sui,Sui
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
EOS
sudo apt install -y python-mecab
a.py
# coding: utf-8
import MeCab
mt = MeCab.Tagger("-Ochasen")
print mt.parse("I am hungry")
python a.py
result
Tummy Onaka Tummy Noun-General
Sui Sui Suku verb-Independent five-stage, Ka line I sound flight continuous use connection
Ta ta auxiliary verb special ta ta basic form
EOS
sudo apt install -y ruby-mecab
a.rb
require 'MeCab'
m = MeCab::Tagger.new ("-Ochasen")
print m.parse ("I am hungry")
ruby a.rb
result
Tummy Onaka Tummy Noun-General
Sui Sui Suku verb-Independent five-stage, Ka line I sound flight continuous use connection
Ta ta auxiliary verb special ta ta basic form
EOS
sudo apt install -y \
php7.0-cli php7.0-dev libmecab-dev
git clone https://github.com/rsky/php-mecab.git
cd php-mecab
cd mecab
phpize
./configure --with-php-config=/usr/bin/php-config --with-mecab=/usr/bin/mecab-config
make
sudo make install
/usr/lib/php/20151012/mecab.so
.extension registration
sudo sh -c "echo 'extension=mecab.so' > /etc/php/7.0/mods-available/mecab.ini"
sudo ln -s /etc/php/7.0/mods-available/mecab.ini /etc/php/7.0/cli/conf.d/20-mecab.ini
Verification
$ php -i | grep -i mecab
/etc/php/7.0/cli/conf.d/20-mecab.ini,
mecab
MeCab Support => enabled
MeCab Library => 0.996 => 0.996
mecab.default_dicdir => no value => no value
mecab.default_rcfile => no value => no value
mecab.default_userdic => no value => no value
Writing is different in php7
- $mecab = new MeCab_Tagger();
+ $mecab = new \MeCab\Tagger();
a.php
<?php
$str = "I am hungry";
$mecab = new \MeCab\Tagger(array('-O' => 'chasen'));
echo $mecab->parse($str) . PHP_EOL;
php a.php
result
Tummy Onaka Tummy Noun-General
Sui Sui Suku verb-Independent five-stage, Ka line I sound flight continuous use connection
Ta ta auxiliary verb special ta ta basic form
EOS
Recommended Posts