Example #1
0
 public function test_TMS_GET_MATCHES_Struct()
 {
     $mt = new MUTE_MT(2);
     $urls = parse_url($mt->fakeUrl);
     parse_str($urls['query']);
     /** @var $q string  */
     $text = $q;
     $source = "en-US";
     $target = "it-IT";
     $key = "";
     $mt_result = $mt->get($text, $source, $target, $key);
     $mt_match = $mt_result->translatedText;
     $penalty = $mt->getPenalty();
     $mt_score = 100 - $penalty;
     $mt_score .= "%";
     $mt_match_res = new TMS_GET_MATCHES($text, $mt_match, $mt_score, "MT-" . $mt->getName(), date("Y-m-d"));
     $mt_res = $mt_match_res->get_as_array();
     $mt_res['sentence_confidence'] = $mt_result->sentence_confidence;
     //can be null
     $this->assertArrayHasKey('id', $mt_res);
     $this->assertArrayHasKey('raw_segment', $mt_res);
     $this->assertArrayHasKey('segment', $mt_res);
     $this->assertArrayHasKey('translation', $mt_res);
     $this->assertArrayHasKey('raw_translation', $mt_res);
     $this->assertArrayHasKey('quality', $mt_res);
     $this->assertArrayHasKey('reference', $mt_res);
     $this->assertArrayHasKey('usage_count', $mt_res);
     $this->assertArrayHasKey('subject', $mt_res);
     $this->assertArrayHasKey('created_by', $mt_res);
     $this->assertArrayHasKey('last_updated_by', $mt_res);
     $this->assertArrayHasKey('create_date', $mt_res);
     $this->assertArrayHasKey('last_update_date', $mt_res);
     $this->assertArrayHasKey('match', $mt_res);
     $this->assertArrayHasKey('sentence_confidence', $mt_res);
     $this->assertEquals('50.35047642150528', $mt_res['sentence_confidence']);
     $this->assertEquals('MT-FBK Legal (EN->IT) - Ad.', $mt_res['created_by']);
     $this->assertEquals("congruente con l'approccio coordinato il distretti di Tesoreria, Labor, e Health e Human Services sta svolgendo in sviluppo delle normative e altre istruzioni sotto il economiche Care Act, la notifica anche sollecita l'immissione su come le tre Reparti deve interpretare ed applicare i privilegi Agisci' s disposizioni limitando la possibilità di piani ed emittenti di imporre un periodo di attesa dello stato di copertura per più di 90 giorni a partire dalla 2014.", $mt_res['raw_translation']);
     $this->assertEquals($text, $mt_res['segment']);
     $this->assertEquals($mt_score, '86%');
 }
 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;
     }
 }