I tried using mecab with python2.7, ruby2.3, php7

reference

Installation

sudo apt install -y \
  mecab mecab-ipadic-utf8

Run

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

Run on python2.7

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

Run with ruby 2.3

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

Run in php7

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

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();

Finally executed

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

I tried using mecab with python2.7, ruby2.3, php7
I tried scraping with Python
[Python] I tried using OpenPose
I tried gRPC with Python
I tried scraping with python
I tried hitting Mastodon API with Ruby (Faraday) / Python (Pycurl) / PHP (Curl)
Dynamic proxy with python, ruby, PHP
I tried web scraping with python.
I tried using Thonny (Python / IDE)
I tried running prolog with python 3.8.2.
I tried SMTP communication with Python
When using MeCab with virtualenv python
[Python] I tried using YOLO v3
I tried using Amazon SQS with django-celery
Realize PHP / Python generator with Golang / Ruby
I tried scraping Yahoo News with Python
Using Python and MeCab with Azure Databricks
I tried using Selenium with Headless chrome
I tried sending an email with python.
I tried using Bayesian Optimization in Python
I tried non-photorealistic rendering with Python + opencv
I tried using UnityCloudBuild API from Python
I tried a functional language with Python
I tried recursion with Python ② (Fibonacci sequence)
#I tried something like Vlookup with Python # 2
I tried to make a todo application using bottle with python
I tried using parameterized
I tried "smoothing" the image with Python + OpenCV
I tried using argparse
I tried hundreds of millions of SQLite with python
I tried using mimesis
I tried using anytree
vprof --I tried using the profiler for Python
I tried web scraping using python and selenium
I tried "differentiating" the image with Python + OpenCV
I tried using Summpy
I tried Python> autopep8
Use mecab with Python3
I tried L-Chika with Raspberry Pi 4 (Python edition)
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried Jacobian and partial differential with python
I tried to get CloudWatch data with Python
I tried using Hubot
I tried function synthesis and curry with python
I tried using ESPCN
I tried to output LLVM IR with Python
I tried using openpyxl
I tried "binarizing" the image with Python + OpenCV
I tried using Ipython
I tried using PyCaret
I tried reading a CSV file using Python
I tried using cron
I tried running faiss with python, Go, Rust
I tried using the Datetime module by Python
I tried to automate sushi making with python
I tried using "Streamlit" which can do the Web only with Python
I tried playing mahjong with Python (single mahjong edition)
I tried using ngrok