mecab_dart 0.1.3
mecab_dart: ^0.1.3 copied to clipboard

Flutter plugin which provides binding to Mecab library (Japanese Morphological Analyzer) on iOS and Android

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:mecab_dart/mecab_dart.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String text = "";
  var tagger = new Mecab();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    String platformVersion;    
    try {
      platformVersion = await MecabDart.platformVersion;

      // Initialize mecab tagger here 
      //   + 1st parameter : dictionary asset folder
      //   + 2nd parameter : additional mecab options      
      await tagger.init("assets/ipadic", true);

      var tokens = tagger.parse('にわにわにわにわとりがいる。');

      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";
      }

    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text(text),
        ),
      ),
    );
  }
}
6
likes
110
pub points
53%
popularity

Flutter plugin which provides binding to Mecab library (Japanese Morphological Analyzer) on iOS and Android

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

ffi, flutter, path_provider

More

Packages that depend on mecab_dart