function TMS($name, $mappings = array()) { $tms = new TMS(); $tms->setModule($name); $tms->load(); return $tms->getValue($mappings); }
public function doAction() { if (empty($this->source_lang)) { $this->result['error'][] = array("code" => -1, "message" => "missing source_lang"); } if (empty($this->target_lang)) { $this->result['error'][] = array("code" => -2, "message" => "missing target_lang"); } if (empty($this->source)) { $this->result['error'][] = array("code" => -3, "message" => "missing source"); } if (empty($this->target)) { $this->result['error'][] = array("code" => -4, "message" => "missing target"); } //$result = deleteToMM($this->source_lang, $this->target_lang, $this->source, $this->target); $tms = new TMS(1); $result = $tms->delete($this->source, $this->target, $this->source_lang, $this->target_lang, $this->id_translator); $this->result['code'] = $result; $this->result['data'] = "OK"; }
public function testRightUrlForTMS() { $expected_String = "http://api.mymemory.translated.net/get?q=This+provision+takes+effect+in+2014.&langpair=en-US%7Cit-IT&de=demo%40matecat.com&mt=1&numres=3&conc=true&mtonly=1"; $config = TMS::getConfigStruct(); $config['get_mt'] = true; $config['mt_only'] = true; $config['segment'] = "This provision takes effect in 2014."; $config['source_lang'] = "en-US"; $config['target_lang'] = "it-IT"; $config['email'] = "*****@*****.**"; $config['id_user'] = null; $config['num_result'] = 3; $config['isConcordance'] = true; $tms = new MUTE_TMS(1); //MyMemory $tms->get($config); $class = new \ReflectionObject($tms); $prop = $class->getProperty('url'); $prop->setAccessible(true); $this->assertEquals($expected_String, $prop->getValue($tms)); }
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; } }
$db->debug = INIT::$DEBUG; $db->connect(); $glossaries = array(array('file' => '140905_Copy of 140825_Glossary_Anti-trust-law Chinese Rev1_V01JH_English-Chinese_Trad.csv', 'source' => "en-US", 'target' => "zh-CN")); foreach ($glossaries as $gloss) { $config = TMS::getConfigStruct(); $config['source_lang'] = $gloss['source']; $config['target_lang'] = $gloss['target']; $config['email'] = "*****@*****.**"; $config['get_mt'] = false; $config['id_user'] = "******"; $config['num_result'] = null; $config['isGlossary'] = true; $fObject = new SplFileObject($gloss['file']); $fObject->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE); $fObject->setCsvControl(",", '"'); $tms = new TMS(1); foreach ($fObject as $k => $row) { if ($test || $skip) { if (!isset($row[1]) || empty($row[1])) { echo "\nFailed at Row: "; print_r($fObject->key() + 1 . "\n"); echo $row[0] . "\n"; // echo $row[ 1 ] . "\n\n"; // sleep(1); continue; } } $config['segment'] = $row[0]; $config['translation'] = $row[1]; $config['tnote'] = isset($row[2]) ? $row[2] : null; if (!$test) {