-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo.php
65 lines (55 loc) · 1.56 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
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);