forever2077 / jieba-php
PHP 实现的 Jieba 中文分词
0.1.1
2023-09-12 05:10 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-12 07:07:00 UTC
README
结巴分词 PHP 实现 - PHP 实现的 Jieba 中文分词
使用 PHP 7.4 中新增的 FFI 对 jieba-rs 进行了包装。
需求
PHP >= 7.4,并开启 FFI 扩展
安装
您可以通过 composer 安装此包
composer require forever2077/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)。有关更多信息,请参阅 许可证文件。