Beispiel #1
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 setUp()
 {
     parent::setUp();
     $this->hasOne('QA as ReplyTo', array('local' => 'reply_id', 'foreign' => 'id'));
     $this->hasOne('Question', array('local' => 'id', 'foreign' => 'best_id'));
     $this->hasMany('Question as Branches', array('local' => 'id', 'foreign' => 'origin_id'));
 }
 public function setUp()
 {
     parent::setUp();
     $this->hasOne('Answer as Best', array('local' => 'best_id', 'foreign' => 'id'));
     $this->hasOne('Answer as Origin', array('local' => 'origin_id', 'foreign' => 'id'));
     $this->hasMany('Question as Related', array('refClass' => 'QuestionRelation', 'local' => 'from_id', 'foreign' => 'to_id', 'equal' => true));
     $this->hasMany('Tag as Tags', array('refClass' => 'QuestionTag', 'local' => 'question_id', 'foreign' => 'tag_id'));
 }
Beispiel #4
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));
    }
 /**
  * When Called it perform the controller action to retrieve/manipulate data
  *
  * @return mixed
  */
 function doAction()
 {
     try {
         $this->_checkData("auto_propagation.log");
     } catch (Exception $e) {
         if ($e->getCode() == -1) {
             Utils::sendErrMailReport($e->getMessage());
         }
         Log::doLog($e->getMessage());
         return $e->getCode();
     }
     $cookie_key = '_auto-propagation-' . $this->id_job . "-" . $this->password;
     $boolString = (string) (int) $this->propagateAll;
     $cookieLife = new DateTime();
     $cookieLife->modify('+15 days');
     $db = Database::obtain();
     if ($this->propagateAll) {
         $db->begin();
         $old_translation = getCurrentTranslation($this->id_job, $this->id_segment);
         //check tag mismatch
         //get original source segment, first
         $segment = getSegment($this->id_segment);
         //compare segment-translation and get results
         $check = new QA($segment['segment'], $this->translation);
         $check->performConsistencyCheck();
         if ($check->thereAreWarnings()) {
             $err_json = $check->getWarningsJSON();
             $translation = $this->translation;
         } else {
             $err_json = '';
             $translation = $check->getTrgNormalized();
         }
         $TPropagation = array();
         $TPropagation['id_job'] = $this->id_job;
         $TPropagation['translation'] = $translation;
         $TPropagation['status'] = Constants_TranslationStatus::STATUS_DRAFT;
         $TPropagation['autopropagated_from'] = $this->id_segment;
         $_Translation['serialized_errors_list'] = $err_json;
         $TPropagation['warning'] = $check->thereAreWarnings();
         $TPropagation['translation_date'] = date("Y-m-d H:i:s");
         $TPropagation['segment_hash'] = $old_translation['segment_hash'];
         try {
             propagateTranslation($TPropagation, $this->jobData, $this->id_segment, true);
             $db->commit();
         } catch (Exception $e) {
             $db->rollback();
             $msg = $e->getMessage() . "\n\n" . $e->getTraceAsString();
             Log::doLog($msg);
             Utils::sendErrMailReport($msg);
         }
     }
     setcookie($cookie_key, $boolString, $cookieLife->getTimestamp(), "/", $_SERVER['HTTP_HOST']);
     Log::doLog("Auto-propagation for already translated segments on Job " . $this->id_job . " set to '" . var_export($this->propagateAll, true) . "'. Cookie Expire at " . $cookieLife->format('Y-m-d H:i:s'));
     $this->result['errors'][] = array("code" => 0, "message" => "OK");
 }
 /**
  * Performs a check on single segment
  *
  */
 private function __segmentWarningsCall()
 {
     $this->result['details'] = null;
     $this->result['token'] = $this->__postInput->token;
     $this->result['total'] = 0;
     $QA = new QA($this->__postInput->src_content, $this->__postInput->trg_content);
     $QA->performConsistencyCheck();
     if (is_array($this->__postInput->glossaryList) && !empty($this->__postInput->glossaryList)) {
         /**
          * FIXME: temporarily disabled due to a bug.
          */
         //            $QA->performGlossaryCheck( $this->__postInput->glossaryList );
     }
     if ($QA->thereAreNotices()) {
         //        if ( $QA->thereAreErrors() ) {
         $this->result['details'] = array();
         $this->result['details']['id_segment'] = $this->__postInput->id;
         //            $this->result[ 'details' ][ 'warnings' ]   = $QA->getErrorsJSON();
         //            $this->result[ 'total' ]                                             = count( $QA->getErrors() );
         $this->result['details']['warnings'] = $QA->getNoticesJSON();
         $this->result['details']['tag_mismatch'] = $QA->getMalformedXmlStructs();
         $this->result['details']['tag_mismatch']['order'] = $QA->getTargetTagPositionError();
         $this->result['total'] = count($QA->getNotices());
         //temp
         //            Log::doLog($this->__postInput->trg_content);
         //            Log::doLog($this->result);
     }
 }
 public function doAction()
 {
     if (!$this->concordance_search) {
         //execute these lines only in segment contribution search,
         //in case of user concordance search skip these lines
         //because segment can be optional
         if (empty($this->id_segment)) {
             $this->result['errors'][] = array("code" => -1, "message" => "missing id_segment");
         }
     }
     if (is_null($this->text) || $this->text === '') {
         $this->result['errors'][] = array("code" => -2, "message" => "missing text");
     }
     if (empty($this->id_job)) {
         $this->result['errors'][] = array("code" => -3, "message" => "missing id_job");
     }
     if (empty($this->num_results)) {
         $this->num_results = INIT::$DEFAULT_NUM_RESULTS_FROM_TM;
     }
     if (!empty($this->result['errors'])) {
         return -1;
     }
     //get Job Infos, we need only a row of jobs ( split )
     $this->jobData = getJobData($this->id_job, $this->password);
     $pCheck = new AjaxPasswordCheck();
     //check for Password correctness
     if (empty($this->jobData) || !$pCheck->grantJobAccessByJobData($this->jobData, $this->password)) {
         $this->result['errors'][] = array("code" => -10, "message" => "wrong password");
         return -1;
     }
     /*
      * string manipulation strategy
      *
      */
     if (!$this->concordance_search) {
         //
         $this->text = CatUtils::view2rawxliff($this->text);
         $this->source = $this->jobData['source'];
         $this->target = $this->jobData['target'];
     } else {
         $regularExpressions = $this->tokenizeSourceSearch();
         if ($this->switch_languages) {
             /*
              *
              * switch languages from user concordances search on the target language value
              * Example:
              * Job is in
              *      source: it_IT,
              *      target: de_DE
              *
              * user perform a right click for concordance help on a german word or phrase
              * we want result in italian from german source
              *
              */
             $this->source = $this->jobData['target'];
             $this->target = $this->jobData['source'];
         } else {
             $this->source = $this->jobData['source'];
             $this->target = $this->jobData['target'];
         }
     }
     $this->id_mt_engine = $this->jobData['id_mt_engine'];
     $this->id_tms = $this->jobData['id_tms'];
     $this->tm_keys = $this->jobData['tm_keys'];
     $config = array();
     if ($this->id_tms == 1) {
         /**
          * MyMemory Enabled
          */
         $config['get_mt'] = true;
         $config['mt_only'] = false;
         if ($this->id_mt_engine != 1) {
             /**
              * Don't get MT contribution from MyMemory ( Custom MT )
              */
             $config['get_mt'] = false;
         }
         $_TMS = $this->id_tms;
     } else {
         if ($this->id_tms == 0 && $this->id_mt_engine == 1) {
             /**
              * MyMemory disabled but MT Enabled and it is NOT a Custom one
              * So tell to MyMemory to get MT only
              */
             $config['get_mt'] = true;
             $config['mt_only'] = true;
             $_TMS = 1;
             /* MyMemory */
         }
     }
     /**
      * if No TM server and No MT selected $_TMS is not defined
      * so we want not to perform TMS Call
      *
      */
     if (isset($_TMS)) {
         /**
          * @var $tms Engines_MyMemory
          */
         $tms = Engine::getInstance($_TMS);
         $config = array_merge($tms->getConfigStruct(), $config);
         $config['segment'] = $this->text;
         $config['source'] = $this->source;
         $config['target'] = $this->target;
         $config['email'] = INIT::$MYMEMORY_API_KEY;
         $config['id_user'] = array();
         $config['num_result'] = $this->num_results;
         $config['isConcordance'] = $this->concordance_search;
         //get job's TM keys
         $this->checkLogin();
         try {
             if (self::isRevision()) {
                 $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
             }
             $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($this->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.");
             Log::doLog($e->getMessage());
             return;
         }
         $tms_match = $tms->get($config);
         $tms_match = $tms_match->get_matches_as_array();
     }
     if ($this->id_mt_engine > 1) {
         /**
          * @var $mt Engines_Moses
          */
         $mt = Engine::getInstance($this->id_mt_engine);
         $config = $mt->getConfigStruct();
         $config['segment'] = $this->text;
         $config['source'] = $this->source;
         $config['target'] = $this->target;
         $config['id_user'] = INIT::$MYMEMORY_API_KEY;
         $config['segid'] = $this->id_segment;
         $mt_result = $mt->get($config);
         if (isset($mt_result['error']['code'])) {
             $mt_result['error']['created_by_type'] = 'MT';
             $this->result['errors'][] = $mt_result['error'];
             $mt_result = false;
         }
     }
     $matches = array();
     if (!empty($tms_match)) {
         $matches = $tms_match;
     }
     if (!empty($mt_result)) {
         $matches[] = $mt_result;
         usort($matches, array("getContributionController", "__compareScore"));
         //this is necessary since usort sorts is ascending order, thus inverting the ranking
         $matches = array_reverse($matches);
     }
     $matches = array_slice($matches, 0, $this->num_results);
     isset($matches[0]['match']) ? $firstMatchVal = floatval($matches[0]['match']) : null;
     if (isset($firstMatchVal) && $firstMatchVal >= 90 && $firstMatchVal < 100) {
         $srcSearch = strip_tags($this->text);
         $segmentFound = strip_tags($matches[0]['raw_segment']);
         $srcSearch = mb_strtolower(preg_replace('#[\\x{20}]{2,}#u', chr(0x20), $srcSearch));
         $segmentFound = mb_strtolower(preg_replace('#[\\x{20}]{2,}#u', chr(0x20), $segmentFound));
         $fuzzy = levenshtein($srcSearch, $segmentFound) / log10(mb_strlen($srcSearch . $segmentFound) + 1);
         //levenshtein handle max 255 chars per string and returns -1, so fuzzy var can be less than 0 !!
         if ($srcSearch == $segmentFound || $fuzzy < 2.5 && $fuzzy >= 0) {
             $qaRealign = new QA($this->text, html_entity_decode($matches[0]['raw_translation']));
             $qaRealign->tryRealignTagID();
             $log_prepend = "CLIENT REALIGN IDS PROCEDURE | ";
             if (!$qaRealign->thereAreErrors()) {
                 /*
                 Log::doLog( $log_prepend . " - Requested Segment: " . var_export( $this->__postInput, 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]['segment'] = CatUtils::rawxliff2view($this->text);
                 $matches[0]['translation'] = CatUtils::rawxliff2view($qaRealign->getTrgNormalized());
                 $matches[0]['match'] = $fuzzy == 0 ? '100%' : '99%';
                 /*
                                     Log::doLog( $log_prepend . "View Segment:     " . var_export($matches[0]['segment'], true) );
                                     Log::doLog( $log_prepend . "View Translation: " . var_export($matches[0]['translation'], true) );
                 */
             } else {
                 Log::doLog($log_prepend . 'Realignment Failed. Skip. Segment: ' . $this->__postInput['id_segment']);
             }
         }
     }
     /* New Feature only if this is not a MT and if it is a ( 90 =< MATCH < 100 ) */
     if (!$this->concordance_search) {
         //execute these lines only in segment contribution search,
         //in case of user concordance search skip these lines
         $res = $this->setSuggestionReport($matches);
         if (is_array($res) and array_key_exists("error", $res)) {
             // error occurred
         }
         //
     }
     foreach ($matches as &$match) {
         if (strpos($match['created_by'], 'MT') !== false) {
             $match['match'] = 'MT';
             $QA = new PostProcess($match['raw_segment'], $match['raw_translation']);
             $QA->realignMTSpaces();
             //this should every time be ok because MT preserve tags, but we use the check on the errors
             //for logic correctness
             if (!$QA->thereAreErrors()) {
                 $match['raw_translation'] = $QA->getTrgNormalized();
                 $match['translation'] = CatUtils::rawxliff2view($match['raw_translation']);
             } else {
                 Log::doLog($QA->getErrors());
             }
         }
         if ($match['created_by'] == 'MT!') {
             $match['created_by'] = 'MT';
             //MyMemory returns MT!
         } else {
             $match['created_by'] = $this->__changeSuggestionSource($match);
         }
         if (!empty($match['sentence_confidence'])) {
             $match['sentence_confidence'] = round($match['sentence_confidence'], 0) . "%";
         }
         if ($this->concordance_search) {
             $match['segment'] = strip_tags(html_entity_decode($match['segment']));
             $match['segment'] = preg_replace('#[\\x{20}]{2,}#u', chr(0x20), $match['segment']);
             //Do something with &$match, tokenize strings and send to client
             $match['segment'] = preg_replace(array_keys($regularExpressions), array_values($regularExpressions), $match['segment']);
             $match['translation'] = strip_tags(html_entity_decode($match['translation']));
         }
     }
     $this->result['data']['matches'] = $matches;
 }
 protected function prepareSegment($seg, $trans_unit_translation = "")
 {
     $end_tags = "";
     //We don't need transform/sanitize from wiew to xliff because the values comes from Database
     //QA non sense for source/source check, until source can be changed. For now SKIP
     if (is_null($seg['translation']) || $seg['translation'] == '') {
         $translation = $seg['segment'];
     } else {
         $translation = $seg['translation'];
         if (empty($seg['locked'])) {
             //consistency check
             $check = new QA($seg['segment'], $translation);
             $check->performTagCheckOnly();
             if ($check->thereAreErrors()) {
                 $translation = '|||UNTRANSLATED_CONTENT_START|||' . $seg['segment'] . '|||UNTRANSLATED_CONTENT_END|||';
                 Log::doLog("tag mismatch on\n" . print_r($seg, true) . "\n(because of: " . print_r($check->getErrors(), true) . ")");
             }
         }
     }
     if ($seg['mrk_id'] !== null) {
         $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>";
     }
     $trans_unit_translation .= $seg['prev_tags'] . $translation . $end_tags . $seg['succ_tags'];
     return $trans_unit_translation;
 }
     continue;
 }
 $tm_match_type = $matches[0]['match'];
 if (stripos($matches[0]['created_by'], "MT") !== false) {
     $tm_match_type = "MT";
 }
 isset($matches[0]['match']) ? $firstMatchVal = floatval($matches[0]['match']) : null;
 if (isset($firstMatchVal) && $firstMatchVal >= 90 && $firstMatchVal < 100) {
     $srcSearch = strip_tags($text);
     $segmentFound = strip_tags($matches[0]['raw_segment']);
     $srcSearch = mb_strtolower(preg_replace('#[\\x{20}]{2,}#u', chr(0x20), $srcSearch));
     $segmentFound = mb_strtolower(preg_replace('#[\\x{20}]{2,}#u', chr(0x20), $segmentFound));
     $fuzzy = @levenshtein($srcSearch, $segmentFound) / log10(mb_strlen($srcSearch . $segmentFound) + 1);
     //levenshtein handle max 255 chars per string and returns -1, so fuzzy var can be less than 0 !!
     if ($srcSearch == $segmentFound || $fuzzy < 2.5 && $fuzzy > 0) {
         $qaRealign = new QA($text, html_entity_decode($matches[0]['raw_translation']));
         $qaRealign->tryRealignTagID();
         $log_prepend = $UNIQUID . " - SERVER REALIGN IDS PROCEDURE | ";
         if (!$qaRealign->thereAreErrors()) {
             /*
             _TimeStampMsg( $log_prepend . " - Requested Segment: " . var_export( $objQueue, true ) );
             _TimeStampMsg( $log_prepend . "Fuzzy: " . $fuzzy . " - Try to Execute Tag ID Realignment." );
             _TimeStampMsg( $log_prepend . "TMS RAW RESULT:" );
             _TimeStampMsg( $log_prepend . var_export( $matches[ 0 ], true ) );
             
             _TimeStampMsg( $log_prepend . "Realignment Success:" );
             */
             $matches[0]['raw_translation'] = $qaRealign->getTrgNormalized();
             $matches[0]['match'] = $fuzzy == 0 ? '100%' : '99%';
             //_TimeStampMsg( $log_prepend . "Raw Translation: " . var_export( $matches[ 0 ]['raw_translation'], true ) );
         } else {
 public function doAction()
 {
     try {
         $this->_checkData();
     } catch (Exception $e) {
         if ($e->getCode() == -1) {
             Utils::sendErrMailReport($e->getMessage());
         }
         Log::doLog($e->getMessage());
         return $e->getCode();
     }
     //check tag mismatch
     //get original source segment, first
     $segment = getSegment($this->id_segment);
     //compare segment-translation and get results
     $check = new QA($segment['segment'], $this->translation);
     $check->performConsistencyCheck();
     if ($check->thereAreWarnings()) {
         $err_json = $check->getWarningsJSON();
         $translation = $this->translation;
     } else {
         $err_json = '';
         $translation = $check->getTrgNormalized();
     }
     /*
      * begin stats counter
      *
      * It works good with default InnoDB Isolation level
      *
      * REPEATABLE-READ offering a row level lock for this id_segment
      *
      */
     $db = Database::obtain();
     $db->begin();
     $old_translation = getCurrentTranslation($this->id_job, $this->id_segment);
     //        $old_version = ( empty( $old_translation['translation_date'] ) ? '0' : date_create( $old_translation['translation_date'] )->getTimestamp() );
     //        if( $this->client_target_version != $old_version ){
     //            $this->result[ 'errors' ][ ] = array( "code" => -102, "message" => "Translation version mismatch" );
     //            $db->rollback();
     //            return false;
     //        }
     //if volume analysis is not enabled and no translation rows exists
     //create the row
     if (!INIT::$VOLUME_ANALYSIS_ENABLED && empty($old_translation['status'])) {
         $_Translation = array();
         $_Translation['id_segment'] = (int) $this->id_segment;
         $_Translation['id_job'] = (int) $this->id_job;
         $_Translation['status'] = Constants_TranslationStatus::STATUS_NEW;
         $_Translation['segment_hash'] = $segment['segment_hash'];
         $_Translation['translation'] = $segment['segment'];
         $_Translation['standard_word_count'] = $segment['raw_word_count'];
         $_Translation['serialized_errors_list'] = '';
         $_Translation['suggestion_position'] = 0;
         $_Translation['warning'] = false;
         $_Translation['translation_date'] = date("Y-m-d H:i:s");
         $res = addTranslation($_Translation);
         if ($res < 0) {
             $this->result['errors'][] = array("code" => -101, "message" => "database errors");
             $db->rollback();
             return $res;
         }
         /*
          * begin stats counter
          *
          */
         $old_translation = $_Translation;
     }
     $_Translation = array();
     $_Translation['id_segment'] = $this->id_segment;
     $_Translation['id_job'] = $this->id_job;
     $_Translation['status'] = $this->status;
     $_Translation['time_to_edit'] = $this->time_to_edit;
     $_Translation['translation'] = preg_replace('/[ \\t\\n\\r\\0\\x0A\\xA0]+$/u', '', $translation);
     $_Translation['serialized_errors_list'] = $err_json;
     $_Translation['suggestion_position'] = $this->chosen_suggestion_index;
     $_Translation['warning'] = $check->thereAreWarnings();
     $_Translation['translation_date'] = date("Y-m-d H:i:s");
     /**
      * when the status of the translation changes, the auto propagation flag
      * must be removed
      */
     if ($_Translation['translation'] != $old_translation['translation'] || $this->status == Constants_TranslationStatus::STATUS_TRANSLATED || $this->status == Constants_TranslationStatus::STATUS_APPROVED) {
         $_Translation['autopropagated_from'] = 'NULL';
     }
     $res = CatUtils::addSegmentTranslation($_Translation);
     if (!empty($res['errors'])) {
         $this->result['errors'] = $res['errors'];
         $msg = "\n\n Error addSegmentTranslation \n\n Database Error \n\n " . var_export(array_merge($this->result, $_POST), true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         $db->rollback();
         return -1;
     }
     if (INIT::$DQF_ENABLED && !empty($this->jobData['dqf_key']) && $_Translation['status'] == Constants_TranslationStatus::STATUS_TRANSLATED) {
         $dqfSegmentStruct = DQF_DqfSegmentStruct::getStruct();
         if ($old_translation['suggestion'] == null) {
             $dqfSegmentStruct->target_segment = "";
             $dqfSegmentStruct->tm_match = 0;
         } else {
             $dqfSegmentStruct->target_segment = $old_translation['suggestion'];
             $dqfSegmentStruct->tm_match = $old_translation['suggestion_match'];
         }
         $dqfSegmentStruct->task_id = $this->id_job;
         $dqfSegmentStruct->segment_id = $this->id_segment;
         $dqfSegmentStruct->source_segment = $segment['segment'];
         $dqfSegmentStruct->new_target_segment = $_Translation['translation'];
         $dqfSegmentStruct->time = $_Translation['time_to_edit'];
         //            $dqfSegmentStruct->mtengine = $this->jobData['id_mt_engine'];
         $dqfSegmentStruct->mt_engine_version = 1;
         try {
             $dqfQueueHandler = new Analysis_DqfQueueHandler();
             $dqfQueueHandler->createSegment($dqfSegmentStruct);
         } catch (Exception $exn) {
             $msg = $exn->getMessage() . "\n\n" . $exn->getTraceAsString();
             Log::doLog($msg);
             Utils::sendErrMailReport($msg);
         }
     }
     $propagateToTranslated = true;
     //for the moment, this is set explicitely
     if ($this->propagate == false) {
         $propagateToTranslated = false;
     }
     //propagate translations
     $TPropagation = array();
     //Warning: this value will NOT be used to update values,
     //but to exclude current segment from auto-propagation
     $_idSegment = $this->id_segment;
     $propagateToTranslated ? $TPropagation['status'] = $this->status : null;
     $TPropagation['id_job'] = $this->id_job;
     $TPropagation['translation'] = $translation;
     $TPropagation['autopropagated_from'] = $this->id_segment;
     $TPropagation['serialized_errors_list'] = $err_json;
     $TPropagation['warning'] = $check->thereAreWarnings();
     //        $TPropagation[ 'translation_date' ]       = date( "Y-m-d H:i:s" );
     $TPropagation['segment_hash'] = $old_translation['segment_hash'];
     $propagationTotal = array();
     if ($propagateToTranslated && in_array($this->status, array(Constants_TranslationStatus::STATUS_TRANSLATED, Constants_TranslationStatus::STATUS_APPROVED, Constants_TranslationStatus::STATUS_REJECTED))) {
         try {
             $propagationTotal = propagateTranslation($TPropagation, $this->jobData, $_idSegment, $propagateToTranslated);
         } catch (Exception $e) {
             $msg = $e->getMessage() . "\n\n" . $e->getTraceAsString();
             Log::doLog($msg);
             Utils::sendErrMailReport($msg);
         }
     }
     //Recount Job Totals
     $old_wStruct = new WordCount_Struct();
     $old_wStruct->setIdJob($this->id_job);
     $old_wStruct->setJobPassword($this->password);
     $old_wStruct->setNewWords($this->jobData['new_words']);
     $old_wStruct->setDraftWords($this->jobData['draft_words']);
     $old_wStruct->setTranslatedWords($this->jobData['translated_words']);
     $old_wStruct->setApprovedWords($this->jobData['approved_words']);
     $old_wStruct->setRejectedWords($this->jobData['rejected_words']);
     $old_wStruct->setIdSegment($this->id_segment);
     //redundant, this is made into WordCount_Counter::updateDB
     $old_wStruct->setOldStatus($old_translation['status']);
     $old_wStruct->setNewStatus($this->status);
     //redundant because the update is made only where status = old status
     if ($this->status != $old_translation['status']) {
         //cambiato status, sposta i conteggi
         $old_count = !is_null($old_translation['eq_word_count']) ? $old_translation['eq_word_count'] : $segment['raw_word_count'];
         //if there is not a row in segment_translations because volume analysis is disabled
         //search for a just created row
         $old_status = !empty($old_translation['status']) ? $old_translation['status'] : Constants_TranslationStatus::STATUS_NEW;
         $counter = new WordCount_Counter($old_wStruct);
         $counter->setOldStatus($old_status);
         $counter->setNewStatus($this->status);
         $newValues = array();
         $newValues[] = $counter->getUpdatedValues($old_count);
         foreach ($propagationTotal as $__pos => $old_value) {
             $counter->setOldStatus($old_value['status']);
             $counter->setNewStatus($this->status);
             $newValues[] = $counter->getUpdatedValues($old_value['total']);
         }
         try {
             $newTotals = $counter->updateDB($newValues);
         } catch (Exception $e) {
             $this->result['errors'][] = array("code" => -101, "message" => "database errors");
             //                Log::doLog("Lock: Transaction Aborted. " . $e->getMessage() );
             //                $x1 = explode( "\n" , var_export( $old_translation, true) );
             //                Log::doLog("Lock: Translation status was " . implode( " ", $x1 ) );
             $db->rollback();
             return $e->getCode();
         }
     } else {
         $newTotals = $old_wStruct;
     }
     $job_stats = CatUtils::getFastStatsForJob($newTotals);
     $project = getProject($this->jobData['id_project']);
     $project = array_pop($project);
     $job_stats['ANALYSIS_COMPLETE'] = $project['status_analysis'] == Constants_ProjectStatus::STATUS_DONE || $project['status_analysis'] == Constants_ProjectStatus::STATUS_NOT_TO_ANALYZE ? true : false;
     $file_stats = array();
     $this->result['stats'] = $job_stats;
     $this->result['file_stats'] = $file_stats;
     $this->result['code'] = 1;
     $this->result['data'] = "OK";
     $this->result['version'] = date_create($_Translation['translation_date'])->getTimestamp();
     /* FIXME: added for code compatibility with front-end. Remove. */
     $_warn = $check->getWarnings();
     $warning = $_warn[0];
     /* */
     $this->result['warning']['cod'] = $warning->outcome;
     if ($warning->outcome > 0) {
         $this->result['warning']['id'] = $this->id_segment;
     } else {
         $this->result['warning']['id'] = 0;
     }
     //strtoupper transforms null to "" so check for the first element to be an empty string
     if (!empty($this->split_statuses[0]) && !empty($this->split_num)) {
         /* put the split inside the transaction if they are present */
         $translationStruct = TranslationsSplit_SplitStruct::getStruct();
         $translationStruct->id_segment = $this->id_segment;
         $translationStruct->id_job = $this->id_job;
         $translationStruct->target_chunk_lengths = array('len' => $this->split_chunk_lengths, 'statuses' => $this->split_statuses);
         $translationDao = new TranslationsSplit_SplitDAO(Database::obtain());
         $result = $translationDao->update($translationStruct);
     }
     $db->commit();
     if ($job_stats['TRANSLATED_PERC'] == '100') {
         $update_completed = setJobCompleteness($this->id_job, 1);
     }
     if (@$update_completed < 0) {
         $msg = "\n\n Error setJobCompleteness \n\n " . var_export($_POST, true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
     }
 }
 /**
  * @return array
  */
 public function getWarning()
 {
     $result = array();
     $QA = new QA($this->source, $this->translation);
     $QA->performConsistencyCheck();
     if ($QA->thereAreNotices()) {
         $notices = $QA->getNoticesJSON();
         $notices = json_decode($notices, true);
         //the outer if it's here because $notices can be
         //an empty string and json_decode will fail into null value
         if (!empty($notices)) {
             $result = array_merge($result, Utils::array_column($notices, 'debug'));
         }
         $tag_mismatch = $QA->getMalformedXmlStructs();
         $tag_order_mismatch = $QA->getTargetTagPositionError();
         if (count($tag_mismatch) > 0) {
             $result[] = sprintf("Tag Mismatch ( %d )", count($tag_mismatch));
         }
         if (count($tag_order_mismatch) > 0) {
             $result[] = sprintf("Tag order mismatch ( %d )", count($tag_order_mismatch));
         }
     }
     $this->warnings = $result;
 }
Beispiel #12
0
 /**
  *  Only if this is not a MT and if it is a ( 90 =< MATCH < 100 ) try to realign tag IDs
  *
  * @param QueueElement $queueElement
  *
  */
 protected function _tryRealignTagID(QueueElement $queueElement)
 {
     isset($this->_matches[0]['match']) ? $firstMatchVal = floatval($this->_matches[0]['match']) : null;
     if (isset($firstMatchVal) && $firstMatchVal >= 90 && $firstMatchVal < 100) {
         $srcSearch = strip_tags($queueElement->params->segment);
         $segmentFound = strip_tags($this->_matches[0]['raw_segment']);
         $srcSearch = mb_strtolower(preg_replace('#[\\x{20}]{2,}#u', chr(0x20), $srcSearch));
         $segmentFound = mb_strtolower(preg_replace('#[\\x{20}]{2,}#u', chr(0x20), $segmentFound));
         $fuzzy = @levenshtein($srcSearch, $segmentFound) / log10(mb_strlen($srcSearch . $segmentFound) + 1);
         //levenshtein handle max 255 chars per string and returns -1, so fuzzy var can be less than 0 !!
         if ($srcSearch == $segmentFound || $fuzzy < 2.5 && $fuzzy > 0) {
             $qaRealign = new \QA($queueElement->params->segment, html_entity_decode($this->_matches[0]['raw_translation']));
             $qaRealign->tryRealignTagID();
             $log_prepend = uniqid('', true) . " - SERVER REALIGN IDS PROCEDURE | ";
             if (!$qaRealign->thereAreErrors()) {
                 /*
                     $this->_doLog( $log_prepend . " - Requested Segment: " . var_export( $queueElement, true ) );
                     $this->_doLog( $log_prepend . "Fuzzy: " . $fuzzy . " - Try to Execute Tag ID Realignment." );
                     $this->_doLog( $log_prepend . "TMS RAW RESULT:" );
                     $this->_doLog( $log_prepend . var_export( $this->_matches[ 0 ]e, true ) );
                     $this->_doLog( $log_prepend . "Realignment Success:" );
                 */
                 $this->_matches[0]['raw_translation'] = $qaRealign->getTrgNormalized();
                 $this->_matches[0]['match'] = $fuzzy == 0 ? '100%' : '99%';
             } else {
                 $this->_doLog($log_prepend . 'Realignment Failed. Skip. Segment: ' . $queueElement->params->id_segment);
             }
         }
     }
 }
 $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);
 $check->performTagCheckOnly();
 //log::doLog($check->getErrors(true));
 echo "--- (child {$my_pid}) : sid={$sid} --- \$tm_match_type={$tm_match_type}, \$fast_match_type={$fast_match_type}, \$new_match_type={$new_match_type}, \$equivalentWordMapping[\$new_match_type]=" . $equivalentWordMapping[$new_match_type] . ", \$raw_wc={$raw_wc},\$standard_words={$standard_words},\$eq_words={$eq_words}\n";
 if ($check->thereAreErrors()) {
     $err_json = $check->getErrorsJSON();
 } else {
     $err_json = '';
 }
 echo "--- (child {$my_pid}) : sid={$sid} --- \$tm_match_type={$tm_match_type}, \$fast_match_type={$fast_match_type}, \$new_match_type={$new_match_type}, \$equivalentWordMapping[\$new_match_type]=" . $equivalentWordMapping[$new_match_type] . ", \$raw_wc={$raw_wc},\$standard_words={$standard_words},\$eq_words={$eq_words}\n";
 $tm_data = array();
 $tm_data['id_job'] = $jid;
 $tm_data['id_segment'] = $sid;
 $tm_data['suggestions_array'] = $suggestion_json;
 $tm_data['suggestion'] = $suggestion;
 $tm_data['suggestion_match'] = $suggestion_match;