|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GinoPane\PHPolyglot\API\Response\Dictionary\Entry; |
|
4
|
|
|
|
|
5
|
|
|
use GinoPane\PHPolyglot\API\Response\Dictionary\Entry\POS\DictionaryEntryPos; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class DictionaryEntry |
|
9
|
|
|
* |
|
10
|
|
|
* DictionaryEntry provides detailed information about a word |
|
11
|
|
|
* |
|
12
|
|
|
* @author Sergey <Gino Pane> Karavay |
|
13
|
|
|
*/ |
|
14
|
|
|
class DictionaryEntry |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* A string containing the source text for current dictionary entry |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $textFrom = ''; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* A string containing the translated text or possible text variant if the languages are the same |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $textTo = ''; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* A string containing the transcription of the text if applicable |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $transcription = ''; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Part of speech of dictionary entry source word |
|
39
|
|
|
* |
|
40
|
|
|
* @var DictionaryEntryPos |
|
41
|
|
|
*/ |
|
42
|
|
|
private $posFrom = null; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Part of speech of dictionary entry resulting word |
|
46
|
|
|
* |
|
47
|
|
|
* @var DictionaryEntryPos |
|
48
|
|
|
*/ |
|
49
|
|
|
private $posTo = null; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* An array of synonyms of the source text |
|
53
|
|
|
* |
|
54
|
|
|
* @var array |
|
55
|
|
|
*/ |
|
56
|
|
|
private $synonyms = []; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* An array of strings describing the meaning of the text |
|
60
|
|
|
* |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
private $meanings = []; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* An associative array of usage examples. The format is: |
|
67
|
|
|
* [ |
|
68
|
|
|
* text_in_language_from => text_in_language_to, |
|
69
|
|
|
* ... |
|
70
|
|
|
* ] |
|
71
|
|
|
* |
|
72
|
|
|
* @var array |
|
73
|
|
|
*/ |
|
74
|
|
|
private $examples = []; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getTextFrom(): string |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->textFrom; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param string $textFrom |
|
86
|
|
|
* |
|
87
|
|
|
* @return DictionaryEntry |
|
88
|
|
|
*/ |
|
89
|
|
|
public function setTextFrom(string $textFrom): DictionaryEntry |
|
90
|
|
|
{ |
|
91
|
|
|
$this->textFrom = $textFrom; |
|
92
|
|
|
|
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getTextTo(): string |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->textTo; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param string $textTo |
|
106
|
|
|
* |
|
107
|
|
|
* @return DictionaryEntry |
|
108
|
|
|
*/ |
|
109
|
|
|
public function setTextTo(string $textTo): DictionaryEntry |
|
110
|
|
|
{ |
|
111
|
|
|
$this->textTo = $textTo; |
|
112
|
|
|
|
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getTranscription(): string |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->transcription; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param string $transcription |
|
126
|
|
|
* |
|
127
|
|
|
* @return DictionaryEntry |
|
128
|
|
|
*/ |
|
129
|
|
|
public function setTranscription(string $transcription): DictionaryEntry |
|
130
|
|
|
{ |
|
131
|
|
|
$this->transcription = $transcription; |
|
132
|
|
|
|
|
133
|
|
|
return $this; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return array |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getSynonyms(): array |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->synonyms; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param array $synonyms |
|
146
|
|
|
* |
|
147
|
|
|
* @return DictionaryEntry |
|
148
|
|
|
*/ |
|
149
|
|
|
public function setSynonyms(array $synonyms): DictionaryEntry |
|
150
|
|
|
{ |
|
151
|
|
|
$this->synonyms = $synonyms; |
|
152
|
|
|
|
|
153
|
|
|
return $this; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return array |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getMeanings(): array |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->meanings; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param array $meanings |
|
166
|
|
|
* |
|
167
|
|
|
* @return DictionaryEntry |
|
168
|
|
|
*/ |
|
169
|
|
|
public function setMeanings(array $meanings): DictionaryEntry |
|
170
|
|
|
{ |
|
171
|
|
|
$this->meanings = $meanings; |
|
172
|
|
|
|
|
173
|
|
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return array |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getExamples(): array |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->examples; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param array $examples |
|
186
|
|
|
* |
|
187
|
|
|
* @return DictionaryEntry |
|
188
|
|
|
*/ |
|
189
|
|
|
public function setExamples(array $examples): DictionaryEntry |
|
190
|
|
|
{ |
|
191
|
|
|
$this->examples = $examples; |
|
192
|
|
|
|
|
193
|
|
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @return string |
|
198
|
|
|
*/ |
|
199
|
|
|
public function getPosFrom(): string |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->getPosAsString('posFrom'); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @return string |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getPosTo(): string |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->getPosAsString('posTo'); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @param DictionaryEntryPos $pos |
|
214
|
|
|
* |
|
215
|
|
|
* @return DictionaryEntry |
|
216
|
|
|
*/ |
|
217
|
|
|
public function setPosTo(DictionaryEntryPos $pos): DictionaryEntry |
|
218
|
|
|
{ |
|
219
|
|
|
$this->posTo = $pos; |
|
220
|
|
|
|
|
221
|
|
|
return $this; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @param DictionaryEntryPos $pos |
|
226
|
|
|
* |
|
227
|
|
|
* @return DictionaryEntry |
|
228
|
|
|
*/ |
|
229
|
|
|
public function setPosFrom(DictionaryEntryPos $pos): DictionaryEntry |
|
230
|
|
|
{ |
|
231
|
|
|
$this->posFrom = $pos; |
|
232
|
|
|
|
|
233
|
|
|
return $this; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @param string $posField |
|
238
|
|
|
* |
|
239
|
|
|
* @return string |
|
240
|
|
|
*/ |
|
241
|
|
|
private function getPosAsString(string $posField): string |
|
242
|
|
|
{ |
|
243
|
|
|
return !is_null($this->{$posField}) ? $this->{$posField}->getPos() : DictionaryEntryPos::POS_UNDEFINED; |
|
244
|
|
|
} |
|
245
|
|
|
} |
|
246
|
|
|
|