public function testSpaces_1() { $source_seg = <<<SRC <g id="pt2">WASHINGTON </g><g id="pt3">— The Treasury Department and Internal Revenue Service today requested public comment on issues relating to the shared responsibility provisions included in the Affordable Care Act that will apply to certain employers starting in 2014.</g> SRC; $target_seg = <<<TRG <g id="pt2"> WASHINGTON </g><g id="pt3">- Il Dipartimento del Tesoro e Internal Revenue Service di oggi hanno chiesto un commento pubblico sulle questioni relative alle disposizioni di responsabilità condivise incluse nel Affordable Care Act che verranno applicate a certi datori di lavoro a partire dal 2014. </g> TRG; $source_seg = CatUtils::view2rawxliff($source_seg); $target_seg = CatUtils::view2rawxliff($target_seg); $check = new QA($source_seg, $target_seg); $check->performConsistencyCheck(); $notices = $check->getNotices(); $warnings = $check->getWarnings(); $errors = $check->getErrors(); $this->assertFalse($check->thereAreErrors()); $this->assertFalse($check->thereAreWarnings()); $this->assertTrue($check->thereAreNotices()); $this->assertEquals(count($notices), 2); $this->assertEquals(1100, $notices[0]->outcome); $this->assertEquals(count($warnings), 1); $this->assertEquals(0, $warnings[0]->outcome); $this->assertEquals(count($errors), 1); $this->assertEquals(0, $errors[0]->outcome); $normalized = $check->getTrgNormalized(); //" 1 " -> 20 31 20 $this->assertEquals('<g id="pt2"> WASHINGTON </g><g id="pt3">- Il Dipartimento del Tesoro e Internal Revenue Service di oggi hanno chiesto un commento pubblico sulle questioni relative alle disposizioni di responsabilità condivise incluse nel Affordable Care Act che verranno applicate a certi datori di lavoro a partire dal 2014. </g>', $normalized); }
public function doAction() { $this->generateAuthURL(); //pay a little query to avoid to fetch 5000 rows $this->data = $jobData = getJobData($this->jid, $this->password); $wStruct = new WordCount_Struct(); $wStruct->setIdJob($this->jid); $wStruct->setJobPassword($this->password); $wStruct->setNewWords($jobData['new_words']); $wStruct->setDraftWords($jobData['draft_words']); $wStruct->setTranslatedWords($jobData['translated_words']); $wStruct->setApprovedWords($jobData['approved_words']); $wStruct->setRejectedWords($jobData['rejected_words']); if ($jobData['status'] == Constants_JobStatus::STATUS_ARCHIVED || $jobData['status'] == Constants_JobStatus::STATUS_CANCELLED) { //this job has been archived $this->job_archived = true; $this->job_owner_email = $jobData['job_owner']; } $this->job_stats = CatUtils::getFastStatsForJob($wStruct); $proj = getProject($jobData['id_project']); $this->project_status = $proj[0]; /** * Retrieve information about job errors * ( Note: these information are fed by the revision process ) * @see setRevisionController */ $jobQA = new Revise_JobQA($this->jid, $this->password, $wStruct->getTotal()); $jobQA->retrieveJobErrorTotals(); $jobVote = $jobQA->evalJobVote(); $this->totalJobWords = $wStruct->getTotal(); $this->qa_data = $jobQA->getQaData(); $this->qa_overall_text = $jobVote['minText']; $this->qa_overall_avg = $jobVote['avg']; $this->qa_equivalent_class = $jobVote['equivalent_class']; }
public function doAction() { $this->generateAuthURL(); //pay a little query to avoid to fetch 5000 rows $this->jobData = $jobData = getJobData($this->jid, $this->password); $wStruct = new WordCount_Struct(); $wStruct->setIdJob($this->jid); $wStruct->setJobPassword($this->password); $wStruct->setNewWords($jobData['new_words']); $wStruct->setDraftWords($jobData['draft_words']); $wStruct->setTranslatedWords($jobData['translated_words']); $wStruct->setApprovedWords($jobData['approved_words']); $wStruct->setRejectedWords($jobData['rejected_words']); if ($jobData['status'] == Constants_JobStatus::STATUS_ARCHIVED || $jobData['status'] == Constants_JobStatus::STATUS_CANCELLED) { //this job has been archived $this->job_archived = true; $this->job_owner_email = $jobData['job_owner']; } $tmp = CatUtils::getEditingLogData($this->jid, $this->password); $this->data = $tmp[0]; $this->stats = $tmp[1]; $this->job_stats = CatUtils::getFastStatsForJob($wStruct); $proj = getProject($jobData['id_project']); $this->project_status = $proj[0]; }
public function __construct() { parent::__construct(); $filterArgs = array('job' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'segment' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'jpassword' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW), 'err_typing' => array('filter' => FILTER_CALLBACK, 'options' => array("setRevisionController", "sanitizeFieldValue")), 'err_translation' => array('filter' => FILTER_CALLBACK, 'options' => array("setRevisionController", "sanitizeFieldValue")), 'err_terminology' => array('filter' => FILTER_CALLBACK, 'options' => array("setRevisionController", "sanitizeFieldValue")), 'err_language' => array('filter' => FILTER_CALLBACK, 'options' => array("setRevisionController", "sanitizeFieldValue")), 'err_style' => array('filter' => FILTER_CALLBACK, 'options' => array("setRevisionController", "sanitizeFieldValue")), 'original' => array('filter' => FILTER_UNSAFE_RAW)); $postInput = filter_input_array(INPUT_POST, $filterArgs); $this->id_job = $postInput['job']; $this->password_job = $postInput['jpassword']; $this->id_segment = $postInput['segment']; $this->err_typing = $postInput['err_typing']; $this->err_translation = $postInput['err_translation']; $this->err_terminology = $postInput['err_terminology']; $this->err_language = $postInput['err_language']; $this->err_style = $postInput['err_style']; list($this->original_translation, $none) = CatUtils::parseSegmentSplit(CatUtils::view2rawxliff($postInput['original']), ' '); Log::doLog($_POST); if (empty($this->id_job)) { $this->result['errors'][] = array('code' => -1, 'message' => 'Job ID missing'); } if (empty($this->id_segment)) { $this->result['errors'][] = array('code' => -2, 'message' => 'Segment ID missing'); } if (empty($this->password_job)) { $this->result['errors'][] = array('code' => -3, 'message' => 'Job password missing'); } }
/** * Return to Javascript client the JSON error list in the form: * * <pre> * array( * [total] => 1 * [details] => Array * ( * ['2224860'] => Array * ( * [id_segment] => 2224860 * [warnings] => '[{"outcome":1000,"debug":"Tag mismatch"}]' * ) * ) * [token] => 'token' * ) * </pre> * */ public function doAction() { if (empty($this->__postInput->id)) { $this->__globalWarningsCall(); } else { $this->__postInput->src_content = CatUtils::view2rawxliff($this->__postInput->src_content); $this->__postInput->trg_content = CatUtils::view2rawxliff($this->__postInput->trg_content); $this->__segmentWarningsCall(); } }
public function doAction() { if (empty($this->segment)) { $this->result['errors'][] = array("code" => -1, "message" => "missing source segment"); } if (empty($this->translation)) { $this->result['errors'][] = array("code" => -2, "message" => "missing target translation"); } if (empty($this->source_lang)) { $this->result['errors'][] = array("code" => -3, "message" => "missing source lang"); } if (empty($this->target_lang)) { $this->result['errors'][] = array("code" => -4, "message" => "missing target lang"); } if (empty($this->time_to_edit)) { $this->result['errors'][] = array("code" => -5, "message" => "missing time to edit"); } if (empty($this->id_segment)) { $this->result['errors'][] = array("code" => -6, "message" => "missing segment id"); } //get Job Infos, we need only a row of jobs ( split ) $job_data = getJobData((int) $this->id_job, $this->password); $pCheck = new AjaxPasswordCheck(); //check for Password correctness if (empty($job_data) || !$pCheck->grantJobAccessByJobData($job_data, $this->password)) { $this->result['errors'][] = array("code" => -10, "message" => "wrong password"); $msg = "\n\n Error \n\n " . var_export(array_merge($this->result, $_POST), true); Log::doLog($msg); Utils::sendErrMailReport($msg); return; } //mt engine to contribute to if ($job_data['id_mt_engine'] <= 1) { return false; } $this->mt = Engine::getInstance($job_data['id_mt_engine']); //array of storicised suggestions for current segment $this->suggestion_json_array = json_decode(getArrayOfSuggestionsJSON($this->id_segment), true); //extra parameters $extra = json_encode(array('id_segment' => $this->id_segment, 'suggestion_json_array' => $this->suggestion_json_array, 'chosen_suggestion_index' => $this->chosen_suggestion_index, 'time_to_edit' => $this->time_to_edit)); //send stuff $config = $this->mt->getConfigStruct(); $config['segment'] = CatUtils::view2rawxliff($this->segment); $config['translation'] = CatUtils::view2rawxliff($this->translation); $config['source'] = $this->source_lang; $config['target'] = $this->target_lang; $config['email'] = INIT::$MYMEMORY_API_KEY; $config['segid'] = $this->id_segment; $config['extra'] = $extra; $config['id_user'] = array("TESTKEY"); $outcome = $this->mt->set($config); if ($outcome->error->code < 0) { $this->result['errors'] = $outcome->error->get_as_array(); } }
public function __construct() { //NEEDED TO UNIFORM DATA as array( $matches ) $args = func_get_args(); if (empty($args)) { throw new Exception("No args defined for " . __CLASS__ . " constructor"); } $match = array(); if (count($args) == 1 and is_array($args[0])) { $match = $args[0]; if ($match['last-update-date'] == "0000-00-00 00:00:00") { $match['last-update-date'] = "0000-00-00"; } if (!empty($match['last-update-date']) and $match['last-update-date'] != '0000-00-00') { $match['last-update-date'] = date("Y-m-d", strtotime($match['last-update-date'])); } if (empty($match['created-by'])) { $match['created-by'] = "Anonymous"; } $match['match'] = $match['match'] * 100; $match['match'] = $match['match'] . "%"; isset($match['prop']) ? $match['prop'] = json_decode($match['prop']) : ($match['prop'] = array()); } if (count($args) > 1 and is_array($args[0])) { throw new Exception("Invalid arg 1 " . __CLASS__ . " constructor"); } if (count($args) == 5 and !is_array($args[0])) { $match['segment'] = CatUtils::rawxliff2view($args[0]); $match['raw_segment'] = $args[0]; $match['translation'] = CatUtils::rawxliff2view($args[1]); $match['raw_translation'] = $args[1]; $match['match'] = $args[2]; $match['created-by'] = $args[3]; $match['last-update-date'] = $args[4]; $match['prop'] = isset($args[5]) ? $args[5] : array(); } $this->id = array_key_exists('id', $match) ? $match['id'] : '0'; $this->create_date = array_key_exists('create-date', $match) ? $match['create-date'] : '0000-00-00'; $this->segment = array_key_exists('segment', $match) ? $match['segment'] : ''; $this->raw_segment = array_key_exists('raw_segment', $match) ? $match['raw_segment'] : ''; $this->translation = array_key_exists('translation', $match) ? $match['translation'] : ''; $this->source_note = array_key_exists('source_note', $match) ? $match['source_note'] : ''; $this->target_note = array_key_exists('target_note', $match) ? $match['target_note'] : ''; $this->raw_translation = array_key_exists('raw_translation', $match) ? $match['raw_translation'] : ''; $this->quality = array_key_exists('quality', $match) ? $match['quality'] : 0; $this->reference = array_key_exists('reference', $match) ? $match['reference'] : ''; $this->usage_count = array_key_exists('usage-count', $match) ? $match['usage-count'] : 0; $this->subject = array_key_exists('subject', $match) ? $match['subject'] : ''; $this->created_by = array_key_exists('created-by', $match) ? $match['created-by'] : ''; $this->last_updated_by = array_key_exists('last-updated-by', $match) ? $match['last-updated-by'] : ''; $this->last_update_date = array_key_exists('last-update-date', $match) ? $match['last-update-date'] : '0000-00-00'; $this->match = array_key_exists('match', $match) ? $match['match'] : 0; $this->memory_key = array_key_exists('key', $match) ? $match['key'] : ''; $this->prop = $match['prop']; }
public function __construct($result) { // print_r($result); $this->error = new MT_ERROR(); if (is_array($result) and array_key_exists("data", $result)) { $this->translatedText = $result['data']['translations'][0]['translatedText']; $this->translatedText = CatUtils::rawxliff2view($this->translatedText); } if (is_array($result) and array_key_exists("error", $result)) { $this->error = new MT_ERROR($result['error']); } }
/** * * * @param $_string * * @return string */ protected function _preserveSpecialStrings($_string) { preg_match_all(self::IOS_STRINGS_REGEXP, $_string, $matches); $matches = $matches[0]; $placeholders = array(); for ($i = 0; $i < count($matches); $i++) { $placeholders[] = CatUtils::generate_password(); } $this->_patterns_found = array_combine($matches, $placeholders); foreach ($this->_patterns_found as $str => $placeholder) { $_string = str_replace($str, $placeholder, $_string); } return $_string; }
public function doAction() { if (!$this->userIsLogged) { throw new Exception('User not Logged'); } if ($this->undo) { $new_pwd = $this->old_password; $actual_pwd = $this->password; } else { $new_pwd = CatUtils::generate_password(); $actual_pwd = $this->password; } changePassword($this->res_type, $this->res_id, $actual_pwd, $new_pwd); $this->result['password'] = $new_pwd; $this->result['undo'] = $this->password; }
public function testTagPositionHardNesting_2() { $source_seg = <<<SRC <g id="6"> <g id="7">st</g><g id="8"> <span class="this is in entities">Section</span> of <.++* Tokyo <g id="9"><g id="10">Station</g></g>, Osaka </g></g> SRC; $target_seg = <<<TRG <g id="6"> <g id="7">st</g> <g id="8"> <span class="this is in entities">Section</span> of <.++* Tokyo <g id="9"></g><g id="10"> Station</g>, Osaka </g></g> TRG; $source_seg = CatUtils::view2rawxliff($source_seg); $target_seg = CatUtils::view2rawxliff($target_seg); $check = new QA($source_seg, $target_seg); $check->performConsistencyCheck(); $this->assertTrue($check->thereAreWarnings()); $checkPosition = $check->getTargetTagPositionError(); $checkPositionVals = array_keys($checkPosition); $this->assertCount(1, $checkPosition); $this->assertEquals('</g>', end($checkPosition)); }
public function __construct($result) { $this->responseData = isset($result['responseData']) ? $result['responseData'] : ''; $this->responseDetails = isset($result['responseDetails']) ? $result['responseDetails'] : ''; $this->responseStatus = isset($result['responseStatus']) ? $result['responseStatus'] : ''; if (is_array($result) and !empty($result) and array_key_exists('matches', $result)) { $matches = $result['matches']; if (is_array($matches) and !empty($matches)) { foreach ($matches as $match) { $match['raw_segment'] = $match['segment']; $match['segment'] = CatUtils::rawxliff2view($match['segment']); $match['raw_translation'] = $match['translation']; $match['translation'] = CatUtils::rawxliff2view($match['translation']); $currMatch = new Engines_Results_MyMemory_Matches($match); $this->matches[] = $currMatch; } } } }
/** * When Called it perform the controller action to retrieve/manipulate data * * @return mixed */ function doAction() { $this->parseIDSegment(); $_thereArePossiblePropagations = countThisTranslatedHashInJob($this->id_job, $this->password, $this->id_segment); $thereArePossiblePropagations = intval($_thereArePossiblePropagations['available']); $Translation_mismatches = array(); if ($thereArePossiblePropagations) { $Translation_mismatches = getTranslationsMismatches($this->id_job, $this->password, $this->id_segment); } $result = array('editable' => array(), 'not_editable' => array(), 'prop_available' => $thereArePossiblePropagations); foreach ($Translation_mismatches as $position => $row) { if ($row['editable']) { $result['editable'][] = array('translation' => CatUtils::rawxliff2view($row['translation']), 'TOT' => $row['TOT'], 'involved_id' => explode(",", $row['involved_id'])); } else { $result['not_editable'][] = array('translation' => CatUtils::rawxliff2view($row['translation']), 'TOT' => $row['TOT'], 'involved_id' => explode(",", $row['involved_id'])); } } $this->result['code'] = 1; $this->result['data'] = $result; }
/** * Return to Javascript client the JSON error list in the form: * * <pre> * array( * [total] => 1 * [details] => Array * ( * ['2224860'] => Array * ( * [id_segment] => 2224860 * [warnings] => '[{"outcome":1000,"debug":"Tag mismatch"}]' * ) * ) * [token] => 'token' * ) * </pre> * */ public function doAction() { if (empty($this->__postInput->id)) { $this->__globalWarningsCall(); } else { /** * Update 2015/08/11, roberto@translated.net * getWarning needs the segment status too because of a bug: * sometimes the client calls getWarning and sends an empty trg_content * because the suggestion has not been loaded yet. * This happens only if segment is in status NEW */ if ($this->__postInput->segment_status == 'new' && empty($this->__postInput->trg_content)) { return; } $this->__postInput->src_content = CatUtils::view2rawxliff($this->__postInput->src_content); $this->__postInput->trg_content = CatUtils::view2rawxliff($this->__postInput->trg_content); $this->__segmentWarningsCall(); } }
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 doAction() { if (!empty($this->result['errors'])) { return; } //save the 2 arrays in the DB $translationStruct = TranslationsSplit_SplitStruct::getStruct(); $translationStruct->id_segment = $this->id_segment; $translationStruct->id_job = $this->id_job; list($this->segment, $translationStruct->source_chunk_lengths) = CatUtils::parseSegmentSplit(CatUtils::view2rawxliff($this->segment)); /* Fill the statuses with DEFAULT DRAFT VALUES */ $pieces = count($translationStruct->source_chunk_lengths) > 1 ? count($translationStruct->source_chunk_lengths) - 1 : 1; $translationStruct->target_chunk_lengths = array('len' => array(0), 'statuses' => array_fill(0, $pieces, Constants_TranslationStatus::STATUS_DRAFT)); $translationDao = new TranslationsSplit_SplitDAO(Database::obtain()); $result = $translationDao->update($translationStruct); if ($result instanceof TranslationsSplit_SplitStruct) { //return success $this->result['data'] = 'OK'; } else { Log::doLog("Failed while splitting/merging segment."); Log::doLog($translationStruct); } }
/** * @param $start int * @param $step int * @param $search_in_pname string|null * @param $search_source string|null * @param $search_target string|null * @param $search_status string|null * @param $search_onlycompleted bool * @param $filter_enabled bool * @param $project_id int * * @return array * @throws Exception */ public static function queryProjects($start, $step, $search_in_pname, $search_source, $search_target, $search_status, $search_onlycompleted, $filter_enabled, $project_id) { $data = getProjects($start, $step, $search_in_pname, $search_source, $search_target, $search_status, $search_onlycompleted, $filter_enabled, $project_id); $projects = array(); $projectIDs = array(); $project2info = array(); //get project IDs from projects array foreach ($data as $item) { $projectIDs[] = $item['pid']; } if (empty($projectIDs)) { return array(); } //get job data using job IDs $jobData = getJobsFromProjects($projectIDs, $search_source, $search_target, $search_status, $search_onlycompleted); $lang_handler = Langs_Languages::getInstance(); //Prepare job data $project2jobChunk = array(); foreach ($jobData as $job_array) { $job = array(); /** * Assign job extracted variables */ $job['id'] = $job_array['id']; $job['pid'] = $job_array['id_project']; $job['password'] = $job_array['password']; $job['source'] = $job_array['source']; $job['target'] = $job_array['target']; $job['subject'] = $job_array['subject']; $job['sourceTxt'] = $lang_handler->getLocalizedName($job['source']); $job['targetTxt'] = $lang_handler->getLocalizedName($job['target']); $job['create_date'] = $job_array['create_date']; $job['formatted_create_date'] = self::formatJobDate($job_array['create_date']); $job['job_first_segment'] = $job_array['job_first_segment']; $job['job_last_segment'] = $job_array['job_last_segment']; $job['mt_engine_name'] = $job_array['name']; $job['id_tms'] = $job_array['id_tms']; //generate and set job stats $jobStats = new WordCount_Struct(); $jobStats->setDraftWords($job_array['DRAFT']); $jobStats->setRejectedWords($job_array['REJECT']); $jobStats->setTranslatedWords($job_array['TRANSLATED']); $jobStats->setApprovedWords($job_array['APPROVED']); //These would be redundant in response. Unset them. unset($job_array['DRAFT']); unset($job_array['REJECT']); unset($job_array['TRANSLATED']); unset($job_array['APPROVED']); $job['stats'] = CatUtils::getFastStatsForJob($jobStats); //generate and set job tm_keys $tm_keys_json = $job_array['tm_keys']; $tm_keys_json = TmKeyManagement_TmKeyManagement::getOwnerKeys(array($tm_keys_json)); $tm_keys = array(); foreach ($tm_keys_json as $tm_key_struct) { /** * @var $tm_key_struct TmKeyManagement_TmKeyStruct */ $tm_keys[] = array("key" => $tm_key_struct->key, "r" => $tm_key_struct->r ? 'Lookup' : ' ', "w" => $tm_key_struct->w ? 'Update' : ''); } $job['private_tm_key'] = json_encode($tm_keys); $job['disabled'] = $job_array['status_owner'] == Constants_JobStatus::STATUS_CANCELLED ? "disabled" : ""; $job['status'] = $job_array['status_owner']; //These vars will be used in projects loop for some flag evaluation. $project2info[$job['pid']]['status'][] = $job['status']; $project2info[$job['pid']]['mt_engine_name'] = $job['mt_engine_name']; $project2info[$job['pid']]['id_tms'] = $job['id_tms']; $project2jobChunk[$job['pid']][$job['id']][$job['job_first_segment']] = $job; } //Prepare project data foreach ($data as $item) { $project = array(); $project['id'] = $item['pid']; $project['name'] = $item['name']; $project['jobs'] = array(); $project['no_active_jobs'] = true; $project['has_cancelled'] = 0; $project['has_archived'] = 0; $project['password'] = $item['password']; $project['tm_analysis'] = number_format($item['tm_analysis_wc'], 0, ".", ","); $project['jobs'] = $project2jobChunk[$project['id']]; $project['no_active_jobs'] = $project['no_active_jobs'] ? ' allCancelled' : ''; $project2info[$project['id']]['status'] = array_unique($project2info[$project['id']]['status']); $project['no_active_jobs'] = !in_array(Constants_JobStatus::STATUS_ACTIVE, $project2info[$project['id']]['status']) ? ' allCancelled' : ''; $project['has_cancelled'] = in_array(Constants_JobStatus::STATUS_CANCELLED, $project2info[$project['id']]['status']); $project['has_archived'] = in_array(Constants_JobStatus::STATUS_ARCHIVED, $project2info[$project['id']]['status']); $project['mt_engine_name'] = $project2info[$project['id']]['mt_engine_name']; $project['id_tms'] = $project2info[$project['id']]['id_tms']; $projects[] = $project; } return $projects; }
public function doAction() { if (empty($this->source_lang)) { $this->result['errors'][] = array("code" => -1, "message" => "missing source_lang"); } if (empty($this->target_lang)) { $this->result['errors'][] = array("code" => -2, "message" => "missing target_lang"); } if (empty($this->source)) { $this->result['errors'][] = array("code" => -3, "message" => "missing source"); } if (empty($this->target)) { $this->result['errors'][] = array("code" => -4, "message" => "missing target"); } //get Job Infos $job_data = getJobData((int) $this->id_job, $this->password); $pCheck = new AjaxPasswordCheck(); //check for Password correctness if (empty($job_data) || !$pCheck->grantJobAccessByJobData($job_data, $this->password)) { $this->result['errors'][] = array("code" => -10, "message" => "wrong password"); return; } $this->tm_keys = $job_data['tm_keys']; $this->checkLogin(); $tms = Engine::getInstance($job_data['id_tms']); $config = $tms->getConfigStruct(); // $config = TMS::getConfigStruct(); $config['segment'] = CatUtils::view2rawxliff($this->source); $config['translation'] = CatUtils::view2rawxliff($this->target); $config['source'] = $this->source_lang; $config['target'] = $this->target_lang; $config['email'] = "*****@*****.**"; $config['id_user'] = array(); //get job's TM keys try { $tm_keys = $this->tm_keys; if (self::isRevision()) { $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR; } elseif ($this->userMail == $job_data['owner']) { $tm_keys = TmKeyManagement_TmKeyManagement::getOwnerKeys(array($tm_keys), 'r', 'tm'); $tm_keys = json_encode($tm_keys); } //get TM keys with read grants $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($tm_keys, 'r', 'tm', $this->uid, $this->userRole); if (is_array($tm_keys) && !empty($tm_keys)) { foreach ($tm_keys as $tm_key) { $config['id_user'][] = $tm_key->key; } } } catch (Exception $e) { $this->result['errors'][] = array("code" => -11, "message" => "Cannot retrieve TM keys info."); return; } //prepare the errors report $set_code = array(); /** * @var $tm_key TmKeyManagement_TmKeyStruct */ //if there's no key if (empty($tm_keys)) { //try deleting anyway, it may be a public segment and it may work $TMS_RESULT = $tms->delete($config); $set_code[] = $TMS_RESULT; } else { //loop over the list of keys foreach ($tm_keys as $tm_key) { //issue a separate call for each key $config['id_user'] = $tm_key->key; $TMS_RESULT = $tms->delete($config); $set_code[] = $TMS_RESULT; } } $set_successful = true; if (array_search(false, $set_code, true)) { //There's an errors $set_successful = false; } $this->result['data'] = $set_successful ? "OK" : null; $this->result['code'] = $set_successful; }
public function doAction() { $this->parseIDSegment(); //get Job Infos $job_data = getJobData((int) $this->id_job); $pCheck = new AjaxPasswordCheck(); if (!$pCheck->grantJobAccessByJobData($job_data, $this->password)) { $this->result['errors'][] = array("code" => -10, "message" => "wrong password"); } if (empty($this->id_segment)) { $this->result['errors'][] = array("code" => -1, "message" => "missing segment id"); } if (empty($this->id_job)) { $this->result['errors'][] = array("code" => -2, "message" => "missing Job id"); } if (!empty($this->result['errors'])) { //no action on errors return; } $segmentStruct = TranslationsSplit_SplitStruct::getStruct(); $segmentStruct->id_segment = $this->id_segment; $segmentStruct->id_job = $this->id_job; $translationDao = new TranslationsSplit_SplitDAO(Database::obtain()); $currSegmentInfo = $translationDao->read($segmentStruct); /** * Split check control */ $isASplittedSegment = false; $isLastSegmentChunk = true; if (count($currSegmentInfo) > 0) { $isASplittedSegment = true; $currSegmentInfo = array_shift($currSegmentInfo); //get the chunk number and check whether it is the last one or not $isLastSegmentChunk = $this->split_num == count($currSegmentInfo->source_chunk_lengths) - 1; if (!$isLastSegmentChunk) { $nextSegmentId = $this->id_segment . "-" . ($this->split_num + 1); } } /** * End Split check control */ if (!$isASplittedSegment || $isLastSegmentChunk) { $segmentList = getNextSegment($this->id_segment, $this->id_job, $this->password, !self::isRevision() ? false : true); if (!self::isRevision()) { $nextSegmentId = fetchStatus($this->id_segment, $segmentList); } else { $nextSegmentId = fetchStatus($this->id_segment, $segmentList, Constants_TranslationStatus::STATUS_TRANSLATED); if (!$nextSegmentId) { $nextSegmentId = fetchStatus($this->id_segment, $segmentList, Constants_TranslationStatus::STATUS_APPROVED); } } } $insertRes = setCurrentSegmentInsert($this->id_segment, $this->id_job, $this->password); $this->result['code'] = 1; $this->result['data'] = array(); //get segment revision informations $reviseDao = new Revise_ReviseDAO(Database::obtain()); $searchReviseStruct = Revise_ReviseStruct::getStruct(); $searchReviseStruct->id_job = $this->id_job; $searchReviseStruct->id_segment = $this->id_segment; $_dbReviseStruct = $reviseDao->read($searchReviseStruct); if (count($_dbReviseStruct) > 0) { $_dbReviseStruct = $_dbReviseStruct[0]; } else { $_dbReviseStruct = Revise_ReviseStruct::getStruct(); } $_dbReviseStruct = Revise_ReviseStruct::setDefaultValues($_dbReviseStruct); $dbReviseStruct = self::prepareReviseStructReturnValues($_dbReviseStruct); $this->result['nextSegmentId'] = $nextSegmentId; $this->result['error_data'] = $dbReviseStruct; $this->result['original'] = CatUtils::rawxliff2view($_dbReviseStruct->original_translation); }
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; }
public function doAction() { //get Job Infos $job_data = getJobData($this->jid); $pCheck = new AjaxPasswordCheck(); //check for Password correctness if (!$pCheck->grantJobAccessByJobData($job_data, $this->password)) { $this->result['errors'][] = array("code" => -10, "message" => "wrong password"); return; } $lang_handler = Langs_Languages::getInstance(); if ($this->ref_segment == '') { $this->ref_segment = 0; } $data = getMoreSegments($this->jid, $this->password, $this->step, $this->ref_segment, $this->where); $this->prepareNotes($data); foreach ($data as $i => $seg) { if ($this->where == 'before') { if ((double) $seg['sid'] >= (double) $this->ref_segment) { break; } } if (empty($this->pname)) { $this->pname = $seg['pname']; } if (empty($this->last_opened_segment)) { $this->last_opened_segment = $seg['last_opened_segment']; } if (empty($this->cid)) { $this->cid = $seg['cid']; } if (empty($this->pid)) { $this->pid = $seg['pid']; } if (empty($this->tid)) { $this->tid = $seg['tid']; } if (empty($this->create_date)) { $this->create_date = $seg['create_date']; } if (empty($this->source_code)) { $this->source_code = $seg['source']; } if (empty($this->target_code)) { $this->target_code = $seg['target']; } if (empty($this->source)) { $s = explode("-", $seg['source']); $source = strtoupper($s[0]); $this->source = $source; } if (empty($this->target)) { $t = explode("-", $seg['target']); $target = strtoupper($t[0]); $this->target = $target; } if (empty($this->err)) { $this->err = $seg['serialized_errors_list']; } $id_file = $seg['id_file']; if (!isset($this->data["{$id_file}"])) { $this->data["{$id_file}"]['jid'] = $seg['jid']; $this->data["{$id_file}"]["filename"] = ZipArchiveExtended::getFileName($seg['filename']); $this->data["{$id_file}"]["mime_type"] = $seg['mime_type']; $this->data["{$id_file}"]['source'] = $lang_handler->getLocalizedName($seg['source']); $this->data["{$id_file}"]['target'] = $lang_handler->getLocalizedName($seg['target']); $this->data["{$id_file}"]['source_code'] = $seg['source']; $this->data["{$id_file}"]['target_code'] = $seg['target']; $this->data["{$id_file}"]['segments'] = array(); } unset($seg['id_file']); unset($seg['source']); unset($seg['target']); unset($seg['source_code']); unset($seg['target_code']); unset($seg['mime_type']); unset($seg['filename']); unset($seg['jid']); unset($seg['pid']); unset($seg['cid']); unset($seg['tid']); unset($seg['pname']); unset($seg['create_date']); unset($seg['id_segment_end']); unset($seg['id_segment_start']); unset($seg['serialized_errors_list']); $seg['parsed_time_to_edit'] = CatUtils::parse_time_to_edit($seg['time_to_edit']); $seg['source_chunk_lengths'] === null ? $seg['source_chunk_lengths'] = '[]' : null; $seg['target_chunk_lengths'] === null ? $seg['target_chunk_lengths'] = '{"len":[0],"statuses":["DRAFT"]}' : null; $seg['source_chunk_lengths'] = json_decode($seg['source_chunk_lengths'], true); $seg['target_chunk_lengths'] = json_decode($seg['target_chunk_lengths'], true); $seg['segment'] = CatUtils::rawxliff2view(CatUtils::reApplySegmentSplit($seg['segment'], $seg['source_chunk_lengths'])); $seg['translation'] = CatUtils::rawxliff2view(CatUtils::reApplySegmentSplit($seg['translation'], $seg['target_chunk_lengths']['len'])); $this->attachNotes($seg); $this->data["{$id_file}"]['segments'][] = $seg; } $this->result['data']['files'] = $this->data; $this->result['data']['where'] = $this->where; }
private function getEditLogData($use_ter_diff = false) { $editLogDao = new EditLog_EditLogDao(Database::obtain()); $data = $editLogDao->getSegments($this->getJid(), $this->getPassword(), self::$start_id); //get translation mismatches and convert the array in a hashmap $translationMismatchList = $editLogDao->getTranslationMismatches($this->getJid()); foreach ($translationMismatchList as $idx => $translMismRow) { $translMismRow[$translMismRow['segment_hash']] = (bool) $translMismRow['translation_mismatch']; } $__pagination_prev = PHP_INT_MAX; $__pagination_next = -2147483648; //PHP_INT_MIN $stat_too_slow = array(); $stat_too_fast = array(); if (!$data) { throw new Exception('There are no changes in this job', -1); } $stats['total-word-count'] = 0; $stat_mt = array(); $stat_valid_rwc = array(); $stat_rwc = array(); $stat_valid_tte = array(); $stat_pee = array(); $stat_ter = array(); $output_data = array(); foreach ($data as $seg) { //if the segment is before the current one if ($seg->id < self::$start_id) { if ($seg->id <= $__pagination_prev) { $__pagination_prev = $seg->id; } continue; } if ($seg->id > $__pagination_next) { $__pagination_next = $seg->id; } $displaySeg = new EditLog_EditLogSegmentClientStruct($seg->toArray()); $displaySeg->suggestion_match .= "%"; $displaySeg->job_id = $this->jid; $tte = CatUtils::parse_time_to_edit($displaySeg->time_to_edit); $displaySeg->display_time_to_edit = "{$tte['1']}m:{$tte['2']}s"; $stat_rwc[] = $seg->raw_word_count; // by definition we cannot have a 0 word sentence. It is probably a - or a tag, so we want to consider at least a word. if ($seg->raw_word_count < 1) { $displaySeg->raw_word_count = 1; } //todo: remove this $displaySeg->secs_per_word = $seg->getSecsPerWord(); if ($displaySeg->secs_per_word < self::EDIT_TIME_SLOW_CUT && $displaySeg->secs_per_word > self::EDIT_TIME_FAST_CUT) { $displaySeg->stats_valid = true; $stat_valid_rwc[] = $seg->raw_word_count; $stat_spw[] = $displaySeg->secs_per_word; } else { $displaySeg->stats_valid = false; } // Stats if ($displaySeg->secs_per_word >= self::EDIT_TIME_SLOW_CUT) { $stat_too_slow[] = $seg->raw_word_count; } if ($displaySeg->secs_per_word <= self::EDIT_TIME_FAST_CUT) { $stat_too_fast[] = $seg->raw_word_count; } $displaySeg->secs_per_word .= "s"; $displaySeg->pe_effort_perc = $displaySeg->getPeePerc(); if ($displaySeg->pe_effort_perc < 0) { $displaySeg->pe_effort_perc = 0; } if ($displaySeg->pe_effort_perc > 100) { $displaySeg->pe_effort_perc = 100; } $stat_pee[] = $displaySeg->pe_effort_perc * $seg->raw_word_count; $displaySeg->pe_effort_perc .= "%"; $lh = Langs_Languages::getInstance(); $lang = $lh->getIsoCode($lh->getLocalizedName($seg->job_target)); $sug_for_diff = CatUtils::placehold_xliff_tags($seg->suggestion); $tra_for_diff = CatUtils::placehold_xliff_tags($seg->translation); //with this patch we have warnings when accessing indexes if ($use_ter_diff) { $ter = MyMemory::diff_tercpp($sug_for_diff, $tra_for_diff, $lang); } else { $ter = array(); } $displaySeg->ter = @$ter[1] * 100; $stat_ter[] = $displaySeg->ter * $seg->raw_word_count; $displaySeg->ter = round(@$ter[1] * 100) . "%"; $diff_ter = @$ter[0]; if ($seg->suggestion != $seg->translation) { //force use of third party ter diff if ($use_ter_diff) { $displaySeg->diff = $diff_ter; } else { $diff_PE = MyMemory::diff_html($sug_for_diff, $tra_for_diff); // we will use diff_PE until ter_diff will not work properly $displaySeg->diff = $diff_PE; } //$seg[ 'diff_ter' ] = $diff_ter; } else { $displaySeg->diff = ''; } $displaySeg->diff = CatUtils::restore_xliff_tags_for_view($displaySeg->diff); // BUG: While suggestions source is not correctly set if ($displaySeg->suggestion_match == "85%" || $displaySeg->suggestion_match == "86%") { $displaySeg->suggestion_source = 'Machine Translation'; $stat_mt[] = $seg->raw_word_count; } else { $displaySeg->suggestion_source = 'TM'; } $array_patterns = array(rtrim(CatUtils::lfPlaceholderRegex, 'g'), rtrim(CatUtils::crPlaceholderRegex, 'g'), rtrim(CatUtils::crlfPlaceholderRegex, 'g'), rtrim(CatUtils::tabPlaceholderRegex, 'g'), rtrim(CatUtils::nbspPlaceholderRegex, 'g')); $array_replacements_csv = array('\\n', '\\r', '\\r\\n', '\\t', Utils::unicode2chr(0xa0)); $displaySeg->source_csv = preg_replace($array_patterns, $array_replacements_csv, $seg->source); $displaySeg->translation_csv = preg_replace($array_patterns, $array_replacements_csv, $seg->translation); $displaySeg->sug_csv = preg_replace($array_patterns, $array_replacements_csv, $displaySeg->suggestion_view); $displaySeg->diff_csv = preg_replace($array_patterns, $array_replacements_csv, $displaySeg->diff); $array_replacements = array('<span class="_0A"></span><br />', '<span class="_0D"></span><br />', '<span class="_0D0A"></span><br />', '<span class="_tab">	</span>', '<span class="_nbsp"> </span>'); $displaySeg->source = preg_replace($array_patterns, $array_replacements, $seg->source); $displaySeg->translation = preg_replace($array_patterns, $array_replacements, $seg->translation); $displaySeg->suggestion_view = preg_replace($array_patterns, $array_replacements, $displaySeg->suggestion_view); $displaySeg->diff = preg_replace($array_patterns, $array_replacements, $displaySeg->diff); $displaySeg->source = trim(CatUtils::rawxliff2view($seg->source)); $displaySeg->suggestion_view = trim(CatUtils::rawxliff2view($seg->suggestion)); $displaySeg->translation = trim(CatUtils::rawxliff2view($seg->translation)); if ($seg->mt_qe == 0) { $displaySeg->mt_qe = 'N/A'; } $displaySeg->num_translation_mismatch = @(int) $translationMismatchList[$displaySeg->segment_hash]; $displaySeg->evaluateWarningString(); $output_data[] = $displaySeg; } $pagination = $this->evaluatePagination($__pagination_prev, $__pagination_next + 1); $globalStats = $this->evaluateGlobalStats(); $stats['valid-word-count'] = $globalStats['raw_words']; //TODO: this will not work anymore $stats['edited-word-count'] = array_sum($stat_rwc); if ($stats['edited-word-count'] > 0) { $stats['too-slow-words'] = round(array_sum($stat_too_slow) / $stats['edited-word-count'], 2) * 100; $stats['too-fast-words'] = round(array_sum($stat_too_fast) / $stats['edited-word-count'], 2) * 100; $stats['avg-pee'] = round(array_sum($stat_pee) / array_sum($stat_rwc)) . "%"; $stats['avg-ter'] = round(array_sum($stat_ter) / array_sum($stat_rwc)) . "%"; } $stats['mt-words'] = round(array_sum($stat_mt) / $stats['edited-word-count'], 2) * 100; $stats['tm-words'] = 100 - $stats['mt-words']; $stats['total-valid-tte'] = round($globalStats['tot_tte']); // Non weighted... // $stats['avg-secs-per-word'] = round(array_sum($stat_spw)/count($stat_spw),1); // Weighted $stats['avg-secs-per-word'] = round($globalStats['secs_per_word'] / 1000, 1); $stats['est-words-per-day'] = number_format(round(3600 * 8 / $stats['avg-secs-per-word']), 0, '.', ','); // Last minute formatting (after calculations) $temp = CatUtils::parse_time_to_edit(round($stats['total-valid-tte'])); $stats['total-valid-tte'] = "{$temp['0']}h:{$temp['1']}m:{$temp['2']}s"; $stats['total-tte-seconds'] = $temp[0] * 3600 + $temp[1] * 60 + $temp[2]; $stats['avg-pee'] = round($globalStats['avg_pee'], 2); $stats['avg-pee'] .= "%"; return array($output_data, $stats, $pagination); }
$suggestion_match = $matches[0]['match']; $suggestion_json = json_encode($matches); $suggestion_source = $matches[0]['created_by']; $equivalentWordMapping = json_decode($payable_rates, true); $new_match_type = getNewMatchType($tm_match_type, $fast_match_type, $equivalentWordMapping, empty($matches[0]['memory_key'])); $eq_words = $equivalentWordMapping[$new_match_type] * $raw_wc / 100; $standard_words = $eq_words; //if the first match is MT perform QA realignment if ($new_match_type == 'MT') { $standard_words = $equivalentWordMapping["NO_MATCH"] * $raw_wc / 100; $check = new PostProcess($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($text, $suggestion); $check->performTagCheckOnly(); //_TimeStampMsg( $check->getErrors() ); if ($check->thereAreErrors()) { $err_json = $check->getErrorsJSON(); } else { $err_json = ''; } }
private function setSuggestionReport($matches) { if (count($matches) > 0) { $suggestions_json_array = json_encode($matches); $match = $matches[0]; $suggestion = $match['translation']; $suggestion_match = $match['match']; $suggestion_source = $match['created_by']; $ret = CatUtils::addTranslationSuggestion($this->id_segment, $this->id_job, $suggestions_json_array, $suggestion, $suggestion_match, $suggestion_source); return $ret; } return 0; }
public function convertToSdlxliff($file_path, $source_lang, $target_lang, $chosen_by_user_machine = false, $segm_rule = null) { if (!file_exists($file_path)) { throw new Exception("Conversion Error : the file <{$file_path}> not exists"); } $fileContent = file_get_contents($file_path); $extension = pathinfo($file_path, PATHINFO_EXTENSION); $filename = pathinfo($file_path, PATHINFO_FILENAME); if (strtoupper($extension) == 'TXT' or strtoupper($extension) == 'STRINGS') { $encoding = mb_detect_encoding($fileContent); //in case of .strings, they may be in UTF-16 if (strtoupper($extension) == 'STRINGS') { //use this function to convert stuff $convertedFile = CatUtils::convertEncoding('UTF-8', $fileContent); //retrieve new content $fileContent = $convertedFile[1]; } else { if ($encoding != 'UTF-8') { $fileContent = iconv($encoding, "UTF-8//IGNORE", $fileContent); } } if (!$this->hasBOM($fileContent)) { $fileContent = $this->addBOM($fileContent); } } //get random name for temporary location $tmp_name = tempnam("/tmp", "MAT_FW"); //write encoded file to temporary location $fileSize = file_put_contents($tmp_name, $fileContent); //assign file pointer for POST $data['documentContent'] = "@{$tmp_name}"; //flush memory unset($fileContent); //assign converter if (!$chosen_by_user_machine) { $this->ip = $this->pickRandConverter($segm_rule); } else { $this->ip = $chosen_by_user_machine; } $url = "{$this->ip}:{$this->port}/{$this->toXliffFunction}"; $data['fileExtension'] = $extension; $data['fileName'] = "{$filename}.{$extension}"; $data['sourceLocale'] = $this->lang_handler->getLangRegionCode($source_lang); $data['targetLocale'] = $this->lang_handler->getLangRegionCode($target_lang); log::doLog($this->ip . " start conversion to xliff of {$file_path}"); $start_time = microtime(true); $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 for {$file_path}"); $this->conversionObject->ip_machine = $this->ip; $this->conversionObject->ip_client = Utils::getRealIpAddr(); $this->conversionObject->path_name = $file_path; $this->conversionObject->file_name = $data['fileName']; $this->conversionObject->direction = 'fw'; $this->conversionObject->src_lang = $data['sourceLocale']; $this->conversionObject->trg_lang = $data['targetLocale']; $this->conversionObject->file_size = $fileSize; $this->conversionObject->conversion_time = $time_diff; $decode = json_decode($curl_result, true); $curl_result = null; $res = $this->__parseOutput($decode); //remove temporary file unlink($tmp_name); return $res; }
public static function getEditingLogData($jid, $password, $use_ter_diff = false) { $data = getEditLog($jid, $password); $slow_cut = 30; $fast_cut = 0.25; $stat_too_slow = array(); $stat_too_fast = array(); if (!$data) { return false; } $stats['total-word-count'] = 0; $stat_mt = array(); foreach ($data as &$seg) { $seg['sm'] .= "%"; $seg['jid'] = $jid; $tte = self::parse_time_to_edit($seg['tte']); $seg['time_to_edit'] = "{$tte['1']}m:{$tte['2']}s"; $stat_rwc[] = $seg['rwc']; // by definition we cannot have a 0 word sentence. It is probably a - or a tag, so we want to consider at least a word. if ($seg['rwc'] < 1) { $seg['rwc'] = 1; } $seg['secs-per-word'] = round($seg['tte'] / 1000 / $seg['rwc'], 1); if ($seg['secs-per-word'] < $slow_cut and $seg['secs-per-word'] > $fast_cut) { $seg['stats-valid'] = 'Yes'; $seg['stats-valid-color'] = ''; $seg['stats-valid-style'] = ''; $stat_valid_rwc[] = $seg['rwc']; $stat_valid_tte[] = $seg['tte']; $stat_spw[] = $seg['secs-per-word']; } else { $seg['stats-valid'] = 'No'; $seg['stats-valid-color'] = '#ee6633'; $seg['stats-valid-style'] = 'border:2px solid #EE6633'; } // Stats if ($seg['secs-per-word'] >= $slow_cut) { $stat_too_slow[] = $seg['rwc']; } if ($seg['secs-per-word'] <= $fast_cut) { $stat_too_fast[] = $seg['rwc']; } $seg['pe_effort_perc'] = round((1 - MyMemory::TMS_MATCH($seg['sug'], $seg['translation'])) * 100); if ($seg['pe_effort_perc'] < 0) { $seg['pe_effort_perc'] = 0; } if ($seg['pe_effort_perc'] > 100) { $seg['pe_effort_perc'] = 100; } $stat_pee[] = $seg['pe_effort_perc'] * $seg['rwc']; $seg['pe_effort_perc'] .= "%"; $lh = Langs_Languages::getInstance(); $lang = $lh->getIsoCode($lh->getLocalizedName($seg['target_lang'])); $sug_for_diff = self::placehold_xliff_tags($seg['sug']); $tra_for_diff = self::placehold_xliff_tags($seg['translation']); // possible patch // $sug_for_diff = html_entity_decode($sug_for_diff, ENT_NOQUOTES, 'UTF-8'); // $tra_for_diff = html_entity_decode($tra_for_diff, ENT_NOQUOTES, 'UTF-8'); //with this patch we have warnings when accessing indexes if ($use_ter_diff) { $ter = MyMemory::diff_tercpp($sug_for_diff, $tra_for_diff, $lang); } else { $ter = array(); } // Log::doLog( $sug_for_diff ); // Log::doLog( $tra_for_diff ); // Log::doLog( $ter ); $seg['ter'] = @$ter[1] * 100; $stat_ter[] = $seg['ter'] * $seg['rwc']; $seg['ter'] = round(@$ter[1] * 100) . "%"; $diff_ter = @$ter[0]; if ($seg['sug'] != $seg['translation']) { //force use of third party ter diff if ($use_ter_diff) { $seg['diff'] = $diff_ter; } else { $diff_PE = MyMemory::diff_html($sug_for_diff, $tra_for_diff); // we will use diff_PE until ter_diff will not work properly $seg['diff'] = $diff_PE; } //$seg[ 'diff_ter' ] = $diff_ter; } else { $seg['diff'] = ''; //$seg[ 'diff_ter' ] = ''; } $seg['diff'] = self::restore_xliff_tags_for_view($seg['diff']); //$seg['diff_ter'] = self::restore_xliff_tags_for_view($seg['diff_ter']); // BUG: While suggestions source is not correctly set if ($seg['sm'] == "85%" or $seg['sm'] == "86%") { $seg['ss'] = 'Machine Translation'; $stat_mt[] = $seg['rwc']; } else { $seg['ss'] = 'Translation Memory'; } $seg['sug_view'] = trim(CatUtils::rawxliff2view($seg['sug'])); $seg['source'] = trim(CatUtils::rawxliff2view($seg['source'])); $seg['translation'] = trim(CatUtils::rawxliff2view($seg['translation'])); $array_patterns = array(rtrim(self::lfPlaceholderRegex, 'g'), rtrim(self::crPlaceholderRegex, 'g'), rtrim(self::crlfPlaceholderRegex, 'g'), rtrim(self::tabPlaceholderRegex, 'g'), rtrim(self::nbspPlaceholderRegex, 'g')); $array_replacements_csv = array('\\n', '\\r', '\\r\\n', '\\t', Utils::unicode2chr(0xa0)); $seg['source_csv'] = preg_replace($array_patterns, $array_replacements_csv, $seg['source']); $seg['translation_csv'] = preg_replace($array_patterns, $array_replacements_csv, $seg['translation']); $seg['sug_csv'] = preg_replace($array_patterns, $array_replacements_csv, $seg['sug_view']); $seg['diff_csv'] = preg_replace($array_patterns, $array_replacements_csv, $seg['diff']); $array_replacements = array('<span class="_0A"></span><br />', '<span class="_0D"></span><br />', '<span class="_0D0A"></span><br />', '<span class="_tab">	</span>', '<span class="_nbsp"> </span>'); $seg['source'] = preg_replace($array_patterns, $array_replacements, $seg['source']); $seg['translation'] = preg_replace($array_patterns, $array_replacements, $seg['translation']); $seg['sug_view'] = preg_replace($array_patterns, $array_replacements, $seg['sug_view']); $seg['diff'] = preg_replace($array_patterns, $array_replacements, $seg['diff']); if ($seg['mt_qe'] == 0) { $seg['mt_qe'] = 'N/A'; } } $stats['edited-word-count'] = array_sum($stat_rwc); $stats['valid-word-count'] = array_sum($stat_valid_rwc); if ($stats['edited-word-count'] > 0) { $stats['too-slow-words'] = round(array_sum($stat_too_slow) / $stats['edited-word-count'], 2) * 100; $stats['too-fast-words'] = round(array_sum($stat_too_fast) / $stats['edited-word-count'], 2) * 100; $stats['avg-pee'] = round(array_sum($stat_pee) / array_sum($stat_rwc)) . "%"; $stats['avg-ter'] = round(array_sum($stat_ter) / array_sum($stat_rwc)) . "%"; } // echo array_sum($stat_ter); // echo "@@@"; // echo array_sum($stat_rwc); // exit; $stats['mt-words'] = round(array_sum($stat_mt) / $stats['edited-word-count'], 2) * 100; $stats['tm-words'] = 100 - $stats['mt-words']; $stats['total-valid-tte'] = round(array_sum($stat_valid_tte) / 1000); // Non weighted... // $stats['avg-secs-per-word'] = round(array_sum($stat_spw)/count($stat_spw),1); // Weighted $stats['avg-secs-per-word'] = round($stats['total-valid-tte'] / $stats['valid-word-count'], 1); $stats['est-words-per-day'] = number_format(round(3600 * 8 / $stats['avg-secs-per-word']), 0, '.', ','); // Last minute formatting (after calculations) $temp = self::parse_time_to_edit(round(array_sum($stat_valid_tte))); $stats['total-valid-tte'] = "{$temp['0']}h:{$temp['1']}m:{$temp['2']}s"; $stats['total-tte-seconds'] = $temp[0] * 3600 + $temp[1] * 60 + $temp[2]; return array($data, $stats); }
public function doAction() { $files_found = array(); $lang_handler = Langs_Languages::getInstance(); $data = getSegmentsInfo($this->jid, $this->password); if (empty($data) or $data < 0) { $this->job_not_found = true; //stop execution return; } //retrieve job owner. It will be useful also if the job is archived or cancelled $this->job_owner = $data[0]['job_owner'] != "" ? $data[0]['job_owner'] : "*****@*****.**"; if ($data[0]['status'] == Constants_JobStatus::STATUS_CANCELLED) { $this->job_cancelled = true; //stop execution return; } if ($data[0]['status'] == Constants_JobStatus::STATUS_ARCHIVED) { $this->job_archived = true; //stop execution return; } /* * I prefer to use a programmatic approach to the check for the archive date instead of a pure query * because the query to check "Utils::getArchivableJobs($this->jid)" should be * executed every time a job is loaded ( F5 or CTRL+R on browser ) and it cost some milliseconds ( ~0.1s ) * and it is little heavy for the database. * We use the data we already have from last query and perform * the check on the last translation only if the job is older than 30 days * */ $lastUpdate = new DateTime($data[0]['last_update']); $oneMonthAgo = new DateTime(); $oneMonthAgo->modify('-' . INIT::JOB_ARCHIVABILITY_THRESHOLD . ' days'); if ($lastUpdate < $oneMonthAgo && !$this->job_cancelled) { $lastTranslationInJob = new Datetime(getLastTranslationDate($this->jid)); if ($lastTranslationInJob < $oneMonthAgo) { $res = "job"; $new_status = Constants_JobStatus::STATUS_ARCHIVED; updateJobsStatus($res, $this->jid, $new_status, null, null, $this->password); $this->job_archived = true; } } foreach ($data as $i => $job) { $this->project_status = $job; // get one row values for the project are the same for every row if (empty($this->pname)) { $this->pname = $job['pname']; $this->downloadFileName = $job['pname'] . ".zip"; // will be overwritten below in case of one file job } if (empty($this->last_opened_segment)) { $this->last_opened_segment = $job['last_opened_segment']; } if (empty($this->cid)) { $this->cid = $job['cid']; } if (empty($this->pid)) { $this->pid = $job['pid']; } if (empty($this->create_date)) { $this->create_date = $job['create_date']; } if (empty($this->source_code)) { $this->source_code = $job['source']; } if (empty($this->target_code)) { $this->target_code = $job['target']; } if (empty($this->source)) { $s = explode("-", $job['source']); $source = strtoupper($s[0]); $this->source = $source; $this->source_rtl = $lang_handler->isRTL(strtolower($this->source)) ? ' rtl-source' : ''; } if (empty($this->target)) { $t = explode("-", $job['target']); $target = strtoupper($t[0]); $this->target = $target; $this->target_rtl = $lang_handler->isRTL(strtolower($this->target)) ? ' rtl-target' : ''; } //check if language belongs to supported right-to-left languages if ($job['status'] == Constants_JobStatus::STATUS_ARCHIVED) { $this->job_archived = true; $this->job_owner = $data[0]['job_owner']; } $id_file = $job['id_file']; if (!isset($this->data["{$id_file}"])) { $files_found[] = $job['filename']; } $wStruct = new WordCount_Struct(); $wStruct->setIdJob($this->jid); $wStruct->setJobPassword($this->password); $wStruct->setNewWords($job['new_words']); $wStruct->setDraftWords($job['draft_words']); $wStruct->setTranslatedWords($job['translated_words']); $wStruct->setApprovedWords($job['approved_words']); $wStruct->setRejectedWords($job['rejected_words']); unset($job['id_file']); unset($job['source']); unset($job['target']); unset($job['source_code']); unset($job['target_code']); unset($job['mime_type']); unset($job['filename']); unset($job['jid']); unset($job['pid']); unset($job['cid']); unset($job['tid']); unset($job['pname']); unset($job['create_date']); unset($job['owner']); unset($job['last_opened_segment']); unset($job['new_words']); unset($job['draft_words']); unset($job['translated_words']); unset($job['approved_words']); unset($job['rejected_words']); //For projects created with No tm analysis enabled if ($wStruct->getTotal() == 0 && ($job['status_analysis'] == Constants_ProjectStatus::STATUS_DONE || $job['status_analysis'] == Constants_ProjectStatus::STATUS_NOT_TO_ANALYZE)) { $wCounter = new WordCount_Counter(); $wStruct = $wCounter->initializeJobWordCount($this->jid, $this->password); Log::doLog("BackWard compatibility set Counter."); } $this->job_stats = CatUtils::getFastStatsForJob($wStruct); } //Needed because a just created job has last_opened segment NULL if (empty($this->last_opened_segment)) { $this->last_opened_segment = getFirstSegmentId($this->jid, $this->password); } $this->first_job_segment = $this->project_status['job_first_segment']; $this->last_job_segment = $this->project_status['job_last_segment']; if (count($files_found) == 1) { $this->downloadFileName = $files_found[0]; } /** * get first segment of every file */ $fileInfo = getFirstSegmentOfFilesInJob($this->jid); $TotalPayable = array(); foreach ($fileInfo as &$file) { $file['file_name'] = ZipArchiveExtended::getFileName($file['file_name']); $TotalPayable[$file['id_file']]['TOTAL_FORMATTED'] = $file['TOTAL_FORMATTED']; } $this->firstSegmentOfFiles = json_encode($fileInfo); $this->fileCounter = json_encode($TotalPayable); list($uid, $user_email) = $this->getLoginUserParams(); if (self::isRevision()) { $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR; } elseif ($user_email == $data[0]['job_owner']) { $this->userRole = TmKeyManagement_Filter::OWNER; } else { $this->userRole = TmKeyManagement_Filter::ROLE_TRANSLATOR; } /* * Take the keys of the user */ try { $_keyList = new TmKeyManagement_MemoryKeyDao(Database::obtain()); $dh = new TmKeyManagement_MemoryKeyStruct(array('uid' => $uid)); $keyList = $_keyList->read($dh); } catch (Exception $e) { $keyList = array(); Log::doLog($e->getMessage()); } $reverse_lookup_user_personal_keys = array('pos' => array(), 'elements' => array()); /** * Set these keys as editable for the client * * @var $keyList TmKeyManagement_MemoryKeyStruct[] */ foreach ($keyList as $_j => $key) { /** * @var $_client_tm_key TmKeyManagement_TmKeyStruct */ //create a reverse lookup $reverse_lookup_user_personal_keys['pos'][$_j] = $key->tm_key->key; $reverse_lookup_user_personal_keys['elements'][$_j] = $key; $this->_keyList['totals'][$_j] = new TmKeyManagement_ClientTmKeyStruct($key->tm_key); } /* * Now take the JOB keys */ $job_keyList = json_decode($data[0]['tm_keys'], true); $this->tid = count($job_keyList) > 0; /** * Start this N^2 cycle from keys of the job, * these should be statistically lesser than the keys of the user * * @var $keyList array */ foreach ($job_keyList as $jobKey) { $jobKey = new TmKeyManagement_ClientTmKeyStruct($jobKey); if ($this->isLoggedIn() && count($reverse_lookup_user_personal_keys['pos'])) { /* * If user has some personal keys, check for the job keys if they are present, and obfuscate * when they are not */ $_index_position = array_search($jobKey->key, $reverse_lookup_user_personal_keys['pos']); if ($_index_position !== false) { //i found a key in the job that is present in my database //i'm owner?? and the key is an owner type key? if (!$jobKey->owner && $this->userRole != TmKeyManagement_Filter::OWNER) { $jobKey->r = $jobKey->{TmKeyManagement_Filter::$GRANTS_MAP[$this->userRole]['r']}; $jobKey->w = $jobKey->{TmKeyManagement_Filter::$GRANTS_MAP[$this->userRole]['w']}; $jobKey = $jobKey->hideKey($uid); } else { if ($jobKey->owner && $this->userRole != TmKeyManagement_Filter::OWNER) { // I'm not the job owner, but i know the key because it is in my keyring // so, i can upload and download TMX, but i don't want it to be removed from job // in tm.html relaxed the control to "key.edit" to enable buttons // $jobKey = $jobKey->hideKey( $uid ); // enable editing } else { if ($jobKey->owner && $this->userRole == TmKeyManagement_Filter::OWNER) { //do Nothing } } } unset($this->_keyList['totals'][$_index_position]); } else { /* * This is not a key of that user, set right and obfuscate */ $jobKey->r = true; $jobKey->w = true; $jobKey = $jobKey->hideKey(-1); } $this->_keyList['job_keys'][] = $jobKey; } else { /* * This user is anonymous or it has no keys in its keyring, obfuscate all */ $jobKey->r = true; $jobKey->w = true; $this->_keyList['job_keys'][] = $jobKey->hideKey(-1); } } //clean unordered keys $this->_keyList['totals'] = array_values($this->_keyList['totals']); /** * Retrieve information about job errors * ( Note: these information are fed by the revision process ) * @see setRevisionController */ $jobQA = new Revise_JobQA($this->jid, $this->password, $wStruct->getTotal()); $jobQA->retrieveJobErrorTotals(); $jobVote = $jobQA->evalJobVote(); $this->qa_data = json_encode($jobQA->getQaData()); $this->qa_overall = $jobVote['minText']; $engine = new EnginesModel_EngineDAO(Database::obtain()); //this gets all engines of the user if ($this->isLoggedIn()) { $engineQuery = new EnginesModel_EngineStruct(); $engineQuery->type = 'MT'; $engineQuery->uid = $uid; $engineQuery->active = 1; $mt_engines = $engine->read($engineQuery); } else { $mt_engines = array(); } // this gets MyMemory $engineQuery = new EnginesModel_EngineStruct(); $engineQuery->type = 'TM'; $engineQuery->active = 1; $tms_engine = $engine->setCacheTTL(3600 * 24 * 30)->read($engineQuery); //this gets MT engine active for the job $engineQuery = new EnginesModel_EngineStruct(); $engineQuery->id = $this->project_status['id_mt_engine']; $engineQuery->active = 1; $active_mt_engine = $engine->setCacheTTL(60 * 10)->read($engineQuery); /* * array_unique cast EnginesModel_EngineStruct to string * * EnginesModel_EngineStruct implements __toString method * */ $this->translation_engines = array_unique(array_merge($active_mt_engine, $tms_engine, $mt_engines)); }
* MyMemory disabled and MT Disabled Too * So don't perform TMS Analysis */ $perform_Tms_Analysis = false; $status = Constants_ProjectStatus::STATUS_DONE; _TimeStampMsg('Perform Analysis ' . var_export($perform_Tms_Analysis, true)); } elseif ($num_segments == 0) { //there is no analysis on that file, it is ALL Pre-Translated _TimeStampMsg('There is no analysis on that file, it is ALL Pre-Translated'); $status = Constants_ProjectStatus::STATUS_DONE; } //compose a lookup array $segment_hashes = array(); foreach ($segments as $pos => $segment) { $segment_hashes[$segment['id']] = array($segment['segment_hash'], $segment['segment'], $segment['raw_word_count'], $segment['source'], $segment['target'], $segment['payable_rates']); $segments[$pos]['segment'] = CatUtils::clean_raw_string4fast_word_count($segment['segment'], $segments[0]['source']); //unset because we don't want to pass these keys to Fast Analysis unset($segments[$pos]['id']); unset($segments[$pos]['segment_hash']); unset($segment['segment']); unset($segment['raw_word_count']); unset($segment['target']); unset($segment['payable_rates']); } _TimeStampMsg("done"); _TimeStampMsg("pid {$pid}: {$num_segments} segments"); _TimeStampMsg("sending query to MyMemory analysis..."); $ws->doLog = false; //tell to the engine to not log the output $fastReport = $ws->fastAnalysis($segments); _TimeStampMsg("Memory: " . memory_get_usage(true) / (1024 * 1024) . "MB");
protected function _generatePassword($length = 12) { return CatUtils::generate_password($length); }
/** * Remove the tag mrk if the file is an xlif and if the file is a globalsight file * * Also, check for encoding and transform utf16 to utf8 and back * * @param $documentContent * @param $path * * @return string */ public function ifGlobalSightXliffRemoveTargetMarks($documentContent, $path) { $extension = FilesStorage::pathinfo_fix($path); if (!DetectProprietaryXliff::isXliffExtension($extension)) { return $documentContent; } $is_utf8 = true; $original_charset = 'utf-8'; //not used, useful only to avoid IDE warning for not used variable //The file is UTF-16 Encoded if (stripos(substr($documentContent, 0, 100), "<?xml ") === false) { $is_utf8 = false; list($original_charset, $documentContent) = CatUtils::convertEncoding('UTF-8', $documentContent); } //avoid in memory copy of very large files if possible $detect_result = DetectProprietaryXliff::getInfoByStringData(substr($documentContent, 0, 1024)); //clean mrk tags for GlobalSight application compatibility //this should be a sax parser instead of in memory copy for every trans-unit if ($detect_result['proprietary_short_name'] == 'globalsight') { // Getting Trans-units $trans_units = explode('<trans-unit', $documentContent); foreach ($trans_units as $pos => $trans_unit) { // First element in the XLIFF split is the header, not the first file if ($pos > 0) { //remove seg-source tags $trans_unit = preg_replace('|<seg-source.*?</seg-source>|si', '', $trans_unit); //take the target content $trans_unit = preg_replace('#<mrk[^>]+>|</mrk>#si', '', $trans_unit); $trans_units[$pos] = $trans_unit; } } // End of trans-units $documentContent = implode('<trans-unit', $trans_units); } if (!$is_utf8) { list($__utf8, $documentContent) = CatUtils::convertEncoding($original_charset, $documentContent); } return $documentContent; }