-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuilder_example.php
42 lines (33 loc) · 1.11 KB
/
builder_example.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
<?php
declare(strict_types=1);
require __DIR__.'/../vendor/autoload.php';
use Sourceability\StringMatcher\Matcher\LiquidMetalMatcher;
use Sourceability\StringMatcher\Simplifier\AlphanumericSimplifier;
use Sourceability\StringMatcher\Simplifier\ChainSimplifier;
use Sourceability\StringMatcher\Simplifier\TrimmedLowercaseSimplifier;
use Sourceability\StringMatcher\ValuesMatcherBuilder;
use const PHP_EOL;
use function print_r;
$chainSimplifier = new ChainSimplifier([
new TrimmedLowercaseSimplifier(),
new AlphanumericSimplifier(),
]);
$matcher = (new ValuesMatcherBuilder())
->addDefaultMatchers()
->addMatcher(new LiquidMetalMatcher($chainSimplifier), 50)
->setMinimumScore(50)
->create();
$input = 'Kraft Mac & Cheese';
$matches = [
'Wine & Cheese',
'Apple iMac',
'Craft Fair',
'Macaroni and Cheese',
'Kraft Macaroni and Cheese',
'Something Unexpected',
];
echo "Best Match Result: \r\n";
echo $matcher->getMatch($input, $matches);
echo PHP_EOL.PHP_EOL;
echo "Multiple Match Result (ordered by likelihood of match): \r\n";
print_r($matcher->getMatches($input, $matches));