Beispiel #1
0
 /**
  * @param array|Word[]   $words
  * @param array|string[] $locales
  *
  * @return SpellResult
  */
 public function check($words, array $locales)
 {
     $misspelledWords = array();
     $enchantResource = enchant_broker_init();
     /*$bprovides = enchant_broker_describe($r);
       echo "Current broker provides the following backend(s):\n";
       print_r($bprovides);*/
     /*$dicts = enchant_broker_list_dicts($r);
       print_r($dicts);*/
     $dictionaries = array();
     foreach ($locales as $locale) {
         if (!enchant_broker_dict_exists($enchantResource, $locale)) {
             // TODO handle and log error
             continue;
         }
         $dictionaries[$locale] = enchant_broker_request_dict($enchantResource, $locale);
     }
     //$dprovides = enchant_dict_describe($dictionary);
     //echo "dictionary $tag provides:\n";
     foreach ($words as $word) {
         $checked = false;
         $suggests = array();
         foreach ($dictionaries as $locale => $dictionary) {
             $suggests[$locale] = array();
             $checked = $checked || enchant_dict_quick_check($dictionary, $word->getWord(), $suggests[$locale]);
         }
         $word->setChecked($checked);
         if (!$word->isChecked()) {
             $word->setSuggests($suggests);
             $misspelledWords[] = $word;
         }
     }
     foreach ($dictionaries as $dictionary) {
         enchant_broker_free_dict($dictionary);
     }
     enchant_broker_free($enchantResource);
     $spellResult = new SpellResult();
     $spellResult->setCountOfWords(count($words));
     $spellResult->setMisspelledWords($misspelledWords);
     return $spellResult;
 }
 /**
  * Check whether a word is correctly spelled and return list suggestions if the word is wrongly spelled
  */
 public function quickCheck($word)
 {
     wfProfileIn(__METHOD__);
     $ret = false;
     if ($this->isLoaded()) {
         $suggestions = array();
         $ret = enchant_dict_quick_check($this->dict, $word, $suggestions);
         // return suggestions if word is misspelled
         if ($ret == false) {
             $ret = $suggestions;
         } else {
             $ret = true;
         }
     }
     wfProfileOut(__METHOD__);
     return $ret;
 }