/** * No More used * * @deprecated * * @param $id_segment * @param $id_job * @param string $suggestions_json_array * @param string $suggestion * @param string $suggestion_match * @param string $suggestion_source * @param string $match_type * @param int $eq_words * @param int $standard_words * @param string $translation * @param string $tm_status_analysis * @param int $warning * @param string $err_json * @param int $mt_qe * @param int $pretranslate_100 * * @return int */ public static function addTranslationSuggestion($id_segment, $id_job, $suggestions_json_array = "", $suggestion = "", $suggestion_match = "", $suggestion_source = "", $match_type = "", $eq_words = 0, $standard_words = 0, $translation = "", $tm_status_analysis = "UNDONE", $warning = 0, $err_json = '', $mt_qe = 0, $pretranslate_100 = 0) { if (!empty($suggestion_source)) { if (strpos($suggestion_source, "MT") === false) { $suggestion_source = 'TM'; } else { $suggestion_source = 'MT'; } } /** * For future refactory, with this SQL construct we halve the number of insert/update queries * * mysql support this: * * INSERT INTO example (id,suggestions_array) VALUES (1,'["key":"we don\'t want this update because of tm_analysis_status is not DONE"]') * ON DUPLICATE KEY UPDATE * suggestions_array = IF( tm_analysis_status = 'DONE' , VALUES(suggestions_array) , suggestions_array ); * */ $segment_status = 'NEW'; //controllare il valore di suggestion_match if ($suggestion_match == "100%" && $pretranslate_100) { $segment_status = 'TRANSLATED'; } $insertRes = setSuggestionInsert($id_segment, $id_job, $suggestions_json_array, $suggestion, $suggestion_match, $suggestion_source, $match_type, $eq_words, $standard_words, $translation, $tm_status_analysis, $warning, $err_json, $mt_qe, $segment_status); if ($insertRes < 0 and $insertRes != -1062) { $result['errors'][] = array("code" => -4, "message" => "error occurred during the storing (INSERT) of the suggestions for the segment {$id_segment} - {$insertRes}"); return $result; } if ($insertRes == -1062) { // the translaion for this segment still exists : update it if ($segment_status !== 'TRANSLATED') { $segment_status = null; } $updateRes = setSuggestionUpdate($id_segment, $id_job, $suggestions_json_array, $suggestion, $suggestion_match, $suggestion_source, $match_type, $eq_words, $standard_words, $translation, $tm_status_analysis, $warning, $err_json, $mt_qe, $segment_status); if ($updateRes < 0) { $result['errors'][] = array("code" => -5, "message" => "error occurred during the storing (UPDATE) of the suggestions for the segment {$id_segment}"); return $result; } } return 0; }
public static function addTranslationSuggestion($id_segment, $id_job, $suggestions_json_array = "", $suggestion = "", $suggestion_match = "", $suggestion_source = "") { if (!empty($suggestion_source)) { if (strpos($suggestion_source, "MT") === false) { $suggestion_source = 'TM'; } else { $suggestion_source = 'MT'; } } $insertRes = setSuggestionInsert($id_segment, $id_job, $suggestions_json_array, $suggestion, $suggestion_match, $suggestion_source); if ($insertRes < 0 and $insertRes != -1062) { $result['error'][] = array("code" => -4, "message" => "error occurred during the storing (INSERT) of the suggestions for the segment {$id_segment} - {$insertRes}"); return $result; } if ($insertRes == -1062) { // the translaion for this segment still exists : update it $updateRes = setSuggestionUpdate($id_segment, $id_job, $suggestions_json_array, $suggestion, $suggestion_match, $suggestion_source); // log::doLog("updateRes"); // log::doLog($updateRes); if ($updateRes < 0) { $result['error'][] = array("code" => -5, "message" => "error occurred during the storing (UPDATE) of the suggestions for the segment {$id_segment}"); return $result; } } return 0; }
function updateTMValues($tm_data) { if (!empty($tm_data['suggestion_source'])) { if (strpos($tm_data['suggestion_source'], "MT") === false) { $tm_data['suggestion_source'] = 'TM'; } else { $tm_data['suggestion_source'] = 'MT'; } } //controllare il valore di suggestion_match if ($tm_data['suggestion_match'] == "100%" && $tm_data['pretranslate_100']) { $tm_data['status'] = Constants_TranslationStatus::STATUS_TRANSLATED; } //there is not a database filed named pretranslate_100 in segment_translations, this is only a flag unset($tm_data['pretranslate_100']); $updateRes = setSuggestionUpdate($tm_data); if ($updateRes < 0) { $result['errors'][] = array("code" => -5, "message" => "error occurred during the storing (UPDATE) of the suggestions for the segment {$tm_data['id_segment']}"); _TimeStampMsg($result); } elseif ($updateRes == 0) { //There was not a fast Analysis??? Impossible. _TimeStampMsg("No row found: " . $tm_data['id_segment'] . "-" . $tm_data['id_job']); } else { _TimeStampMsg("Row found: " . $tm_data['id_segment'] . "-" . $tm_data['id_job'] . " - UPDATED."); } }
/** * @param QueueElement $queueElement * * @throws Exception * @throws ReQueueException */ protected function _updateRecord(QueueElement $queueElement) { $tm_match_type = $this->_matches[0]['match']; if (stripos($this->_matches[0]['created_by'], "MT") !== false) { $tm_match_type = "MT"; } $suggestion = \CatUtils::view2rawxliff($this->_matches[0]['raw_translation']); //preg_replace all x tags <x not closed > inside suggestions with correctly closed $suggestion = preg_replace('|<x([^/]*?)>|', '<x\\1/>', $suggestion); $suggestion_match = $this->_matches[0]['match']; $suggestion_json = json_encode($this->_matches); $suggestion_source = $this->_matches[0]['created_by']; $equivalentWordMapping = json_decode($queueElement->params->payable_rates, true); $new_match_type = $this->_getNewMatchType($tm_match_type, $queueElement->params->match_type, $equivalentWordMapping, empty($this->_matches[0]['memory_key'])); $eq_words = $equivalentWordMapping[$new_match_type] * $queueElement->params->raw_word_count / 100; $standard_words = $eq_words; //if the first match is MT perform QA realignment if ($new_match_type == 'MT') { $standard_words = $equivalentWordMapping["NO_MATCH"] * $queueElement->params->raw_word_count / 100; $check = new \PostProcess($this->_matches[0]['raw_segment'], $suggestion); $check->realignMTSpaces(); //this should every time be ok because MT preserve tags, but we use the check on the errors //for logic correctness if (!$check->thereAreErrors()) { $suggestion = \CatUtils::view2rawxliff($check->getTrgNormalized()); $err_json = ''; } else { $err_json = $check->getErrorsJSON(); } } else { //try to perform only the tagCheck $check = new \PostProcess($queueElement->params->segment, $suggestion); $check->performTagCheckOnly(); //_TimeStampMsg( $check->getErrors() ); if ($check->thereAreErrors()) { $err_json = $check->getErrorsJSON(); } else { $err_json = ''; } } !empty($this->_matches[0]['sentence_confidence']) ? $mt_qe = floatval($this->_matches[0]['sentence_confidence']) : ($mt_qe = null); $tm_data = array(); $tm_data['id_job'] = $queueElement->params->id_job; $tm_data['id_segment'] = $queueElement->params->id_segment; $tm_data['suggestions_array'] = $suggestion_json; $tm_data['suggestion'] = $suggestion; $tm_data['match_type'] = $new_match_type; $tm_data['eq_word_count'] = $eq_words; $tm_data['standard_word_count'] = $standard_words; $tm_data['translation'] = $suggestion; $tm_data['tm_analysis_status'] = "DONE"; $tm_data['warning'] = (int) $check->thereAreErrors(); $tm_data['serialized_errors_list'] = $err_json; $tm_data['mt_qe'] = $mt_qe; $tm_data['suggestion_source'] = $suggestion_source; if (!empty($tm_data['suggestion_source'])) { if (strpos($tm_data['suggestion_source'], "MT") === false) { $tm_data['suggestion_source'] = 'TM'; } else { $tm_data['suggestion_source'] = 'MT'; } } //check the value of suggestion_match $tm_data['suggestion_match'] = $suggestion_match; if ($tm_data['suggestion_match'] == "100%" && $queueElement->params->pretranslate_100) { $tm_data['status'] = \Constants_TranslationStatus::STATUS_TRANSLATED; } $updateRes = setSuggestionUpdate($tm_data); if ($updateRes < 0) { $this->_doLog("**** Error occurred during the storing (UPDATE) of the suggestions for the segment {$tm_data['id_segment']}"); throw new ReQueueException("**** Error occurred during the storing (UPDATE) of the suggestions for the segment {$tm_data['id_segment']}", self::ERR_REQUEUE); } elseif ($updateRes == 0) { //There was not a fast Analysis??? Impossible. $this->_doLog("No row found: " . $tm_data['id_segment'] . "-" . $tm_data['id_job']); } else { $this->_doLog("Row found: " . $tm_data['id_segment'] . "-" . $tm_data['id_job'] . " - UPDATED."); } //set redis cache $this->_incrementAnalyzedCount($queueElement->params->pid, $eq_words, $standard_words); $this->_decSegmentsToAnalyzeOfWaitingProjects($queueElement->params->pid); $this->_tryToCloseProject($queueElement->params->pid); }