Git Product home page Git Product logo

hanlpandroiddemo's Introduction

HanLP Android 示例

portable版

portable版零配置,仅提供中文分词、简繁拼音、同义词等功能。只需在build.gradle中加入依赖:

dependencies {
    compile 'com.hankcs:hanlp:portable-1.6.8'
}

自定义版

HanLP的全部功能(分词、简繁、拼音、文本分类、句法分析)都兼容安卓,具体配置方法如下:

  1. 下载hanlp.jar放入app/libs
  2. 下载data.zip解压到app/src/main/assets ,按需删除不需要的文件以减小apk体积。
  3. 在程序启动时(通常是MainApplicationMainActivityonCreate方法)执行初始化代码:
    private void initHanLP()
    {
        try
        {
            Os.setenv("HANLP_ROOT", "", true);
        }
        catch (ErrnoException e)
        {
            throw new RuntimeException(e);
        }
        final AssetManager assetManager = getAssets();
        HanLP.Config.IOAdapter = new IIOAdapter()
        {
            @Override
            public InputStream open(String path) throws IOException
            {
                return assetManager.open(path);
            }

            @Override
            public OutputStream create(String path) throws IOException
            {
                throw new IllegalAccessError("不支持写入" + path + "!请在编译前将需要的数据放入app/src/main/assets/data");
            }
        };
    }

之后就可以像普通Java项目一样调用HanLP的全部功能了。

欢迎参考HanLP文档以了解更多信息。

screenshot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.