1 | <?php |
||
35 | class GlSpellChecker |
||
36 | { |
||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | private $languageToolServerPort = 8081; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $languageToolLanguage = 'fr'; |
||
46 | |||
47 | /** |
||
48 | * @var Process $languagetoolServer ; |
||
49 | */ |
||
50 | private $languagetoolServer = null; |
||
51 | |||
52 | /** |
||
53 | * @var Client |
||
54 | */ |
||
55 | private $languagetoolClientHttp; |
||
56 | |||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | private $enchantLanguage = "fr_FR"; |
||
62 | private $enchantDictionnary = null; |
||
63 | private $enchantBroker = null; |
||
64 | |||
65 | /** |
||
66 | * @param string $languageToolDirectory |
||
67 | * @param string $languageToolLanguage |
||
68 | * @param string $enchantLanguage |
||
69 | * @param string $languageToolServerIP |
||
70 | * @param int $languageToolServerPort |
||
71 | * |
||
72 | * @throws \Exception |
||
73 | */ |
||
74 | public function __construct( |
||
101 | |||
102 | public function __destruct() |
||
110 | |||
111 | /** |
||
112 | * @param string $title |
||
113 | * @param GlSpellCheckerSentence[] $sentences |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | public function convertToHtml($title, $sentences) |
||
188 | |||
189 | public function checkYamlFiles( |
||
236 | |||
237 | /** |
||
238 | * @param Finder $files |
||
239 | * @param callable $checkfilestart |
||
240 | * @param callable $checksentence |
||
241 | * @param callable $checkfileend |
||
242 | * |
||
243 | * @return array |
||
244 | */ |
||
245 | public function checkHtmlFiles( |
||
284 | |||
285 | /** |
||
286 | * @param array $sentences |
||
287 | * |
||
288 | * @param callable $closure |
||
289 | * |
||
290 | * @return GlSpellCheckerSentence[] |
||
291 | */ |
||
292 | public |
||
293 | function checkSentences( |
||
294 | array $sentences, |
||
295 | callable $closure |
||
296 | ) { |
||
297 | $url = "http://{$this->languageToolServerIP}:{$this->languageToolServerPort}"; |
||
298 | $sentencesChecked = []; |
||
299 | foreach ($sentences as $sentence) { |
||
300 | $response = $this->languagetoolClientHttp->get( |
||
301 | $url, |
||
302 | [ |
||
303 | 'query' => [ |
||
304 | 'language' => $this->languageToolLanguage, |
||
305 | 'text' => $sentence |
||
306 | ] |
||
307 | ] |
||
308 | ); |
||
309 | $xml = $response->getBody()->getContents(); |
||
310 | $glxml = new GlHtml($xml); |
||
311 | $errors = $glxml->get('error'); |
||
312 | $sentenceChecked = new GlSpellCheckerSentence($sentence); |
||
313 | if (count($errors) > 0) { |
||
314 | foreach ($errors as $error) { |
||
315 | $msg = $error->getAttribute('msg'); |
||
316 | $offset = (int)$error->getAttribute('offset'); |
||
317 | $length = (int)$error->getAttribute('errorlength'); |
||
318 | $suggs = []; |
||
319 | $word = null; |
||
320 | if ($error->getAttribute('locqualityissuetype') == 'misspelling') { |
||
321 | $word = mb_substr($sentence, $offset, $length, 'UTF-8'); |
||
322 | if ($this->enchantDictionnary) { |
||
323 | $wordcorrect = enchant_dict_check($this->enchantDictionnary, $word); |
||
324 | if (!$wordcorrect) { |
||
325 | $suggs = enchant_dict_suggest($this->enchantDictionnary, $word); |
||
326 | } |
||
327 | } |
||
328 | } |
||
329 | $glerror = new GlSpellCheckerError($msg, $offset, $length, $word, $suggs); |
||
330 | $sentenceChecked->addError($glerror); |
||
331 | } |
||
332 | } |
||
333 | $sentencesChecked[] = $sentenceChecked; |
||
334 | $closure($sentence); |
||
335 | } |
||
336 | |||
337 | return $sentencesChecked; |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * @param string $directory |
||
342 | */ |
||
343 | private function startLanguageToolServer($directory) |
||
350 | |||
351 | private function stopLanguageToolServer() |
||
358 | } |
||
359 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.