wyndow/fuzzywuzzy
Composer 安装命令:
composer require wyndow/fuzzywuzzy
包简介
Fuzzy string matching based on FuzzyWuzzy from Seatgeek
README 文档
README
Fuzzy string matching for PHP, based on the python library of the same name.
Requirements
- PHP 5.4 or higher
Installation
Using Composer
composer require wyndow/fuzzywuzzy
Usage
use FuzzyWuzzy\Fuzz; use FuzzyWuzzy\Process; $fuzz = new Fuzz(); $process = new Process($fuzz); // $fuzz is optional here, and can be omitted.
Simple Ratio
>>> $fuzz->ratio('this is a test', 'this is a test!') => 96
Partial Ratio
>>> $fuzz->partialRatio('this is a test', 'this is a test!') => 100
Token Sort Ratio
>>> $fuzz->ratio('fuzzy wuzzy was a bear', 'wuzzy fuzzy was a bear') => 90 >>> $fuzz->tokenSortRatio('fuzzy wuzzy was a bear', 'wuzzy fuzzy was a bear') => 100
Token Set Ratio
>>> $fuzz->tokenSortRatio('fuzzy was a bear', 'fuzzy fuzzy was a bear') => 84 >>> $fuzz->tokenSetRatio('fuzzy was a bear', 'fuzzy fuzzy was a bear') => 100
Process
>>> $choices = ['Atlanta Falcons', 'New York Jets', 'New York Giants', 'Dallas Cowboys'] >>> $c = $process->extract('new york jets', $choices, null, null, 2) => FuzzyWuzzy\Collection {#205} >>> $c->toArray() => [ [ "New York Jets", 100, ], [ "New York Giants", 78, ], ] >>> $process->extractOne('cowboys', $choices) => [ "Dallas Cowboys", 90, ]
You can also pass additional parameters to extractOne to make it use a specific scorer.
>>> $process->extractOne('cowbell', $choices, null, [$fuzz, 'ratio']) => [ "Dallas Cowboys", 38, ] >>> $process->extractOne('cowbell', $choices, null, [$fuzz, 'tokenSetRatio']) => [ "Dallas Cowboys", 57, ]
Caveats
Unicode strings may produce unexpected results. We intend to correct this in future versions.
Further Reading
wyndow/fuzzywuzzy 适用场景与选型建议
wyndow/fuzzywuzzy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.08M 次下载、GitHub Stars 达 75, 最近一次更新时间为 2017 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wyndow/fuzzywuzzy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wyndow/fuzzywuzzy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.08M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 76
- 点击次数: 15
- 依赖项目数: 6
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-25