2017 © Pedro Peláez
 

library php-levenshtein-distance

Calculate the Levenshtein distance and edit progresses between two strings.

image

jfcherng/php-levenshtein-distance

Calculate the Levenshtein distance and edit progresses between two strings.

  • Thursday, July 26, 2018
  • by jfcherng
  • Repository
  • 1 Watchers
  • 0 Stars
  • 452 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

php-levenshtein-distance

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

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., (*2)

Features

  • UTF-8-ready.
  • Full edit progresses information.

Installation

$ composer require jfcherng/php-levenshtein-distance

Example

See demo.php., (*3)

<?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.

The Versions

26/07 2018

dev-master

9999999-dev

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

18/07 2018

2.3.4

2.3.4.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

04/07 2018

2.3.3

2.3.3.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

04/07 2018

2.3.2

2.3.2.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

03/07 2018

2.3.1

2.3.1.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

03/07 2018

2.3.0

2.3.0.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

03/07 2018

2.2.0

2.2.0.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

28/06 2018

2.1.3

2.1.3.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

28/06 2018

2.1.2

2.1.2.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

28/06 2018

2.1.1

2.1.1.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

28/06 2018

2.1.0

2.1.0.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

28/06 2018

2.0.0

2.0.0.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

edit-progress levenshtein-distance

24/06 2018

1.0.1

1.0.1.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng

24/06 2018

1.0.0

1.0.0.0

Calculate the Levenshtein distance and edit progresses between two strings.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

by Jack Cherng