public function doAction() { //check if id file and job is a number //if (is_numeric($this->id_file) && is_numeric($this->id_job)) //convert id_file and id_job into a numbers $id_file = (int) $this->id_file; $id_job = (int) $this->id_job; ini_set('max_execution_time', 6000); $ret = -1; if (substr(php_uname(), 0, 7) == "Windows") { log::doLog("windows"); $ret = pclose(popen("start C:\\wamp\\bin\\php\\php5.4.3\\php " . INIT::$MODEL_ROOT . "/exportLog.php " . $id_file . " " . $id_job . " 1", "r")); } else { $ret = pclose(popen("nohup php " . INIT::$MODEL_ROOT . "/exportLog.php " . $id_file . " " . $id_job . " 1 &", "r")); } log::doLog("CASMACAT: return exportLog: " . $ret); ini_set('max_execution_time', 30); // $this->filename ="log_id".$this->id_file."_".$this->file_name.".xml"; // header('Content-Type: text/xml; charset=UTF-8'); // header('Content-Disposition: attachment; filename="' . $this->file_name . '.xml"'); // // //log::doLog("CASMACAT: file: ".INIT::$LOG_DOWNLOAD . "/" .$this->filename); // // $this->content = file_get_contents(INIT::$LOG_DOWNLOAD . "/" . $this->filename); if ($ret == "END") { $this->result['code'] = 0; $this->result['data'] = "OK"; } else { $this->result['errors'] = "It is not possible to get the log file"; $this->result['code'] = -1; } }
public function doAction() { if (empty($this->source)) { $this->result['error'][] = array("code" => -1, "message" => "missing source segment"); } if (empty($this->target)) { $this->result['error'][] = array("code" => -2, "message" => "missing target segment"); } if (empty($this->source_lang)) { $this->result['error'][] = array("code" => -3, "message" => "missing source lang"); } if (empty($this->target_lang)) { $this->result['error'][] = array("code" => -2, "message" => "missing target lang"); } if (!empty($this->result['error'])) { return -1; } if (!empty($this->id_translator)) { $this->key = $this->calculateMyMemoryKey($this->id_translator); log::doLog("key is {$this->key}"); } $set_results = addToMM($this->source, $this->target, $this->source_lang, $this->target_lang, $this->id_translator, $this->key); $this->result['code'] = 1; $this->result['data'] = "OK"; }
public function doAction() { try { log::doLog("CASMACAT: loadLogChunkController->doAction(): Loading logListChunk..."); $logListChunk = fetchLogChunk($this->jobId, $this->fileId, $this->startOffset, $this->endOffset); if ($logListChunk < 0) { $this->result["code"] = -1; $this->result["errors"][] = array("code" => -1, "message" => "Error loading logListChunk"); } else { if (!$logListChunk) { $this->result["code"] = 1; $this->result["data"] = "No more data"; } else { $this->result["code"] = 0; // $this->result["data"]["logListChunk"] = json_encode($logListChunk); $this->result["data"]["logListChunk"] = $logListChunk; } } log::doLog("CASMACAT: loadLogChunkController->doAction(): Loading of logListChunk finished, " . count($logListChunk) . " events loaded."); } catch (Exception $e) { $this->result["code"] = -1; $this->result["errors"][] = array("code" => -1, "message" => "Unexcpected error: '" . $e->GetMessage() . "'"); log::doLog("CASMACAT: loadLogChunkController->doAction(): Unexcpected error: '" . $e->GetMessage() . "'"); } }
public function doAction() { $gold_offset = (int) $this->gold_offset; $id = (int) $this->id; log::doLog("CASMACAT: gold offset: " . $gold_offset . " id: " . $id); $db = Database::obtain(); try { $db->query("UPDATE fixation_event SET gold_offset='{$gold_offset}' WHERE header_id = '{$id}'"); } catch (Exception $e) { log::doLog("CASMACAT: expection " . $e); } }
private function __construct() { //get languages file // // SDL supported language codes // http://kb.sdl.com/kb/?ArticleId=2993&source=Article&c=12&cid=23#tab:homeTab:crumb:7:artId:4878 $file = INIT::$UTILS_ROOT . '/Langs/supported_langs.json'; if (!file_exists($file)) { log::doLog("no language defs found in {$file}"); exit; } $string = file_get_contents($file); //parse to associative array $langs = json_decode($string, true); $langs = $langs['langs']; //build internal maps //for each lang foreach ($langs as $k1 => $lang) { //for each localization of that lang foreach ($lang['localized'] as $k2 => $localizedTagPair) { foreach ($localizedTagPair as $isocode => $localizedTag) { //build mapping of localized string -> rfc code self::$map_string2rfc[$localizedTag] = $lang['rfc3066code']; //add associative reference $langs[$k1]['localized'][$isocode] = $localizedTag; } //remove positional reference unset($langs[$k1]['localized'][$k2]); } } //create internal support objects representation foreach ($langs as $lang) { //add code -> rfc mapping if (isset($lang['languageRegionCode'])) { self::$map_string2rfc[$lang['languageRegionCode']] = $lang['rfc3066code']; } //add rfc fallback self::$map_string2rfc[$lang['rfc3066code']] = $lang['rfc3066code']; //primary pointers are RFC self::$map_rfc2obj[$lang['rfc3066code']] = $lang; //set support for ISO by indirect reference through RFC pointers self::$map_iso2rfc[$lang['isocode']] = $lang['rfc3066code']; //manage ambiguities self::$map_iso2rfc['en'] = 'en-US'; self::$map_iso2rfc['pt'] = 'pt-BR'; } }
private function __construct() { //get languages file // // SDL supported language codes // http://kb.sdl.com/kb/?ArticleId=2993&source=Article&c=12&cid=23#tab:homeTab:crumb:7:artId:4878 $file = INIT::$UTILS_ROOT . '/Langs/languageDomains.json'; if (!file_exists($file)) { log::doLog("no subject defs found in {$file}"); exit; } $string = file_get_contents($file); //parse to associative array $subjects = json_decode($string, true); Utils::raiseJsonExceptionError(); self::$subjectMap = $subjects; }
function addToMM($seg, $tra, $source_lang, $target_lang, $id_translator, $key) { $seg = urlencode($seg); $tra = urlencode($tra); $private_query = ""; if (!empty($id_translator) and !empty($key)) { $id_translator = rawurldecode($id_translator); $key = rawurlencode($key); $private_query = "user={$id_translator}&key={$key}"; } $url = "http://mymemory.translated.net/api/set?seg={$seg}&tra={$tra}&langpair={$source_lang}|{$target_lang}&de=matecatdeveloper@matecat.com&{$private_query}"; log::doLog("set url : {$url}"); $res = file_get_contents($url); log::doLog("res encoded .{$res}"); $res = json_decode($res, true); log::doLog($res); // print_r($res); return $res; }
public function __construct() { parent::__construct(); $this->jid = $this->get_from_get_post("jid"); $this->password = $this->get_from_get_post("password"); $this->step = $this->get_from_get_post("step"); $this->ref_segment = $this->get_from_get_post("segment"); $this->where = $this->get_from_get_post("where"); // log::doLog('LAST LOADED ID - MODIFIED: '.$this->last_loaded_id); // if($this->central_segment) log::doLog('CENTRAL SEGMENT: '.$this->central_segment); // CASMACAT extension start if ($this->get_from_get_post("replay") == "true") { // replay mode log::doLog("CASMACAT: Running in replay mode."); $this->casIsReplaying = true; include_once INIT::$MODEL_ROOT . "/casQueries.php"; } // CASMACAT extension end }
public function doAction() { try { log::doLog("CASMACAT: resetDocumentController->doAction(): Resetting document..."); if (!resetDocument($this->jobId, $this->fileId)) { $this->result["code"] = -1; $this->result["errors"][] = array("code" => -1, "message" => "Error resetting document"); } else { $this->result["code"] = 0; // $this->result["data"]["logListChunk"] = json_encode($logListChunk); $this->result["data"] = "OK"; } log::doLog("CASMACAT: resetDocumentController->doAction(): Document reset."); } catch (Exception $e) { $this->result["code"] = -1; $this->result["errors"][] = array("code" => -1, "message" => "Unexcpected error: '" . $e->GetMessage() . "'"); log::doLog("CASMACAT: resetDocumentController->doAction(): Unexcpected error: '" . $e->GetMessage() . "'"); } }
public function doAction() { if (empty($this->id_segment)) { $this->result['error'][] = array("code" => -1, "message" => "missing id_segment"); } if (empty($this->id_job)) { $this->result['error'][] = array("code" => -2, "message" => "missing id_job"); } if (empty($this->id_first_file)) { $this->result['error'][] = array("code" => -2, "message" => "missing id_job"); } if (empty($this->time_to_edit)) { $this->time_to_edit = 0; } if (empty($this->status)) { $this->status = 'DRAFT'; } if (empty($this->translation)) { log::doLog("empty"); return 0; // won's save empty translation but there is no need to return an error } //ONE OR MORE ERRORS OCCURRED : EXITING if (!empty($this->result['error'])) { log::doLog("Generic Error in SetTranslationController"); return -1; } $this->translation = CatUtils::view2rawxliff($this->translation); $res = CatUtils::addSegmentTranslation($this->id_segment, $this->id_job, $this->status, $this->time_to_edit, $this->translation); if (!empty($res['error'])) { $this->result['error'] = $res['error']; return -1; } $job_stats = CatUtils::getStatsForJob($this->id_job); $file_stats = CatUtils::getStatsForFile($this->id_first_file); $this->result['stats'] = $job_stats; $this->result['file_stats'] = $file_stats; $this->result['code'] = 1; $this->result['data'] = "OK"; }
public function __construct($ext) { if (empty($ext)) { throw new Exception("No extension specified"); } $this->extension = strtolower($ext); switch ($this->extension) { case 'doc': $this->type = 'MSWORD_DOC'; break; case 'docx': $this->type = 'MSWORD_DOCX'; break; case 'txt': $this->type = 'PLAINTEXT'; break; case 'xlf': // Just until we support tag management // Just until we support tag management case 'xliff': // Just until we support tag management // Just until we support tag management case 'sdlxliff': // Just until we support tag management $this->type = 'SDLXLIFF'; break; case 'html': case 'htm': case 'php': $this->type = 'HTML'; break; default: log::doLog("Unrecognized extension {$this->extension} : assign default PLAINTEXT"); $this->type = 'PLAINTEXT'; } }
private function setSuggestionReport($matches) { if (count($matches) > 0) { foreach ($matches as $k => $m) { $matches[$k]['raw_translation'] = CatUtils::view2rawxliff($matches[$k]['raw_translation']); if ($matches[$k]['created_by'] == 'MT!') { $matches[$k]['created_by'] = 'MT'; //MyMemory returns MT! } else { $matches[$k]['created_by'] = $this->__changeSuggestionSource($m); } } $suggestions_json_array = json_encode($matches); $match = $matches[0]; !empty($match['sentence_confidence']) ? $mt_qe = floatval($match['sentence_confidence']) : ($mt_qe = null); $data = array(); $data['suggestions_array'] = $suggestions_json_array; $data['suggestion'] = $match['raw_translation']; $data['mt_qe'] = $mt_qe; $data['suggestion_match'] = str_replace('%', '', $match['match']); $where = " id_segment= " . (int) $this->id_segment . " and id_job = " . (int) $this->id_job . " and status = 'NEW' "; $db = Database::obtain(); try { $affectedRows = $db->update('segment_translations', $data, $where); } catch (PDOException $e) { log::doLog($e->getMessage()); return $e->getCode() * -1; } return $affectedRows; } return 0; }
function insertEpenEvent($event) { $headerId = insertLogEventHeader($event); $data = array(); $data["id"] = "NULL"; $data["header_id"] = $headerId; $data["info"] = json_encode($event->info); $db = Database::obtain(); $db->insert("epen_event", $data); $err = $db->get_error(); $errno = $err["error_code"]; if ($errno != 0) { log::doLog("CASMACAT: insertEpenEvent(): " . print_r($err, true)); throw new Exception("CASMACAT: insertEpenEvent(): " . print_r($err, true)); // return $errno * -1; } }
$logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_ADD_STROKE: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_END: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_GESTURE: $logEvent->epenData($value); insertEpenEvent($logEvent); break; // merc - blur/focus // merc - blur/focus case LogEvent::BLUR: insertLogEventHeader($logEvent); break; case LogEvent::FOCUS: insertLogEventHeader($logEvent); break; default: log::doLog("CASMACAT: uploadXML: '{$logEvent->type}' at index: '{$key}'"); } } } ?>
public function convertToOriginal($xliffVector, $chosen_by_user_machine = false) { $xliffContent = $xliffVector['content']; $xliffName = $xliffVector['out_xliff_name']; // Log::dolog( $xliffName ); //assign converter if (!$chosen_by_user_machine) { $this->ip = $this->pickRandConverter(); $storage = $this->getValidStorage(); //add replace/regexp pattern because we have more than 1 replacement //http://stackoverflow.com/questions/2222643/php-preg-replace $xliffContent = self::replacedAddress($storage, $xliffContent); } else { $this->ip = $chosen_by_user_machine; } $url = "{$this->ip}:{$this->port}/{$this->fromXliffFunction}"; $uid_ext = $this->extractUidandExt($xliffContent); $data['uid'] = $uid_ext[0]; //get random name for temporary location $tmp_name = tempnam("/tmp", "MAT_BW"); //write encoded file to temporary location $fileSize = file_put_contents($tmp_name, $xliffContent); //$data['xliffContent'] = $xliffContent; $data['xliffContent'] = "@{$tmp_name}"; log::doLog($this->ip . " start conversion back to original"); $start_time = microtime(true); //TODO: this helper doesn't help! //How TODO: create a resource handler e return it, so it can be added to a MultiCurl Handler instance $curl_result = $this->curl_post($url, $data, $this->opt); $end_time = microtime(true); $time_diff = $end_time - $start_time; log::doLog($this->ip . " took {$time_diff} secs"); $this->conversionObject->ip_machine = $this->ip; $this->conversionObject->ip_client = Utils::getRealIpAddr(); $this->conversionObject->path_name = $xliffVector['out_xliff_name']; $this->conversionObject->file_name = pathinfo($xliffVector['out_xliff_name'], PATHINFO_BASENAME); $this->conversionObject->direction = 'bw'; $this->conversionObject->src_lang = $this->lang_handler->getLangRegionCode($xliffVector['source']); $this->conversionObject->trg_lang = $this->lang_handler->getLangRegionCode($xliffVector['target']); $this->conversionObject->file_size = $fileSize; $this->conversionObject->conversion_time = $time_diff; $decode = json_decode($curl_result, true); unset($curl_result); $res = $this->__parseOutput($decode); unset($decode); //remove temporary file unlink($tmp_name); return $res; }
// // $err = $db->get_error(); // $errno = $err["error_code"]; // if ($errno != 0) { // log::doLog("CASMACAT: fetchLogChunk(): " . print_r($err, true)); // throw new Exception("CASMACAT: fetchLogChunk(): " . print_r($err, true)); // } //------------------------------------------------------------------------------------------------ //config_event $to_print = $to_print . "Configuration:\n"; $q = "SELECT h.id as id, h.job_id as job_id, h.file_id as file_id, h.element_id as element_id, h.x_path as x_path, h.time as time, h.type as type, " . "c.config" . " FROM log_event_header h, config_event c WHERE h.job_id = '{$jobId}' AND h.file_id = '{$fileId}' AND h.id = c.header_id ORDER BY h.time, h.id ASC"; $queryId = $db->query($q); $err = $db->get_error(); $errno = $err["error_code"]; if ($errno != 0) { log::doLog("CASMACAT: fetchLogChunk(): " . print_r($err, true)); throw new Exception("CASMACAT: fetchLogChunk(): " . print_r($err, true)); } $configRow = null; $configEvents = array(); while (($configRow = $db->fetch($queryId)) != false) { $configRowAsObject = snakeToCamel($configRow); //log::doLog("CASMACAT: fetchLogChunk(): Next headerRow: " . print_r($configRowAsObject, true)); $configEvent = new LogEvent($jobId, $fileId, $configRowAsObject); $configEvent->configData($configRowAsObject); //log::doLog("CASMACAT: fetchLogChunk(): configEvent: " . print_r($configEvent,true)); $configs = explode(",", $configEvent->config); foreach ($configs as $c) { $to_print = $to_print . "{$c}\n"; } //$to_print = $to_print. $configEvent->config."\n";
function extractSegments($files_path, $file, $pid, $fid, $jid) { // Output // true = ok // -1 = Extension not supported // -2 = Parse Error // -3 = DB Error $mysql_hostname = INIT::$DB_SERVER; // Database Server machine $mysql_database = INIT::$DB_DATABASE; // Database Name $mysql_username = INIT::$DB_USER; // Database User $mysql_password = INIT::$DB_PASS; // Database Password $mysql_link = mysql_connect($mysql_hostname, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $mysql_link); $query_segment = array(); // Checking Extentions $info = pathinfo($file); if ($info['extension'] == 'xliff' || $info['extension'] == 'sdlxliff' || $info['extension'] == 'xlf') { $content = file_get_contents("{$files_path}/{$file}"); } else { log::doLog("Xliff Import: Extension " . $info['extension'] . " not managed"); return false; } $xliff_obj = new Xliff_Parser(); $xliff = $xliff_obj->Xliff2Array($content); //log::doLog($xliff); // Checking that parsing went well if (isset($xliff['parser-errors']) or !isset($xliff['files'])) { log::doLog("Xliff Import: Error parsing. " . join("\n", $xliff['parser-errors'])); return false; } // Creating the Query foreach ($xliff['files'] as $xliff_file) { $count = 0; foreach ($xliff_file['trans-units'] as $xliff_trans_unit) { $count = $count + 1; if (!isset($xliff_trans_unit['attr']['translate'])) { $xliff_trans_unit['attr']['translate'] = 'yes'; } if ($xliff_trans_unit['attr']['translate'] == "no") { log::doLog("Xliff Import: Skipping segment marked as non-translatable: " . $xliff_trans_unit['source']['raw-content']); } else { // If the XLIFF is already segmented (has <seg-source>) if (isset($xliff_trans_unit['seg-source'])) { foreach ($xliff_trans_unit['seg-source'] as $seg_source) { $show_in_cattool = 1; $tempSeg = stripTagsFromSource2($seg_source['raw-content']); $tempSeg = trim($tempSeg); if (empty($tempSeg)) { $show_in_cattool = 0; } $mid = mysql_real_escape_string($seg_source['mid']); $ext_tags = mysql_real_escape_string($seg_source['ext-prec-tags']); $source = mysql_real_escape_string($seg_source['raw-content']); $ext_succ_tags = mysql_real_escape_string($seg_source['ext-succ-tags']); $num_words = CatUtils::segment_raw_wordcount($seg_source['raw-content']); $trans_unit_id = mysql_real_escape_string($xliff_trans_unit['attr']['id']); $query_segment = "('{$trans_unit_id}',{$fid},'{$source}',{$num_words},'{$mid}','{$ext_tags}','{$ext_succ_tags}',{$show_in_cattool})"; } } else { $show_in_cattool = 1; $tempSeg = stripTagsFromSource2($xliff_trans_unit['source']['raw-content']); $tempSeg = trim($tempSeg); if (empty($tempSeg)) { $show_in_cattool = 0; } $source = mysql_real_escape_string($xliff_trans_unit['source']['raw-content']); $num_words = CatUtils::segment_raw_wordcount($xliff_trans_unit['source']['raw-content']); $trans_unit_id = mysql_real_escape_string($xliff_trans_unit['attr']['id']); $query_segment = "('{$trans_unit_id}',{$fid},'{$source}',{$num_words},NULL,NULL,NULL,{$show_in_cattool})"; } $ret = true; // Executing the Query $query_segment = "INSERT INTO segments (internal_id,id_file, segment, raw_word_count, xliff_mrk_id, xliff_ext_prec_tags, xliff_ext_succ_tags, show_in_cattool)\n values " . $query_segment; //log::doLog($query_segment); //exit; $res = mysql_query($query_segment, $mysql_link); if (!$res) { log::doLog("File import - DB Error: " . mysql_error() . " - {$query_segment}\n"); $ret = false; } if (isset($xliff_trans_unit['target'])) { $target = mysql_real_escape_string($xliff_trans_unit['target']['raw-content']); //log::doLog("Target: ".$target); if (!empty($target)) { $last_id = mysql_insert_id($mysql_link); //log::doLog("Last_id: ".$last_id); $query_segment_translations = "('{$last_id}', '{$jid}','TRANSLATED','{$target}',NULL,NULL,NULL,NULL, NULL, NULL, '{$target}',NULL,NULL,NULL)"; // Executing the Query $query_segment_translations = "INSERT INTO segment_translations (id_segment, id_job,status, translation, translation_date, time_to_edit, match_type, context_hash, eq_word_count, suggestions_array, suggestion, suggestion_match, suggestion_source, suggestion_position)\n values " . $query_segment_translations; //log::doLog($query_segment_translations); $res2 = mysql_query($query_segment_translations, $mysql_link); if (!$res2) { log::doLog("File import - DB Error: " . mysql_error() . " - {$query_segment_translations}\n"); $ret = false; } } } } } } return $ret; }
public function get($segment, $source_lang, $target_lang, $key = "") { $source_lang = $this->fix_language($source_lang); $target_lang = $this->fix_language($target_lang); $parameters = array(); $parameters['q'] = $segment; $parameters['source'] = $source_lang; $parameters['target'] = $target_lang; $parameters['key'] = $key; $this->doQuery("get", $parameters); // echo "--- $this->raw_result --"; $this->result = new MT_RESULT($this->raw_result); log::doLog("--------------------------------------------------------------------------------------"); //log::doLog($this->result->error); /* if (!empty($this->result->error->code) and $this->result->error->code != "200") { return array(-1, $this->result->error->message); }*/ return array(0, $this->result->translatedText); }
function getNextSegmentId($sid, $jid, $status) { $rules = $status == 'untranslated' ? "'NEW','DRAFT','REJECTED'" : "'{$status}'"; $statusIsNull = $status == 'untranslated' ? " OR status IS NULL" : ""; // Warning this is a LEFT join a little slower... $query = "select s.id as sid\n\t\t\t\tfrom segments s\n\t\t\t\tLEFT JOIN segment_translations st on st.id_segment = s.id\n\t\t\t\tINNER JOIN files_job fj on fj.id_file=s.id_file \n\t\t\t\tINNER JOIN jobs j on j.id=fj.id_job \n\t\t\t\twhere fj.id_job={$jid} AND \n\t\t\t\t\t (status in ({$rules}){$statusIsNull}) and s.id>{$sid}\n\t\t\t\tand s.show_in_cattool=1\n\t\t\t\torder by s.id\n\t\t\t\tlimit 1\n\t\t\t"; $db = Database::obtain(); $results = $db->query_first($query); log::doLog("NEXT"); log::doLog($results); return $results['sid']; }
private function buildQuery($function, $parameters) { $function = strtolower(trim($function)); $this->url = "{$this->base_url}/" . $this->{$function . "_url"} . "?"; if (is_array($this->extra_parameters) and !empty($this->extra_parameters)) { $parameters = array_merge($parameters, $this->extra_parameters); } log::doLog("engine input parameters"); log::doLog($parameters); $parameters_query_string = http_build_query($parameters); $this->url .= $parameters_query_string; //echo " eurl $this->url"; exit; log::doLog("\n engine url {$this->url}\n"); }
public function doAction() { if ($this->jsonError !== JSON_ERROR_NONE) { $this->result["code"] = $this->jsonError; $msg = "Unknown error"; switch ($this->jsonError) { case JSON_ERROR_NONE: // No error has occurred break; case JSON_ERROR_DEPTH: $msg = "The maximum stack depth has been exceeded"; break; case JSON_ERROR_STATE_MISMATCH: $msg = "Invalid or malformed JSON"; break; case JSON_ERROR_CTRL_CHAR: $msg = "Control character error, possibly incorrectly encoded"; break; case JSON_ERROR_SYNTAX: $msg = "Syntax error"; break; case JSON_ERROR_UTF8: $msg = "Malformed UTF-8 characters, possibly incorrectly encoded"; break; } $this->result["errors"][] = array("code" => -1, "message" => "Unexcpected JSON decode error: '{$msg}'"); log::doLog("CASMACAT: saveLogChunkController->doAction(): Unexcpected JSON decode error: '{$msg}', logList: '" . print_r($this->logList, true) . "'"); return; } $db = Database::obtain(); $db->query("SET AUTOCOMMIT=0"); $db->query("START TRANSACTION"); try { $eventCount = count($this->logList); log::doLog("CASMACAT: saveLogChunkController->doAction(): Processing of logList containing '" . $eventCount . "' elements..."); if (!is_array($this->logList)) { log::doLog("CASMACAT: saveLogChunkController->doAction(): Not an array: '" . print_r($this->logList, true) . "'."); throw new Exception("CASMACAT: saveLogChunkController->doAction(): Not an array: '" . print_r($this->logList, true) . "'."); } // TODO how about transactions? foreach ($this->logList as $key => $value) { // $value = (object) $value; $logEvent = new LogEvent($this->jobId, $this->fileId, $value); switch ($logEvent->type) { case LogEvent::START_SESSION: insertLogEventHeader($logEvent); break; case LogEvent::STOP_SESSION: insertLogEventHeader($logEvent); break; case LogEvent::RESIZE: $logEvent->resizeData($value); insertResizeEvent($logEvent); break; case LogEvent::TEXT: $logEvent->textData($value); insertTextEvent($logEvent); break; case LogEvent::SELECTION: $logEvent->selectionData($value); insertSelectionEvent($logEvent); break; case LogEvent::SCROLL: $logEvent->scrollData($value); insertScrollEvent($logEvent); break; case LogEvent::GAZE: $logEvent->gazeData($value); insertGazeEvent($logEvent); break; case LogEvent::FIXATION: $logEvent->fixationData($value); insertFixationEvent($logEvent); break; case LogEvent::DRAFTED: case LogEvent::TRANSLATED: case LogEvent::APPROVED: case LogEvent::REJECTED: insertLogEventHeader($logEvent); break; case LogEvent::VIEWPORT_TO_SEGMENT: insertLogEventHeader($logEvent); break; case LogEvent::SOURCE_COPIED: insertLogEventHeader($logEvent); break; case LogEvent::SEGMENT_OPENED: insertLogEventHeader($logEvent); break; case LogEvent::SEGMENT_CLOSED: insertLogEventHeader($logEvent); break; case LogEvent::LOADING_SUGGESTIONS: insertLogEventHeader($logEvent); break; case LogEvent::SUGGESTIONS_LOADED: $logEvent->suggestionsLoadedData($value); insertSuggestionsLoadedEvent($logEvent); break; case LogEvent::SUGGESTION_CHOSEN: $logEvent->suggestionChosenData($value); insertSuggestionChosenEvent($logEvent); break; case LogEvent::DELETING_SUGGESTION: $logEvent->deletingSuggestionData($value); insertDeletingSuggestionEvent($logEvent); break; case LogEvent::SUGGESTION_DELETED: insertLogEventHeader($logEvent); break; case LogEvent::STATS_UPDATED: $logEvent->statsUpdatedData($value); insertStatsUpdatedEvent($logEvent); break; case LogEvent::DECODE: case LogEvent::ALIGNMENTS: case LogEvent::SUFFIX_CHANGE: case LogEvent::CONFIDENCES: case LogEvent::TOKENS: case LogEvent::SHOW_ALIGNMENT_BY_KEY: case LogEvent::HIDE_ALIGNMENT_BY_KEY: $logEvent->itpData($value); insertItpEvent($logEvent); break; case LogEvent::SHOW_ALIGNMENT_BY_MOUSE: case LogEvent::HIDE_ALIGNMENT_BY_MOUSE: insertLogEventHeader($logEvent); break; case LogEvent::KEY_DOWN: case LogEvent::KEY_UP: $logEvent->keyData($value); insertKeyEvent($logEvent); break; case LogEvent::MOUSE_DOWN: case LogEvent::MOUSE_UP: case LogEvent::MOUSE_CLICK: case LogEvent::MOUSE_MOVE: $logEvent->mouseData($value); insertMouseEvent($logEvent); break; case LogEvent::BEFORE_CUT: case LogEvent::BEFORE_COPY: case LogEvent::BEFORE_PASTE: insertLogEventHeader($logEvent); break; case LogEvent::VIS_MENU_DISPLAYED: case LogEvent::VIS_MENU_HIDDEN: insertLogEventHeader($logEvent); break; case LogEvent::INITIAL_CONFIG: case LogEvent::CONFIG_CHANGED: $logEvent->configData($value); insertConfigEvent($logEvent); break; case LogEvent::MOUSE_WHEEL_DOWN: case LogEvent::MOUSE_WHEEL_UP: case LogEvent::MOUSE_WHEEL_INVALIDATE: insertLogEventHeader($logEvent); break; case LogEvent::MEMENTO_UNDO: case LogEvent::MEMENTO_REDO: case LogEvent::MEMENTO_INVALIDATE: insertLogEventHeader($logEvent); break; case LogEvent::SR_MENU_DISPLAYED: case LogEvent::SR_MENU_HIDDEN: case LogEvent::SR_MATCH_CASE_ON: case LogEvent::SR_MATCH_CASE_OFF: case LogEvent::SR_REG_EXP_ON: case LogEvent::SR_REG_EXP_OFF: case LogEvent::SR_RULES_SETTING: insertLogEventHeader($logEvent); break; case LogEvent::SR_RULES_SET: $logEvent->srRulesSetData($value); insertSrEvent($logEvent); break; case LogEvent::SR_RULES_APPLIED: case LogEvent::SR_RULE_DELETED: insertLogEventHeader($logEvent); break; // merc - adding float prediction, biconcordancer and translation_option // merc - adding float prediction, biconcordancer and translation_option case LogEvent::FLOAT_PREDICTION: insertLogEventHeader($logEvent); break; case LogEvent::BICONCOR: $logEvent->biconcorData($value); insertBiconcorEvent($logEvent); break; case LogEvent::BICONCOR_CLOSED: insertLogEventHeader($logEvent); break; case LogEvent::TRANSLATION_OPTION: insertLogEventHeader($logEvent); break; // merc - adding epen // merc - adding epen case LogEvent::EPEN_OPENED: insertLogEventHeader($logEvent); break; case LogEvent::EPEN_CLOSED: insertLogEventHeader($logEvent); break; case LogEvent::HTR_RESULT: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_UPDATE: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_NBEST_CLICK: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_TEXT_CHANGE: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_START: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_ADD_STROKE: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_END: $logEvent->epenData($value); insertEpenEvent($logEvent); break; case LogEvent::HTR_GESTURE: $logEvent->epenData($value); insertEpenEvent($logEvent); break; // merc - blur/focus // merc - blur/focus case LogEvent::BLUR: insertLogEventHeader($logEvent); break; case LogEvent::FOCUS: insertLogEventHeader($logEvent); break; default: // $db->query("COMMIT"); // at least, store what was ok // $db->query("SET AUTOCOMMIT=1"); // $this->result["executionTime"] = time() - $this->startTime; $this->result["code"] = -1; $this->result["errors"][] = array("code" => -1, "message" => "Unknown log event type: '{$logEvent->type}' at index: '{$key}'"); log::doLog("CASMACAT: saveLogChunkController->doAction(): '{$logEvent->type}' at index: '{$key}'"); // throw new Exception("CASMACAT: saveLogChunkController->doAction(): Unknown log event type: '$logEvent->type' at index: '$key'"); // return -1; // do not stop saving of events here } } $db->query("COMMIT"); $db->query("SET AUTOCOMMIT=1"); $this->result["executionTime"] = Tools::getCurrentMillis() - $this->startTime; if (!isset($this->result["code"])) { $this->result["code"] = 0; } $this->result["data"] = "OK"; log::doLog("CASMACAT: saveLogChunkController->doAction(): Processing of logList containing '" . $eventCount . "' elements finished, time used: '" . $this->result["executionTime"] . "' ms."); } catch (Exception $e) { $db->query("COMMIT"); // at least, store what was ok $db->query("SET AUTOCOMMIT=1"); // $this->result["executionTime"] = time() - $this->startTime; $this->result["code"] = -1; $this->result["errors"][] = array("code" => -1, "message" => "Unexpected error: '" . $e->GetMessage() . "'"); log::doLog("CASMACAT: saveLogChunkController->doAction(): Unexpected error: '" . $e->GetMessage() . "'"); } }
public static function Xliff2Array($file_content) { // Pre-Processing. // Fixing non UTF-8 encoding (often I get Unicode UTF-16) $enc = mb_detect_encoding($file_content); if ($enc != 'UTF-8') { $file_content = iconv($enc, 'UTF-8', $file_content); $xliff['parser-warnings'][] = "Input identified as {$enc} ans converted UTF-8. May not be a problem if the content is English only"; } // Checking Requirements (By specs, I know that xliff version is in the first 1KB) preg_match('|<xliff\\s.*?version\\s?=\\s?["\'](.*?)["\']|si', substr($file_content, 0, 1000), $tmp); if (!isset($tmp[1])) { $xliff['parser-errors'][] = "Cannot import. This does not seems a valid XLIFF, we support version 1.0, 1.1, 1.2."; return $xliff; } if (!in_array($tmp[1], array('1.0', '1.1', '1.2'))) { $xliff['parser-errors'][] = "Cannot import XLIFF version {$tmp['1']}. We only support XLIFF (version 1.0, 1.1, 1.2)."; return $xliff; } // Getting the Files $files = preg_split('|<file[\\s>]|si', $file_content, -1, PREG_SPLIT_NO_EMPTY); $i = 0; foreach ($files as $file) { // First element in the XLIFF split is the content before <file> (header), skipping if ($i > 0) { // Getting Files Attributes // Restrict preg action for speed, just for attributes $file_short = substr($file, 0, strpos($file, '>') + 1); // Original unset($temp); preg_match('|original\\s?=\\s?["\'](.*?)["\']|si', $file_short, $temp); $xliff['files'][$i]['attr']['original'] = $temp[1]; // Source-language unset($temp); preg_match('|source-language\\s?=\\s?["\'](.*?)["\']|si', $file_short, $temp); $xliff['files'][$i]['attr']['source-language'] = $temp[1]; // Data-type unset($temp); preg_match('|datatype\\s?=\\s?["\'](.*?)["\']|si', $file_short, $temp); $xliff['files'][$i]['attr']['datatype'] = $temp[1]; // Target-language unset($temp); preg_match('|target-language\\s?=\\s?["\'](.*?)["\']|si', $file_short, $temp); if (isset($temp[1])) { $xliff['files'][$i]['attr']['target-language'] = $temp[1]; } // Getting Trans-units $trans_units = preg_split('|<trans-unit[\\s>]|si', $file, -1, PREG_SPLIT_NO_EMPTY); $j = 0; foreach ($trans_units as $trans_unit) { // First element in the XLIFF split is the header, not the first file if ($j > 0) { // Getting Trans-unit attributes // ID unset($temp); preg_match('|id\\s?=\\s?["\'](.*?)["\']|si', $trans_unit, $temp); $xliff['files'][$i]['trans-units'][$j]['attr']['id'] = $temp[1]; // Translate unset($temp); preg_match('|translate\\s?=\\s?["\'](.*?)["\']|si', $trans_unit, $temp); if (isset($temp[1])) { $xliff['files'][$i]['trans-units'][$j]['attr']['translate'] = $temp[1]; } // Getting Source and Target raw content unset($temp); preg_match('|<source.*?>(.*?)</source>|si', $trans_unit, $temp); // just in case of a <source /> if (!isset($temp[1])) { $temp[1] = ''; } $temp[1] = self::fix_non_well_formed_xml($temp[1]); $xliff['files'][$i]['trans-units'][$j]['source']['raw-content'] = $temp[1]; unset($temp); preg_match('|<target.*?>(.*?)</target>|si', $trans_unit, $temp); if (isset($temp[1])) { $temp[1] = self::fix_non_well_formed_xml($temp[1]); $xliff['files'][$i]['trans-units'][$j]['target']['raw-content'] = $temp[1]; } // Add here other trans-unit sub-elements you need, copying and pasting the 3 lines below unset($temp); preg_match('|<seg-source.*?>(.*?)</seg-source>|si', $trans_unit, $temp); // if (isset($temp[1])) $xliff['files'][$i]['trans-units'][$j]['seg-sources']['raw-content'] = $temp[1]; if (isset($temp[1])) { $markers = $temp[1]; unset($temp); log::doLog("BEFORE"); log::doLog($markers); $markers = preg_split('#(<mrk\\s.*?type="seg".*?>(.*?)</mrk>)#si', $markers, -1, PREG_SPLIT_DELIM_CAPTURE); log::doLog("AFTER"); log::doLog($markers); $mi = 0; $k = 0; while (isset($markers[$mi + 1])) { log::doLog("mi is {$mi} - exits \$marckers[\$mi +1]"); unset($mid); preg_match('|mid\\s?=\\s?["\'](.*?)["\']|si', $markers[$mi + 1], $mid); // For not loosing info I attach the last external tag to the last seg marker. if (!isset($markers[$mi + 5])) { $last_ext_tags = $markers[$mi + 3]; } else { $last_ext_tags = ''; } $xliff['files'][$i]['trans-units'][$j]['seg-source'][$k]['mid'] = $mid[1]; $xliff['files'][$i]['trans-units'][$j]['seg-source'][$k]['ext-prec-tags'] = $markers[$mi]; $xliff['files'][$i]['trans-units'][$j]['seg-source'][$k]['raw-content'] = $markers[$mi + 2]; $xliff['files'][$i]['trans-units'][$j]['seg-source'][$k]['ext-succ-tags'] = $last_ext_tags; // Different from source and target content, I expect that if you used seg-source it is a a well done tool so I don't try to fix. $mi = $mi + 3; $k++; } log::doLog("mi exit {$mi} \n\n"); } } $j++; } // End of trans-units } // End of files $i++; } //log::doLog ($xliff); //echo "<pre>"; print_r ($xliff); exit; return $xliff; }
public static function addSegmentTranslation($id_segment, $id_job, $status, $time_to_edit, $translation) { $insertRes = setTranslationInsert($id_segment, $id_job, $status, $time_to_edit, $translation); log::doLog("translation is {$translation} - encoded " . htmlentities($translation)); if ($insertRes < 0 and $insertRes != -1062) { $result['error'][] = array("code" => -4, "message" => "error occurred during the storing (INSERT) of the translation for the segment {$id_segment} - {$insertRes}"); return $result; } if ($insertRes == -1062) { $updateRes = setTranslationUpdate($id_segment, $id_job, $status, $time_to_edit, $translation); if ($updateRes < 0) { $result['error'][] = array("code" => -5, "message" => "error occurred during the storing (UPDATE) of the translation for the segment {$id_segment}"); return $result; } } return 0; }
public function setTemplateVars() { $this->template->itpserver = INIT::$ITP_SERVER; $this->template->htrserver = INIT::$HTR_SERVER; $this->template->biconcorserver = INIT::$BICONCOR_SERVER; $this->template->jid = $this->jid; $this->template->password = $this->password; $this->template->cid = $this->cid; $this->template->create_date = $this->create_date; $this->template->pname = $this->pname; $this->template->pid = $this->pid; $this->template->tid = $this->tid; $this->template->source = $this->source; $this->template->target = $this->target; //$this->template->cucu=$this->open_segment; if (!empty($_GET["itp-server"])) { $this->template->itpserver = $_GET["itp-server"]; } if ($this->page) { // use this only when a value has been given. And yes, we should homogenize stuff like this ASAP!! // FIXME: This is a temp workaround for the pre-evaluation. We should homogenize stuff like this ASAP! // We reuse the $page var to indicate the CAT client configuration, since $page is actually not being used in the prototype. $delimiters = array(":", "@"); foreach ($delimiters as $delim) { if (strpos($this->page, $delim) !== false) { break; // We have found the current delimiter } else { $delim = null; } } $server_url = INIT::$ITP_SERVER; // We can't access template vars before PHPTAL populates them $path_parts = explode("/", $server_url); $server_data = $path_parts[0]; if ($delim) { list($catsetting, $portnum) = explode($delim, $this->page); $this->template->catsetting = $catsetting; if (intval($portnum) > 0) { if (strstr($server_url, "http://") === true) { $server_url = str_replace("http://", "", $server_url); } // In nginx we use the @ to change port number at runtime, otherwise we'll pass the port as usual (:) if (strpos($server_data, "@") !== false) { $server_data = preg_replace('/@[0-9]+/', $delim . $portnum, $server_data); } elseif (strpos($server_data, ":") !== false) { $server_data = preg_replace('/:[0-9]+/', $delim . $portnum, $server_data); } } } else { $this->template->catsetting = $this->page; } $path_parts[0] = $server_data; $this->template->itpserver = implode("/", $path_parts); } else { $this->template->catsetting = ""; } // $this->template->stats=$stats[0]['TOTAL']; $this->template->source_code = $this->source_code; $this->template->target_code = $this->target_code; // CASMACAT extension start $this->template->logEnabled = INIT::$LOG_ENABLED; $this->template->logMaxChunkSize = INIT::$LOG_MAXCHUNKSIZE; $this->template->casIsReplaying = $this->casIsReplaying; // do this always, otherwise an error will be thrown in PHPTAL // when accessing template variables log::doLog("CASMACAT: Setting additional template variables..."); $this->template->debug = INIT::$DEBUG; $this->template->itpEnabled = INIT::$ITP_ENABLED; $this->template->penEnabled = INIT::$PEN_ENABLED; $this->template->etEnabled = INIT::$ET_ENABLED; $this->template->etType = INIT::$ET_TYPE; $this->template->srEnabled = INIT::$SR_ENABLED; $this->template->biconcorEnabled = INIT::$BICONCOR_ENABLED; $this->template->hideContributions = INIT::$HIDE_CONTRIBUTIONS; $this->template->floatPredictions = INIT::$FLOAT_PREDICTIONS; $this->template->translationOptions = INIT::$TRANSLATION_OPTIONS; $this->template->allowChangeVisualizationOptions = INIT::$ALLOW_CHANGE_VISUALIZATION_OPTIONS; $this->template->itpDraftOnly = INIT::$ITP_DRAFT_ONLY; log::doLog("CASMACAT: itpEnabled: " . INIT::$ITP_ENABLED); log::doLog("CASMACAT: etEnabled: " . INIT::$ET_ENABLED); if (INIT::$LOG_ENABLED) { log::doLog("CASMACAT: Correcting 'last_opened_segment'..."); if ($this->casIsReplaying) { $this->last_opened_segment = 0; } else { if (!isset($this->last_opened_segment)) { $this->last_opened_segment = ""; } } } if ($this->casIsReplaying) { // $this->template->fid = $this->initCfg->file_id; // $this->template->logEnabled = $this->initCfg->logEnabled; // $this->template->logMaxChunkSize = $this->initCfg->logMaxChunkSize; // $this->template->replay = $this->initCfg->casIsReplaying; // $this->template->debug = $this->initCfg->debug; $this->template->catsetting = $this->initCfg->catsetting; $this->template->itpEnabled = $this->initCfg->itpEnabled; $this->template->penEnabled = $this->initCfg->penEnabled; $this->template->etEnabled = $this->initCfg->etEnabled; // $this->template->etType = $this->initCfg->etType; $this->template->srEnabled = $this->initCfg->srEnabled; $this->template->biconcorEnabled = $this->initCfg->biconcorEnabled; $this->template->hideContributions = $this->initCfg->hideContributions; $this->template->floatPredictions = $this->initCfg->floatPredictions; $this->template->translationOptions = $this->initCfg->translationOptions; // prefs } // CASMACAT extension end $this->template->fid = $this->fid; $this->template->last_opened_segment = $this->last_opened_segment; $this->template->data = $this->data; $this->template->job_stats = $this->job_stats; $end_time = microtime(true) * 1000; $load_time = $end_time - $this->start_time; $this->template->load_time = $load_time; $this->template->time_to_edit_enabled = INIT::$TIME_TO_EDIT_ENABLED; $this->template->build_number = INIT::$BUILD_NUMBER; $this->template->downloadFileName = $this->downloadFileName; $this->template->job_not_found = $this->job_not_found; // echo "<pre>"; // print_r ($this->template); // exit; }