|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/similarity |
|
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
|
6
|
|
|
* For the information of copyright and license you should read the file |
|
7
|
|
|
* LICENSE which is distributed with this source code. |
|
8
|
|
|
* Para a informação dos direitos autorais e de licença você deve ler o arquivo |
|
9
|
|
|
* LICENSE que é distribuído com este código-fonte. |
|
10
|
|
|
* Para obtener la información de los derechos de autor y la licencia debe leer |
|
11
|
|
|
* el archivo LICENSE que se distribuye con el código fuente. |
|
12
|
|
|
* For more information, see <https://www.gpupo.com/>. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Gpupo\Similarity; |
|
16
|
|
|
|
|
17
|
|
|
class SimilarNumber extends SimilarityAbstract implements SimilarInterface |
|
18
|
|
|
{ |
|
19
|
21 |
|
public function hasSimilarity() |
|
20
|
|
|
{ |
|
21
|
21 |
|
if ($this->isEquals()) { |
|
22
|
8 |
|
return true; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
13 |
|
if ($this->isApproximate()) { |
|
26
|
5 |
|
return true; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
8 |
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
28 |
|
public function isEquals() |
|
33
|
|
|
{ |
|
34
|
28 |
|
if ($this->getInput()->getFirst() === $this->getInput()->getSecond()) { |
|
35
|
15 |
|
return true; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
13 |
|
return false; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
21 |
|
public function getProximityCalculation() |
|
42
|
|
|
{ |
|
43
|
|
|
$calc = [ |
|
44
|
21 |
|
'first' => $this->getInput()->getFirst(), |
|
45
|
21 |
|
'second' => $this->getInput()->getSecond(), |
|
46
|
|
|
]; |
|
47
|
21 |
|
$calc['limit'] = $this->getLimitOfProximity($calc['first'], $calc['second']); |
|
48
|
21 |
|
$calc['difference'] = abs($calc['first'] - $calc['second']); |
|
49
|
|
|
|
|
50
|
21 |
|
return $calc; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
21 |
|
protected function getLimitOfProximity($first, $second) |
|
54
|
|
|
{ |
|
55
|
|
|
$calc = [ |
|
56
|
21 |
|
'chars' => strlen($first.$second), |
|
57
|
21 |
|
'multiplicator' => (10 - ($this->getAccuracy() / 10)), |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
21 |
|
$calc['maxDifference'] = ($calc['chars'] * $calc['multiplicator']); |
|
61
|
|
|
|
|
62
|
21 |
|
return $calc; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
8 |
|
public function __toArray() |
|
66
|
|
|
{ |
|
67
|
8 |
|
return array_merge(parent::__toArray(), [ |
|
68
|
8 |
|
'proximityCalculation' => $this->getProximityCalculation(), |
|
69
|
|
|
]); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|