Giter Club home page Giter Club logo

vicword's Introduction

VicWord 一个纯php的分词

QQ交流群: 731475644

安装

composer require lizhichao/word

分词说明

  • 含有3种切分方法
    • getWord 长度优先切分 。最快
    • getShortWord 细粒度切分。比最快慢一点点
    • getAutoWord 自动切分 。效果最好
  • 可自定义词典,自己添加词语到词库,词库支持文本格式json和二级制格式igb 二进制格式词典小,加载快
  • dict.igb含有175662个词,欢迎大家补充词语到 dict.txt ,格式(词语 \t idf \t 词性)
    • idf 获取方法 百度搜索这个词语 Math.log(100000001/结果数量),如果你有更好的方法欢迎补充。
    • 词性 [标点符号,名词,动词,形容词,区别词,代词,数词,量词,副词,介词,连词,助词,语气词,拟声词,叹词] 取index ;标点符号取0
  • 三种分词结果对比
$fc = new VicWord();
$arr = $fc->getWord('北京大学生喝进口红酒,在北京大学生活区喝进口红酒');
//北京大学|生喝|进口|红酒|,|在|北京大学|生活区|喝|进口|红酒
//$arr 是一个数组 每个单元的结构[词语,词语位置,词性,这个词语是否包含在词典中] 这里只值列出了词语

$arr =  $fc->getShortWord('北京大学生喝进口红酒,在北京大学生活区喝进口红酒');
//北京|大学|生喝|进口|红酒|,|在|北京|大学|生活|区喝|进口|红酒

$arr = $fc->getAutoWord('北京大学生喝进口红酒,在北京大学生活区喝进口红酒');
//北京|大学生|喝|进口|红酒|,|在|北京大学|生活区|喝|进口|红酒

//对比
//qq的分词 http://nlp.qq.com/semantic.cgi#page2 
//百度的分词 http://ai.baidu.com/tech/nlp/lexical

分词速度

机器阿里云 Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
getWord 每秒140w字
getShortWord 每秒138w字
getAutoWord 每秒40w字
测试文本在百度百科拷贝的一段5000字的文本

制作词库

  • 词库支持utf-8的任意字符
  • 词典大小不影响 分词速度

只有一个方法 VicDict->add(词语,词性 = null)

require __DIR__.'/Lib/VicDict.php';

//目前可支持 igb 和 json 两种词典库格式;igb需要安装igbinary扩展,igb文件小,加载快
$path = ''; //词典地址
$dict = new VicDict($path);

//添加词语词库 add(词语,词性) 不分语言,可以是utf-8编码的任何字符
$dict->add('**','n');

//保存词库
$dict->save();

demo

demo

该作者的其他软件

vicword's People

Contributors

lizhichao avatar kmvan avatar

Watchers

James Cloos avatar

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.