예제 #1
0
    public function testWrongTM()
    {
        $source_seg = <<<TRG
<g id="1877">31-235</g> <g id="1878">The default PR upper alarm is120.</g>
TRG;
        $target_seg = <<<SRC
<g id="1877"> 31-235 </g><x id="1878"/> L'impostazione predefinita PR IS120 allarme.
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->assertTrue($check->thereAreErrors());
        $this->assertTrue($check->thereAreWarnings());
        $this->assertEquals(count($warnings), 2);
        $this->assertEquals(1000, $warnings[0]->outcome);
        $this->assertCount(2, $errors);
        $this->assertAttributeEquals(1000, 'outcome', $errors[0]);
        $this->assertRegExp('/\\( 1 \\)/', $check->getErrorsJSON());
        $this->assertAttributeEquals(4, 'outcome', $errors[1]);
        $this->assertRegExp('/\\( 1 \\)/', $check->getErrorsJSON());
        $this->setExpectedException('LogicException');
        $normalized = $check->getTrgNormalized();
    }
예제 #2
0
     $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 = '';
     }
 }
 !empty($matches[0]['sentence_confidence']) ? $mt_qe = floatval($matches[0]['sentence_confidence']) : ($mt_qe = null);
 //        _TimeStampMsg ( "--- (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" );
 $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;
 $tm_data['suggestion_source'] = $suggestion_source;
 $tm_data['match_type'] = $new_match_type;
 $tm_data['eq_word_count'] = $eq_words;
예제 #3
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);
 }