jfcherng/php-levenshtein-distance
Composer 安装命令:
composer require jfcherng/php-levenshtein-distance
包简介
Calculate the Levenshtein distance and edit progresses between two strings.
README 文档
README
Calculate the Levenshtein distance and edit progresses between two strings. Note that if you do not need the edit path, PHP has a built-in levenshtein() function.
Features
- UTF-8-ready.
- Full edit progresses information.
Installation
$ composer require jfcherng/php-levenshtein-distance
Example
See demo.php.
<?php include __DIR__ . '/vendor/autoload.php'; use Jfcherng\Diff\LevenshteinDistance as LD; $old = '自訂取代詞語模組'; $new = '自订取代词语模组!'; $calculator = new LD( true, // calculate edit progresses? // progress options LD::PROGRESS_OP_AS_STRING | LD::PROGRESS_PATCH_MODE ); $results = $calculator->calculate($old, $new); // this is the same but using an internal singleton $results = LD::staticCalculate( $old, // old string $new, // new string true, // calculate edit progresses? // progress options LD::PROGRESS_OP_AS_STRING | LD::PROGRESS_PATCH_MODE ); // [ // 'distance' => 5, // 'progresses' => [ // ['ins', 8, '!', 1], // ['rep', 7, '组', 1], // ['cpy', 6, '模', 1], // ['rep', 5, '语', 1], // ['rep', 4, '词', 1], // ['cpy', 3, '代', 1], // ['cpy', 2, '取', 1], // ['rep', 1, '订', 1], // ['cpy', 0, '自', 1], // ], // ] var_dump($results); $results = LD::staticCalculate( $old, // old string $new, // new string true, // calculate edit progresses? // progress options LD::PROGRESS_OP_AS_STRING | LD::PROGRESS_PATCH_MODE | LD::PROGRESS_MERGE_NEIGHBOR ); // [ // 'distance' => 5, // 'progresses' => [ // ['ins', 8, '!', 1], // ['rep', 7, '组', 1], // ['cpy', 6, '模', 1], // ['rep', 4, '词语', 2], // ['cpy', 2, '取代', 2], // ['rep', 1, '订', 1], // ['cpy', 0, '自', 1], // ], // ] var_dump($results);
Progress Options
LD::PROGRESS_NO_COPY: Do not includeCOPYoperations in the progresses.LD::PROGRESS_MERGE_NEIGHBOR: Merge neighbor progresses if possible.LD::PROGRESS_OP_AS_STRING: Convert the operation in progresses from int to string.LD::PROGRESS_PATCH_MODE: Replace the new edit position with the corresponding string.
Returned progresses
- The operation.
- The edit position for the new string.
- The edit position for the old string.
Or the corresponding string if
LD::PROGRESS_PATCH_MODEis used. - The edit length.
jfcherng/php-levenshtein-distance 适用场景与选型建议
jfcherng/php-levenshtein-distance 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.12k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 06 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「edit-progress」 「levenshtein-distance」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jfcherng/php-levenshtein-distance 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jfcherng/php-levenshtein-distance 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jfcherng/php-levenshtein-distance 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 14.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-24