def _setup_with_memories(self): a = self.mmt.api.create_memory('A') b = self.mmt.api.create_memory('B', owner=self.USER_1) c = self.mmt.api.create_memory('B', owner=self.USER_2) self.assertNotIn('owner', a) self.assertEqual(self.USER_1, b['owner']) self.assertEqual(self.USER_2, c['owner']) self.mmt.import_corpus(compact=CompactCorpus(os.path.join(RES_FOLDER, 'Memory.A.cpt')).path, memory=a['id']) self.mmt.import_corpus(compact=CompactCorpus(os.path.join(RES_FOLDER, 'Memory.B.cpt')).path, memory=b['id']) self.mmt.import_corpus(compact=CompactCorpus(os.path.join(RES_FOLDER, 'Memory.C.cpt')).path, memory=c['id'])
def test_add_with_all_language_combinations(self): memories = {} for source, target in [('en', 'de'), ('en', 'fr'), ('en', 'it'), ('en', 'es'), ('en', 'zh')]: corpus = CompactCorpus(os.path.join(RES_FOLDER, 'Memory.%s__%s.cpt' % (source, target))) memory = self.mmt.api.create_memory('Memory.%s__%s' % (source, target)) job = None with corpus.reader() as reader: for s, t, sentence, translation in reader: job = self.mmt.api.append_to_memory(s, t, memory['id'], sentence, translation) if job is not None: self.mmt.wait_job(job) memories['%s_%s' % (source, target)] = memory self._verify_index_integrity(memories)
def test_import_with_all_language_combinations(self): memories = {} for source, target in [('en', 'de'), ('en', 'fr'), ('en', 'it'), ('en', 'es'), ('en', 'zh')]: corpus = CompactCorpus(os.path.join(RES_FOLDER, 'Memory.%s__%s.cpt' % (source, target))) memory = self.mmt.import_corpus(compact=corpus.path) memories['%s_%s' % (source, target)] = memory self._verify_index_integrity(memories)
def test_updating_from_scratch_memory(self): corpus = CompactCorpus(os.path.join(RES_FOLDER, 'Memory.en__it.cpt')) self.mmt.import_corpus(compact=corpus.path) self.assertEqual(self.mmt.get_channels(), ModernMT.Channels(7, 0)) self.mmt.stop() shutil.rmtree(self.mmt.memory.path) self.mmt.start() self.assertEqual(self.mmt.get_channels(), ModernMT.Channels(7, 0)) self._verify_index_integrity()
def _setup_with_contributions(self): a = self.mmt.api.create_memory('A') b = self.mmt.api.create_memory('B', owner=self.USER_1) c = self.mmt.api.create_memory('B', owner=self.USER_2) self.assertNotIn('owner', a) self.assertEqual(self.USER_1, b['owner']) self.assertEqual(self.USER_2, c['owner']) with CompactCorpus(os.path.join(RES_FOLDER, 'Memory.A.cpt')).reader() as reader: for s, t, sentence, translation in reader: self.mmt.add_contributions(s, t, [(sentence, translation)], memory=1) with CompactCorpus(os.path.join(RES_FOLDER, 'Memory.B.cpt')).reader() as reader: for s, t, sentence, translation in reader: self.mmt.add_contributions(s, t, [(sentence, translation)], memory=2) with CompactCorpus(os.path.join(RES_FOLDER, 'Memory.C.cpt')).reader() as reader: for s, t, sentence, translation in reader: self.mmt.add_contributions(s, t, [(sentence, translation)], memory=3)
def test_upload_domain(self): corpus = CompactCorpus(os.path.join(RES_FOLDER, 'Memory.en__it.cpt')) self.mmt.import_corpus(compact=corpus.path) self.assertEqual(self.mmt.get_channels(), ModernMT.Channels(7, 0)) self._verify_index_integrity()