Run Mecab on Win10 + Eclipse + Java + cmecab-java (January 2020)

Since we set it up through trial and error, we have not confirmed the reproduction of this procedure.

Mecab setup

The Windows version distributed at the head family is a 32bit version and it seems that it is not suitable for use from 64bit Java, so we introduced the 64bit version distributed as a stray build

Mecab 64bit download

https://github.com/ikegami-yukino/mecab/releases/tag/v0.996

Mecab 64bit installation

Installation directory C: \ Program Files \ MeCab Character encoding UTF-8 Introduced by specifying

Mecab 64bit installation result

Although the characters are garbled, it started to work for the time being.

>mecab
It's nice weather today.
Today is a good day,荳 € 闊 ャ,*,*,*,*,*
V locust plague, locust plague, gimlet, locust, locust*,*,*,*
險 伜 捷,荳 € 闊 ャ,*,*,*,*,*
C Locust plague, locust plague, gimlet, locust, locust*,*,*,*
險 伜 捷,荳 € 闊 ャ,*,*,*,*,*
Locust plague, locust plague, locust plague, locust plague, locust plague*,*,*,*
暪 伜 捷,荳 € 闊 ャ,*,*,*,*,*
B Locust plague, locust plague, gimlet, locust, locust*,*,*,*
EOS
^Z

Copy of Mecab 64bit DLL

"C:\Program Files\MeCab\bin\libmecab.dll" To "C:\Windows\System32\libmecab.dll" I copied it to.

setup and build of cmecab-java

cmecab-java download

https://code.google.com/archive/p/cmecab-java/downloads

I downloaded cmecab-java-2.0.1-src.zip.

cmecab-java build work

Extract cmecab-java-2.0.1-src.zip and copy it to your Eclipse workspace. When I ant run build.xml, cmecab-2.0.jar is output under bin. (Since the bin directory is not displayed in Package Explorer of Eclipse, I checked it in Explorer of Windows.)

It looked like this in Eclipse. Clipboard01.png

Creating projects and programs using cmecab-java

Create a Java project and set cmecab-2.0.jar and bridj-0.6.1 in the classpath

Clipboard02.png

Create the following sample code (Although it is almost the same as the head family, the sample code was not displayed well in the head family, so I made a clean copy.)

// https://code.google.com/archive/p/cmecab-java/wikis/HowToUse.wiki
import net.moraleboost.mecab.Lattice;
import net.moraleboost.mecab.Node;
import net.moraleboost.mecab.impl.StandardTagger;

public class HelloMecabMain {
	public static void main(String[] args) throws Exception {
//Build Tagger.
//In the argument, createTagger of MeCab()Give the argument to give to the function.
		StandardTagger tagger = new StandardTagger("");
//Get version string
		System.out.println("MeCab version " + tagger.version());
//Build Lattice (an object that stores runtime information required for morphological analysis)
		Lattice lattice = tagger.createLattice();
//Set the analysis target character string
		String text = "It is a good weather today.";
		lattice.setSentence(text);
//tagger.parse()Is called to morphologically analyze the character string.
		tagger.parse(lattice);
//Output morphological analysis results
		System.out.println(lattice.toString());
//Output surface shape and features while tracing morphemes one by one
		Node node = lattice.bosNode();
		while (node != null) {
			String surface = node.surface();
			String feature = node.feature();
			System.out.println(surface + "\t" + feature);
			node = node.next();
		}
//lattice,Destroy tagger
		lattice.destroy();
		tagger.destroy();
	}
}

Execution result

MeCab version 0.996
Noun today,Adverbs possible,*,*,*,*,today,today,Kyo
Is a particle,Particle,*,*,*,*,Is,C,Wow
Good adjective,Independence,*,*,Adjective, good,Uninflected word,Good,good,good
Weather noun,General,*,*,*,*,weather,weather,weather
Auxiliary verb,*,*,*,Special Death,Uninflected word,is,death,death
.. symbol,Kuten,*,*,*,*,。,。,。
EOS

	BOS/EOS,*,*,*,*,*,*,*,*
Noun today,Adverbs possible,*,*,*,*,today,today,Kyo
Is a particle,Particle,*,*,*,*,Is,C,Wow
Good adjective,Independence,*,*,Adjective, good,Uninflected word,Good,good,good
Weather noun,General,*,*,*,*,weather,weather,weather
Auxiliary verb,*,*,*,Special Death,Uninflected word,is,death,death
.. symbol,Kuten,*,*,*,*,。,。,。
	BOS/EOS,*,*,*,*,*,*,*,*

Impressions

It is difficult to build an environment related to Mecab. I thought it would be nice if there was an OS-independent execution environment. I think that Mecab is not so troublesome for research purposes or to run alone, but there are problems in using it for full-scale text analysis and as a business application in the presence of various execution environments. I wondered.

reference

Referenced page

I had a hard time binding MeCab and eclipse-Sakaiaka's blog http://sakaiakas.hatenablog.com/entry/2018/02/20/231719

Try using MeCab with Python (Windows 10 64bit) --Qiita https://qiita.com/wanko5296/items/eeb7865ee71a7b9f1a3a

Recommended Posts

Run Mecab on Win10 + Eclipse + Java + cmecab-java (January 2020)
Run kuromoji on Win10 + Eclipse + Java environment (January 2020 version)
Run PostgreSQL on Java
How to run Java EE Tutial on github on Eclipse
Run java applet on ubuntu
Run Eclipse CDT on Ubuntu
Run Java EE applications on CICS
Run tomcat shell script on java8
Run jooby's Eclipse development environment on Gradle
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
[Tutorial] Download Eclipse → Run the application with Java (Pleiades)
[Tutorial] Download Eclipse → Run Web application with Java (Pleiades)