function index() { $this->load->library('form_validation'); $this->load->helper('word_list'); $this->form_validation->set_rules('words', 'Word/s', 'required'); if ($this->form_validation->run() == FALSE) { $this->load->view('home'); } else { //curl variables //pass in parameter, either single word or array. If array, loop through $apiKey = '1766cba83f05e0a627fbe111ab8ae039'; $baseUrl = 'https://api.pearson.com/longman/dictionary/0.1/'; $dataFmt = '.json'; $searchUrl = $baseUrl . 'entry' . $dataFmt; $searchUrl .= '?apikey=' . $apiKey . '&q='; //get list of words $data['word_list'] = word_list($this->form_validation->set_value('words')); $data['defined_words'] = array(); $data['undefined_words'] = array(); $result_str = ''; //now get definitions for each //first, check to see if it is in mongo.db //if it isn't, get it from dictionary site, then add json object into the db, then process word for ($i = 0; $i < sizeof($data['word_list']); $i++) { // Start session (also wipes existing/previous sessions) $this->curl->create($searchUrl . $data['word_list'][$i]); // Options $this->curl->options(array(CURLOPT_BUFFERSIZE => 10, CURLOPT_SSL_VERIFYPEER => FALSE)); // Execute - returns json object, Entries->Entries - if only one entry it returns head, body etc. Otherwise it returns {},{},{} $json = $this->curl->execute(); //format json into an array $entries = json_decode($json, true); //if entries not null if ($entries['Entries'] != '') { $result_str .= '<article><ol>'; $result_str .= $this->wordmodel->process_entries($entries['Entries']['Entry']); $result_str .= '</ol></article>'; array_push($data['defined_words'], $data['word_list'][$i]); } else { array_push($data['undefined_words'], $data['word_list'][$i]); } } $data['results'] = $result_str; $this->load->view('home', $data); } }
} return $words; } $text = stripslashes($_REQUEST['text']); // This is to deal with the fact that IE receives two characters (\r, \n) for every line break. // This was throwing off the positions of words to be corrected. The positions were off by // one character for each line break entered in the textarea field. $text = preg_replace("/\r/", "", $text); if ($text) { $xml = '<?xml version="1.0" ?>'; /* $xml = '<?xml-stylesheet type="text/xsl" href="spellchecker.xsl" ?>'; */ $xml .= '<spellcheck>'; $xml .= "<originaltext>{$text}</originaltext>"; $spell_checker = new SpellChecker(); $textwords = strip_punct($text); $textwordsArray = word_list($textwords); $list = ""; foreach ($textwordsArray as $n => $w) { $xml .= "<word>"; $xml .= "<original pos=\"{$w->pos}\" len=\"{$w->len}\">{$w->word}</original>"; if (!$spell_checker->check($w->word)) { $xml .= '<status>-1</status>'; $suggestions = $spell_checker->suggest($w->word); if (sizeof($suggestions) > 0) { $xml .= '<suggestions>'; foreach ($suggestions as $s) { $xml .= "<sugword>{$s}</sugword>"; } $xml .= '</suggestions>'; } }