1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hasantayyar\Synonyms; |
4
|
|
|
|
5
|
|
|
use Yangqi\Htmldom\Htmldom as Htmldom; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* |
9
|
|
|
* |
10
|
|
|
* @author Hasan Tayyar BEŞİK <[email protected]> |
11
|
|
|
* @author Hasan Tayyar BEŞİK |
12
|
|
|
* @version 0.1 |
13
|
|
|
* @package Synonyms |
14
|
|
|
*/ |
15
|
|
|
class Synonyms { |
16
|
|
|
|
17
|
|
|
private $url; |
18
|
|
|
private $word; |
19
|
|
|
private $words; |
20
|
|
|
public $suggestions = array(); |
21
|
|
|
|
22
|
|
|
public function __construct($word) { |
23
|
|
|
$this->word = $word; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getWords() { |
27
|
|
|
return $this->words; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getFormatted() { |
31
|
|
|
if (!is_array($this->words)) { |
32
|
|
|
return FALSE; |
33
|
|
|
} |
34
|
|
|
$formattedString = ''; |
35
|
|
|
foreach ($this->words as $level) { |
36
|
|
|
foreach ($level['data'] as $item) { |
37
|
|
|
$formattedString.= $item['word'] . "\n"; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
return $formattedString; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* get and get Thesaurus.com data |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function getThesaurus($word = NULL) { |
|
|
|
|
47
|
|
|
$word = !$word ? $this->word : $word; |
48
|
|
|
$service = new Services\Thesaurus(); |
49
|
|
|
$this->words = $service->getWords($word); |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function getBighugelabs($word = NULL) { |
|
|
|
|
54
|
|
|
$word = !$word ? $this->word : $word; |
55
|
|
|
$service = new Services\Bighugelabs(); |
56
|
|
|
$this->words = $service->getWords($word); |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function getTurkishSynonyms($word = NULL) { |
|
|
|
|
61
|
|
|
$word = !$word ? $this->word : $word; |
62
|
|
|
$service = new Services\TurkishSynonyms(); |
63
|
|
|
$this->words = $service->getWords($word); |
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getWordnik($word = NULL) { |
|
|
|
|
68
|
|
|
//https://www.wordnik.com/fragments/tags/test |
69
|
|
|
return NULL; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @todo get google suggestions |
74
|
|
|
*/ |
75
|
|
|
public function getGoogleSuggestions($word = NULL) { |
|
|
|
|
76
|
|
|
return NULL; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
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.