Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

hankcs/HanLPAndroidDemo

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

HanLP Android Demo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.