[JAVA] Mecab installation that can be done almost by typing a command

I wrote it because I was addicted to it. It's mostly because of System.loadLibrary ...

environment

macOS High Sierra

download

http://taku910.github.io/mecab/#download

--MeCab body (mecab-0.996.tar.gz) --Dictionary file (mecab-ipadic-2.7.0-20070801.tar.gz) --Java binding (mecab-java-0.996.tar.gz)

Installation of the main unit

$ tar zxfv mecab-0.996.tar.gz

$ cd mecab-0.996

$ ./configure $ make $ make check $ sudo make install

Dictionaries installation

$ cd ../ $ tar zxfv mecab-ipadic-2.7.0-20070801.tar.gz $ cd mecab-ipadic-2.7.0-20070801

$ ./configure --with-charset=utf8 --enable-utf8-only $ make $ make install

(* There are quite a few articles that manually switch the configuration file, but it is unnecessary) (If you set the --with-charset = utf8 --enable-utf8-only option to the configure command, the process of converting the dictionary file encoding from EUC to UTF-8 will run. At this time, UTF-8 will be manually executed. If you switch to, the encoding of the original file is not EUC, so it will fail with an error.)

If the settings are incorrect, the following error will occur.

iconv conversion failed. skip this entry:... 

Verification

$ mecab
Good morning
Good morning interjection,*,*,*,*,*,Good morning,Ohayou,Ohayo
Auxiliary verb,*,*,*,5th Dan / La Line Special,Continuous form,Gozaru,Gozai,Gozai
Auxiliary verb,*,*,*,Special / mass,Uninflected word,Masu,trout,trout
EOS

(* Enter "Good morning" on the second line by yourself)

Install the latest version of the JDK

Java SE Development Kit 9 Downloads (* Please search and download the latest version) (* 8 may not work)

Binding to Java

$ cd ../ $ tar zxfv mecab-java-0.996.tar.gz $ cd mecab-java-0.996

$ vi Makefile

INCLUDE=/usr/lib/jvm/java-6-openjdk/include ↓ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers

(* An error occurred when the following folder was specified) INCLUDE=/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/include

$ sudo make
Password:
c++ -O3 -c -fpic MeCab_wrap.cxx  `mecab-config --cflags` -I/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/include/linux
In file included from MeCab_wrap.cxx:159:
/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/include/jni.h:45:10: fatal error: 
      'jni_md.h' file not found
#include "jni_md.h"
         ^~~~~~~~~~
1 error generated.
make: *** [all] Error 1

$ make

(A lot of warnings will be issued, but it is OK if two files, MeCab.jar and libMeCab.so, are generated.)

$ javac -cp MeCab.jar test.java
test.java:7:error:An error occurred while writing test: /usr/local/lib/mecab-java/test.class
public class test {
       ^
1 error

Rename folder

Rename and move the folder to make it easier to manage.

$ cd ../ $ mv mecab-java-0.996 mecab-java $ mv mecab-java /usr/local/lib/mecab-java

Modifications to be made to run the verification program

Fixed the confirmation program test.java (loadLibrary did not load MeCab well in my environment ...) System.loadLibrary("MeCab"); ↓ System.load("/usr/local/lib/mecab-java/libMeCab.so");

$ sudo javac -cp MeCab.jar test.java $ sudo java -cp MeCab.jar:. test


bash-3.2$ java -cp MeCab.jar:. test
0.996
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Jiro,Jiro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

	BOS/EOS,*,*,*,*,*,*,*,*
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Jiro,Jiro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
	BOS/EOS,*,*,*,*,*,*,*,*
EOS

Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Jiro,Jiro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

Taro handed this book to Jiro.
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Jiro,Jiro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

	BOS/EOS,*,*,*,*,*,*,*,*
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Jiro,Jiro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
	BOS/EOS,*,*,*,*,*,*,*,*
EOS

nbest:0
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Jiro,Jiro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:1
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Two nouns,number,*,*,*,*,two,D,D
Ro noun,General,*,*,*,*,Ro,Rowe,Low
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:2
Taro noun,Proper noun,area,General,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Jiro,Jiro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:3
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,General,*,*,*,Jiro,Niro,Niro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:4
Taro noun,Proper noun,area,General,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Two nouns,number,*,*,*,*,two,D,D
Ro noun,General,*,*,*,*,Ro,Rowe,Low
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:5
Taro noun,Proper noun,area,General,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,General,*,*,*,Jiro,Niro,Niro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:6
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Two nouns,number,*,*,*,*,two,D,D
Ro noun,General,*,*,*,*,Ro,Rowe,Low
Particles,Adverbization,*,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:7
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Niro,Niro
Particles,Case particles,General,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:8
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Jiro noun,Proper noun,Personal name,Name,*,*,Jiro,Jiro,Jiro
Particles,Adverbization,*,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

nbest:9
Taro noun,Proper noun,area,General,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
Two nouns,number,*,*,*,*,two,D,D
Ro noun,General,*,*,*,*,Ro,Rowe,Low
Particles,Adverbization,*,*,*,*,To,D,D
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

Recommended Posts

Mecab installation that can be done almost by typing a command
Object-oriented that can be understood by fairies
Write a class that can be ordered in Java
I tried a puzzle that can only be solved by the bottom 10% of bad engineers
Create a page control that can be used with RecyclerView
Create a jar file that can be executed in Gradle
Find a Switch statement that can be converted to a Switch expression
How to make a key pair of ecdsa in a format that can be read by Java
I made a question that can be used for a technical interview
Settings that should be done when operating a production environment with Rails