承接 jfcherng/php-levenshtein-distance 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jfcherng/php-levenshtein-distance

最新稳定版本:4.0.2

Composer 安装命令:

composer require jfcherng/php-levenshtein-distance

包简介

Calculate the Levenshtein distance and edit progresses between two strings.

README 文档

README

GitHub Workflow Status (branch) Packagist Packagist Version Project license GitHub stars Donate to this project using Paypal

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 include COPY operations 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

  1. The operation.
  2. The edit position for the new string.
  3. The edit position for the old string. Or the corresponding string if LD::PROGRESS_PATCH_MODE is used.
  4. The edit length.

统计信息

  • 总下载量: 8.12k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知