binaryoung / jieba-php
在 PHP 中实现的结巴中文分词
v0.1.0
2020-06-16 06:55 UTC
Requires
- php: ^7.4
- ext-ffi: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- fukuball/jieba-php: ^0.33.0
- phpunit/phpunit: ^9.0
- symfony/var-dumper: ^4.3
This package is auto-updated.
Last update: 2024-09-16 17:24:30 UTC
README
结巴分词 PHP 实现 - 在 PHP 中实现的结巴中文分词
使用 PHP 7.4 中新增的 FFI 对 jieba-rs 进行了包装。
要求
PHP >= 7.4,并启用 FFI 扩展
安装
您可以通过 composer 安装此包
composer require binaryoung/jieba-php
使用
use Binaryoung\Jieba\Jieba; var_dump(Jieba::cut('PHP是世界上最好的语言!'));
API
array cut(string $sentence, bool $hmm = true) array cutAll(string $sentence) array cutForSearch(string $sentence, bool $hmm = true) array TFIDFExtract(string $sentence, int $topK = 20, array $allowedPOS = []) array textRankExtract(string $sentence, int $topK = 20, array $allowedPOS = []) array tokenize(string $sentence, string $mode = 'default', bool $hmm = true) array tag(string $sentence, bool $hmm = true) int suggestFrequency(string $segment) self addWord(string $word, ?int $frequency = null, ?string $tag = null) self useDictionary(string $path)
示例
查看 examples/example.php
composer example
测试
composer test
基准测试
composer bench
对比 jukuball/jieba-php,循环 50 次对围城每行文字作为一个句子进行分词,分词算法都采用 HMM 模式。
变更日志
请参阅 CHANGELOG 了解最近更改的信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全性
如果您发现任何安全相关的问题,请通过电子邮件联系我,而不是使用问题跟踪器。
致谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。