MeCab(Japanese Morphological Analyzer) bindings for flutter on all platforms. Try it out in the browser!.
Android | iOS | Windows | MacOS | Linux | Web | Web --wasm |
---|---|---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
- Add this plug_in as a dependency in your pubspec.yaml file.
dependencies:
mecab_for_flutter: <your_version>
On dart:io
platforms this plugin ships with the necessary mecab binaries.
On web this package expects that the libraries are in assets/blobs/
.
Alternatively, the init
constructor can be used with a custom path.
You can get a precompiled version here.
For more details about the binaries see
Init Mecab:
var tagger = new Mecab();
await tagger.initFlutter("path/to/your/dictionary/", true);
Set the boolean option in init
function to true
if you want to get the tokens including features,
set it to false
if you only want the token surfaces.
Use the tagger to parse text:
var tokens = tagger.parse('にわにわにわにわとりがいる。');
var text = '';
for(var token in tokens) {
text += token.surface + "\t";
for(var i = 0; i < token.features.length; i++) {
text += token.features[i];
if(i + 1 < token.features.length) {
text += ",";
}
}
text += "\n";
}
For a more detailed example see the ./example/.