{"id":21912481,"url":"https://github.com/tianliangzhou/ffi-lac","last_synced_at":"2025-04-16T04:42:37.226Z","repository":{"id":110644921,"uuid":"359138074","full_name":"TianLiangZhou/ffi-lac","owner":"TianLiangZhou","description":"基于百度LAC项目的PHP中文智能分词库","archived":false,"fork":false,"pushed_at":"2024-06-25T01:43:16.000Z","size":3710,"stargazers_count":10,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-25T07:01:34.701Z","etag":null,"topics":["baidu-lac","php-ffi","php-ffi-extension","php-lac","php8"],"latest_commit_sha":null,"homepage":"https://loocode.com/tool/chinese-word-segmentation","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TianLiangZhou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-18T12:34:04.000Z","updated_at":"2024-06-25T01:43:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"3a6e14a7-f797-4971-9f1f-869091a4eff7","html_url":"https://github.com/TianLiangZhou/ffi-lac","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TianLiangZhou%2Fffi-lac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TianLiangZhou%2Fffi-lac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TianLiangZhou%2Fffi-lac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TianLiangZhou%2Fffi-lac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TianLiangZhou","download_url":"https://codeload.github.com/TianLiangZhou/ffi-lac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226963528,"owners_count":17710194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["baidu-lac","php-ffi","php-ffi-extension","php-lac","php8"],"created_at":"2024-11-28T18:10:14.525Z","updated_at":"2024-11-28T18:10:15.047Z","avatar_url":"https://github.com/TianLiangZhou.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ffi-lac\n\n`ffi-lac`是一个PHP高性能智能中文分词库，基于百度开源的[lac](https://github.com/baidu/lac) 项目，使用`C++`导出`C`函数构建动态链接库来给`php`调用。\n项目中大部分源码都可以从 https://github.com/baidu/lac 找到。\n\n### 环境\n\n需要`php \u003e= 7.4` 以上的版本并且开启了`FFI`扩展。\n\n还需要设置`php.ini` 中的`ffi.enable`为`On`。\n\n### paddlepaddle\n\n推理预测库版本: [2.5](https://www.paddlepaddle.org.cn/inference/v2.5/guides/introduction/index_intro.html)\n\n项目依赖: __paddle推理预测库__([点击去下载](https://www.paddlepaddle.org.cn/inference/v2.5/guides/install/download_lib.html) )，__预测模型库__([点击去下载](https://github.com/baidu/lac/releases/tag/v2.1.0) )。\n\n### Linux\n\n将下载的推理预测库存放到: `/opt/paddle_inference`目录。\n\n可以通过`ldd lib/liblacffi.so`显示库的依赖, 再根据情况建立软链。\n\n```shell \n[meshell@/] ln -s paddle_inference/paddle/lib/libpaddle_inference.so libpaddle_inference.so\n[meshell@/] ln -s paddle_inference/third_party/install/mklml/lib/libmklml_intel.so libmklml_intel.so\n[meshell@/] ln -s paddle_inference/third_party/install/mklml/lib/libiomp5.so libiomp5.so\n[meshell@/] ln -s paddle_inference/third_party/install/mkldnn/lib/libmkldnn.so.0 libdnnl.so.2\n```\n\n```shell\nffi-lac git:(main) ✗ ldd lib/liblacffi.so\n\tlinux-vdso.so.1 (0x00007ffc0939f000)\n\tlibpaddle_inference.so =\u003e /opt/paddle_inference/paddle/lib/libpaddle_inference.so (0x00007f397be00000)\n\tlibstdc++.so.6 =\u003e /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f397bb93000)\n\tlibgcc_s.so.1 =\u003e /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f397bb6f000)\n\tlibc.so.6 =\u003e /lib/x86_64-linux-gnu/libc.so.6 (0x00007f397b946000)\n\tlibpthread.so.0 =\u003e /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3983256000)\n\tlibpaddle2onnx.so.1.0.0rc2 =\u003e /lib/libpaddle2onnx.so.1.0.0rc2 (0x00007f397b000000)\n\tlibonnxruntime.so.1.11.1 =\u003e /lib/libonnxruntime.so.1.11.1 (0x00007f397a198000)\n\tlibrt.so.1 =\u003e /lib/x86_64-linux-gnu/librt.so.1 (0x00007f3983251000)\n\tlibdnnl.so.2 =\u003e /lib/libdnnl.so.2 (0x00007f3977e00000)\n\tlibiomp5.so =\u003e /lib/libiomp5.so (0x00007f3977a00000)\n\tlibm.so.6 =\u003e /lib/x86_64-linux-gnu/libm.so.6 (0x00007f397b85f000)\n\t/lib64/ld-linux-x86-64.so.2 (0x00007f3983290000)\n\tlibdl.so.2 =\u003e /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f398324a000)\n\tlibgomp.so.1 =\u003e /lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f39779ac000)\n\t\n```\n\n### THULAC\n\n`thulac`由清华大学自然语言处理与社会人文计算实验室研制推出的一套中文词法分析工具包，具有中文分词和词性标注功能。\n目前是基于 [thulac.so](https://github.com/thunlp/THULAC.so) 导出`.so`供FFI调用。该库需要字典词库下载地址: [thulac.thunlp.org](thulac.thunlp.org)\n\n### Usage \n\n```php\n\u003c?php\n\ninclude __DIR__ . '/../src/LAC.php';\n\n$dictDir = \"\"; // 默认库根目录下的model/lac_model\n\n$lac = \\FastFFI\\LAC\\LAC::new($dictDir);\n\nvar_dump(\n    $lac-\u003eparse(\"LAC智能中文分词库\")\n);\n\n\n$thuLac = \\FastFFI\\LAC\\ThuLAC::new();\n\nvar_dump(\n    $thuLac-\u003eparse(\"thulac智能中文分词库\")\n);\n\n\n\n```\n\n以上程序执行后的结果: \n\n```php \narray(2) {\n  [\"words\"]=\u003e\n  string(29) \"LAC 智能 中文 分 词库 \"\n  [\"tags\"]=\u003e\n  string(11) \"nz n n v n \"\n}\n\narray(3) {\n  [\"words\"]=\u003e\n  string(31) \"thulac 智能 中文 分词库 \"\n  [\"tags\"]=\u003e\n  string(9) \"x n nz n \"\n  [\"weight\"]=\u003e\n  string(0) \"\"\n}\n```\n\n结果分别为词和标签都是以空格分隔。\n\n百度LAC以下是标签含义：\n\n| 标签 | 含义     | 标签 | 含义     | 标签 | 含义     | 标签 | 含义     |\n| ---- | -------- | ---- | -------- | ---- | -------- | ---- | -------- |\n| n    | 普通名词 | f    | 方位名词 | s    | 处所名词  | nw   | 作品名   |\n| nz   | 其他专名 | v    | 普通动词 | vd   | 动副词   | vn   | 名动词   |\n| a    | 形容词   | ad   | 副形词   | an   | 名形词   | d    | 副词     |\n| m    | 数量词   | q    | 量词     | r    | 代词     | p    | 介词     |\n| c    | 连词     | u    | 助词     | xc   | 其他虚词 | w    | 标点符号 |\n| PER  | 人名     | LOC  | 地名     | ORG  | 机构名   | TIME | 时间     |\n\n权重定义:\n\n| 标签 | 含义       | 常见于词性|\n| ---- | --------  | ----   | \n| 0    | query中表述的冗余词   |  p, w, xc ...    | \n| 1    | query中限定较弱的词   |  r, c, u ...     | \n| 2    | query中强限定的词     |  n, s, v ...     | \n| 3    | query中的核心词       |  nz, nw, LOC ... | \n\n\nTHULAC标签含义:\n\n\n\n| 标签 | 含义      | 标签     | 含义     | 标签    | 含义     | 标签    | 含义  | 标签    | 含义  |\n|----|---------|--------|--------|-------|--------|-------|-----| ---- | ---- |\n| n  | 名词      | np     | 人名     | ns    | 地名     | ni    | 机构名 | nz |其它专名|\n|m|数词| q|量词 |mq|数量词| t|时间词| f|方位词 |s|处所词|\n|v|动词 |a|形容词| d|副词| h|前接成分| k|后接成分 |\n|i|习语 |j|简称| r|代词| c|连词| p|介词| u|助词 |y|语气助词|\n|e|叹词 |o|拟声词 |g|语素| w|标点| x|其它 |\n\n\n\u003e 该项目不支持`window`环境，如果你需要请自行编译。\n\n[在线转换](http://loocode.com/tool/lac/chinese-word-segmentation)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftianliangzhou%2Fffi-lac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftianliangzhou%2Fffi-lac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftianliangzhou%2Fffi-lac/lists"}