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\Input; |
16
|
|
|
|
17
|
|
|
abstract class InputAbstract extends \ArrayObject |
18
|
|
|
{ |
19
|
82 |
View Code Duplication |
public function __construct($first = null, $second = null, |
|
|
|
|
20
|
|
|
array $costs = null) |
21
|
|
|
{ |
22
|
82 |
|
if (is_array($first)) { |
23
|
|
|
$array = array_combine(['first', 'second', 'costs'], $first); |
24
|
|
|
} else { |
25
|
|
|
$array = [ |
26
|
82 |
|
'first' => $first, |
27
|
82 |
|
'second' => $second, |
28
|
82 |
|
'costs' => $costs, |
29
|
|
|
]; |
30
|
|
|
} |
31
|
82 |
|
parent::__construct($array, parent::ARRAY_AS_PROPS); |
32
|
|
|
|
33
|
82 |
|
$this->constructCosts(); |
34
|
82 |
|
} |
35
|
|
|
|
36
|
|
|
public function setFirst($value) |
37
|
|
|
{ |
38
|
|
|
return $this->set('first', $value); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setSecond($value) |
42
|
|
|
{ |
43
|
|
|
return $this->set('second', $value); |
44
|
|
|
} |
45
|
|
|
|
46
|
82 |
|
public function setCostsByArray(array $array) |
47
|
|
|
{ |
48
|
82 |
|
$this->setCosts(new Costs($array)); |
49
|
82 |
|
} |
50
|
|
|
|
51
|
6 |
|
public function setStopwords(array $array) |
52
|
|
|
{ |
53
|
6 |
|
$this->set('stopwords', $array); |
54
|
6 |
|
} |
55
|
|
|
|
56
|
39 |
|
public function getStopwords() |
57
|
|
|
{ |
58
|
39 |
|
return $this->get('stopwords'); |
59
|
|
|
} |
60
|
|
|
|
61
|
82 |
|
protected function constructCosts() |
62
|
|
|
{ |
63
|
82 |
|
$defaultCosts = [1, 0, 1]; |
64
|
|
|
|
65
|
82 |
|
return $this->setCostsByArray(($this->costs) ? $this->costs : $defaultCosts); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
82 |
|
public function setCosts($value) |
69
|
|
|
{ |
70
|
82 |
|
return $this->set('costs', $value); |
71
|
|
|
} |
72
|
|
|
|
73
|
82 |
|
protected function set($key, $value) |
74
|
|
|
{ |
75
|
82 |
|
$this->$key = $value; |
76
|
82 |
|
} |
77
|
|
|
|
78
|
82 |
|
protected function get($key) |
79
|
|
|
{ |
80
|
82 |
|
if ($this->offsetExists($key)) { |
81
|
82 |
|
return $this->$key; |
82
|
|
|
} |
83
|
33 |
|
} |
84
|
|
|
} |
85
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.