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');
     }
 }
Beispiel #2
0
    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 __construct()
 {
     parent::__construct();
     $filterArgs = array('id_job' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'password' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'propagate' => array('filter' => FILTER_VALIDATE_BOOLEAN, 'flags' => FILTER_NULL_ON_FAILURE), 'id_segment' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'time_to_edit' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'id_translator' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'translation' => array('filter' => FILTER_UNSAFE_RAW), 'version' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'chosen_suggestion_index' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'status' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'splitStatuses' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH));
     $this->__postInput = filter_input_array(INPUT_POST, $filterArgs);
     $this->id_job = $this->__postInput['id_job'];
     $this->password = $this->__postInput['password'];
     $this->propagate = $this->__postInput['propagate'];
     //not used here but used in child class setAutoPropagationController
     $this->id_segment = $this->__postInput['id_segment'];
     $this->time_to_edit = (int) $this->__postInput['time_to_edit'];
     //cast to int, so the default is 0
     $this->id_translator = $this->__postInput['id_translator'];
     $this->client_target_version = empty($this->__postInput['version']) ? '0' : $this->__postInput['version'];
     list($this->translation, $this->split_chunk_lengths) = CatUtils::parseSegmentSplit(CatUtils::view2rawxliff($this->__postInput['translation']), ' ');
     $this->chosen_suggestion_index = $this->__postInput['chosen_suggestion_index'];
     $this->status = strtoupper($this->__postInput['status']);
     $this->split_statuses = explode(",", strtoupper($this->__postInput['splitStatuses']));
     //strtoupper transforms null to ""
     //PATCH TO FIX BOM INSERTIONS
     $this->translation = str_replace("", '', $this->translation);
     if (is_null($this->propagate) || !isset($this->propagate)) {
         $this->propagate = true;
     }
     Log::doLog($this->__postInput);
 }
 /**
  * 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();
     }
 }
Beispiel #6
0
    public function testTagPositionHardNesting_2()
    {
        $source_seg = <<<SRC
<g id="6"> <g id="7">st</g><g id="8">&nbsp;<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">&nbsp;<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));
    }
 /**
  * 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);
     }
 }
 $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 doReplaceAll()
 {
     $this->queryParams['trg'] = $this->target;
     $this->queryParams['trg'] = CatUtils::view2rawxliff($this->target);
     $this->queryParams['replacement'] = CatUtils::view2rawxliff($this->replace);
     /**
      * Leave the FatalErrorHandler catch the Exception, so the message with Contact Support will be sent
      * @throws Exception
      */
     doReplaceAll($this->queryParams);
     //SKIPPED setContribution for all segments ( Un-Completed )
     //        if ( $this->job_data['id_tms'] != 0 ) {
     //
     //            $config = TMS::getConfigStruct();
     //
     //            $config[ 'segment' ]     = CatUtils::view2rawxliff( $this->source );
     //            $config[ 'translation' ] = CatUtils::view2rawxliff( $this->target );
     //            $config[ 'source_lang' ] = $this->source;
     //            $config[ 'target_lang' ] = $this->target;
     //            $config[ 'email' ]       = "*****@*****.**";
     //
     //
     //            //instantiate TMS object
     //            $tms    = new TMS( $this->job_data['id_tms'] );
     //            $result = array();
     //
     //            $this->checkLogin();
     //
     //            try {
     //
     //                $_from_url = parse_url( @$_SERVER['HTTP_REFERER'] );
     //                $url_request = strpos( $_from_url['path'] , "/revise" ) === 0;
     //
     //                if ( $url_request ) {
     //                    $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
     //                }
     //
     //                //find all the job's TMs with write grants and make a contribution to them
     //                $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys(  $this->job_data['tm_keys'], 'w', 'tm', $this->uid, $this->userRole  );
     //
     //                if ( !empty( $tm_keys ) ) {
     //
     //                    foreach ( $tm_keys as $i => $tm_info ) {
     //                        $config[ 'id_user' ][] = $tm_info->key;
     //                    }
     //
     //                    $res = $tms->set( $config );
     //
     //                    if ( !$res ) {
     //
     //                        $this->result[ 'error' ][ ] = array(
     //                                "code"    => -5,
     //                                "message" => "Set contribution error" );
     //
     //                        Log::doLog( "Set contribution error " . implode( ",", $config['id_user'] ) );
     //
     //                    }
     //
     //                } else {
     //
     //                    $res = $tms->set( $config );
     //
     //                    if ( !$res ) {
     //                        $result[ ]                  = $res;
     //                        $this->result[ 'error' ][ ] = array(
     //                                "code"    => -5,
     //                                "message" => "Set contribution error"
     //                        );
     //
     //                    }
     //
     //                }
     //
     //
     //            } catch ( Exception $e ) {
     //                $this->result[ 'error' ][ ] = array( "code" => -6, "message" => "Error while retrieving job's TM." );
     //                Log::doLog( __METHOD__ . " -> " . $e->getMessage() );
     //            }
     //
     //        }
 }
 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()
 {
     if (empty($this->id_segment)) {
         $this->result['errors'][] = array("code" => -1, "message" => "missing id_segment");
     }
     if (empty($this->text)) {
         $this->result['errors'][] = array("code" => -2, "message" => "missing text");
     }
     if (empty($this->num_results)) {
         $this->num_results = INIT::$DEFAULT_NUM_RESULTS_FROM_TM;
     }
     if (!empty($this->result['errors'])) {
         return -1;
     }
     $st = getJobData($this->id_job);
     $this->source = $st['source'];
     $this->target = $st['target'];
     $this->id_mt_engine = $st['id_mt_engine'];
     $this->id_tms = $st['id_tms'];
     $tms_match = array();
     if (!empty($this->id_tms)) {
         $mt_from_tms = 1;
         if (!empty($this->id_mt_engine)) {
             $mt_from_tms = 0;
         }
         //log::doLog("before $this->text");
         $this->text = CatUtils::view2rawxliff($this->text);
         //	log::doLog("after $this->text");
         $tms = new TMS($this->id_tms);
         $tms_match = $tms->get($this->text, $this->source, $this->target, "*****@*****.**", $mt_from_tms, $this->id_translator);
         //	log::doLog ("tms_match");
         //log::doLog ($tms_match);
     }
     // UNUSED
     $mt_res = array();
     $mt_match = "";
     if (!empty($this->id_mt_engine)) {
         $mt = new MT($this->id_mt_engine);
         $mt_result = $mt->get($this->text, $this->source, $this->target);
         if ($mt_result[0] < 0) {
             $mt_match = '';
         } else {
             $mt_match = $mt_result[1];
             $penalty = $mt->getPenalty();
             $mt_score = 100 - $penalty;
             $mt_score .= "%";
             $mt_match_res = new TMS_GET_MATCHES($this->text, $mt_match, $mt_score, "MT-" . $mt->getName(), date("Y-m-d"));
             $mt_res = $mt_match_res->get_as_array();
         }
     }
     $matches = array();
     if (!empty($tms_match)) {
         $matches = $tms_match;
     }
     if (!empty($mt_match)) {
         $matches[] = $mt_res;
         usort($matches, "compareScore");
     }
     $matches = array_slice($matches, 0, INIT::$DEFAULT_NUM_RESULTS_FROM_TM);
     $res = $this->setSuggestionReport($matches);
     if (is_array($res) and array_key_exists("error", $res)) {
     }
     foreach ($matches as &$match) {
         if (strpos($match['created_by'], 'MT') !== false) {
             $match['match'] = 'MT';
         }
         if ($match['created_by'] == 'MT!') {
             $match['created_by'] = 'MT';
             //MyMemory returns MT!
         }
     }
     if (empty($matches)) {
         $this->result['errors'][] = array("code" => -3, "message" => "empty matches");
     } else {
         $this->result['data']['matches'] = $matches;
     }
 }
 protected function _delete($config)
 {
     $tm_keys = $this->job_info['tm_keys'];
     if (self::isRevision()) {
         $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
     }
     //get TM keys with read grants
     $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($tm_keys, 'w', 'glos', $this->uid, $this->userRole);
     $config['segment'] = CatUtils::view2rawxliff($config['segment']);
     $config['translation'] = CatUtils::view2rawxliff($config['translation']);
     //prepare the error report
     $set_code = array();
     //set the glossary entry for each key with write grants
     if (count($tm_keys)) {
         /**
          * @var $tm_key TmKeyManagement_TmKeyStruct
          */
         foreach ($tm_keys as $tm_key) {
             $config['id_user'] = $tm_key->key;
             $TMS_RESULT = $this->_TMS->delete($config);
             $set_code[] = $TMS_RESULT;
         }
     }
     $set_successful = true;
     if (array_search(false, $set_code, true)) {
         $set_successful = false;
     }
     $this->result['code'] = $set_successful;
     $this->result['data'] = $set_successful ? 'OK' : null;
 }
Beispiel #15
0
 /**
  * @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);
 }
 public function doAction()
 {
     if (is_null($this->source) || $this->source === '') {
         $this->result['errors'][] = array("code" => -1, "message" => "missing source segment");
     }
     if (is_null($this->target) || $this->target === '') {
         $this->result['errors'][] = array("code" => -2, "message" => "missing target segment");
     }
     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" => -2, "message" => "missing target lang");
     }
     if (empty($this->id_job)) {
         $this->result['errors'][] = array("code" => -4, "message" => "id_job not valid");
         $msg = "\n\n Critical. Quit. \n\n " . var_export(array_merge($this->result, $_POST), true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         // critical. Quit.
         return -1;
     }
     //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)) {
         $this->result['errors'][] = array("code" => -101, "message" => "error fetching job data");
     }
     if (empty($this->result['errors']) && !$pCheck->grantJobAccessByJobData($job_data, $this->password)) {
         $this->result['errors'][] = array("code" => -10, "message" => "wrong password");
     }
     if (!empty($this->result['errors'])) {
         $msg = "\n\n Error \n\n " . var_export(array_merge($this->result, $_POST), true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         return -1;
     }
     $id_tms = $job_data['id_tms'];
     $tm_keys = $job_data['tm_keys'];
     if ($id_tms != 0) {
         $tms = Engine::getInstance(1);
         /**
          * @var $tms Engines_MyMemory
          */
         $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'] = "*****@*****.**";
         //Props
         $config['prop'] = json_encode(CatUtils::getTMProps($job_data));
         //instantiate TMS object
         $result = array();
         $this->checkLogin();
         try {
             if (self::isRevision()) {
                 $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
             }
             //find all the job's TMs with write grants and make a contribution to them
             $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($tm_keys, 'w', 'tm', $this->uid, $this->userRole);
             if (!empty($tm_keys)) {
                 unset($config['id_user']);
                 foreach ($tm_keys as $i => $tm_info) {
                     $config['id_user'] = $tm_info->key;
                     $res = $tms->set($config);
                     if (!$res) {
                         $result[] = $res;
                         $this->result['errors'][] = array("code" => -5, "message" => "Set contribution error for key " . $tm_info->name);
                     }
                 }
             } else {
                 $res = $tms->set($config);
                 if (!$res) {
                     $result[] = $res;
                     $this->result['errors'][] = array("code" => -5, "message" => "Set contribution error");
                 }
             }
         } catch (Exception $e) {
             $this->result['errors'][] = array("code" => -6, "message" => "Error while retrieving job's TM.");
             Log::doLog(__METHOD__ . " -> " . $e->getMessage());
         }
         //if translator_username is empty no key is added to MyMemory API SET query string, so, anonymous by default
         if (count($result)) {
             $this->result['code'] = -1;
             $this->result['data'] = "KO";
             Log::doLog("Set Contribution Failed.");
             Log::doLog(var_export($_POST, true));
             return -1;
         }
         $this->result['code'] = 1;
         $this->result['data'] = "OK";
     } else {
         $this->result['code'] = 1;
         $this->result['data'] = "NOCONTRIB_OK";
     }
 }
Beispiel #17
0
    public function testRealString1()
    {
        $source_seg = <<<TRG
<g id="1877">31-235</g>\t<g id="1878">The default PR upper alarm is120.</g>
TRG;
        $target_seg = <<<SRC
<g id="1877"> 31-235 </g><g id="1878"> L'impostazione predefinita PR IS120 allarme. </g>
SRC;
        $source_seg = CatUtils::view2rawxliff($source_seg);
        $target_seg = CatUtils::view2rawxliff($target_seg);
        $check = new PostProcess($source_seg, $target_seg);
        $check->realignMTSpaces();
        $warnings = $check->getWarnings();
        $errors = $check->getErrors();
        $this->assertFalse($check->thereAreErrors());
        $this->assertFalse($check->thereAreWarnings());
        $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();
        //trick strings are not exactly the same .. there's a tab between tags in source string
        $this->assertEquals('<g id="1877">31-235</g><g id="1878">L\'impostazione predefinita PR IS120 allarme.</g>', $normalized);
    }
 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;
 }
         $log_prepend = $UNIQUID . " - SERVER REALIGN IDS PROCEDURE | ";
         if (!$qaRealign->thereAreErrors()) {
             Log::doLog($log_prepend . " - Requested Segment: " . var_export($segment, true));
             Log::doLog($log_prepend . "Fuzzy: " . $fuzzy . " - Try to Execute Tag ID Realignment.");
             Log::doLog($log_prepend . "TMS RAW RESULT:");
             Log::doLog($log_prepend . var_export($matches[0], true));
             Log::doLog($log_prepend . "Realignment Success:");
             $matches[0]['raw_translation'] = $qaRealign->getTrgNormalized();
             $matches[0]['match'] = $fuzzy == 0 ? '100%' : '99%';
             Log::doLog($log_prepend . "Raw Translation: " . var_export($matches[0]['raw_translation'], true));
         } else {
             Log::doLog($log_prepend . 'Realignment Failed. Skip. Segment: ' . $segment['sid']);
         }
     }
 }
 $suggestion = CatUtils::view2rawxliff($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 = $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']));
 //echo "sid is $sid ";
 $eq_words = $equivalentWordMapping[$new_match_type] * $raw_wc / 100;
 $standard_words = $eq_words;
 if ($new_match_type == 'MT') {
     $standard_words = $equivalentWordMapping["NO_MATCH"] * $raw_wc / 100;
 }
 !empty($matches[0]['sentence_confidence']) ? $mt_qe = floatval($matches[0]['sentence_confidence']) : ($mt_qe = null);
 $check = new QA($text, $suggestion);