Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_viterbi_alignment(self):
x = viterbi_alignment([1, 2, 1],
[2, 3, 2],
collections.defaultdict(int),
collections.defaultdict(int))
# Viterbi_alignment selects the first token
# if t or a doesn't contain the key.
# This means it returns NULL token
# in such a situation.
self.assertEqual(x, {1: 1, 2: 1, 3: 1})
def symmetrization(es, fs, corpus):
'''
forpus
for translation from fs to es
return
alignment **from fs to es**
'''
f2e_train = ibmmodel2._train(corpus, loop_count=10)
f2e = ibmmodel2.viterbi_alignment(es, fs, *f2e_train).items()
e2f_corpus = list(zip(*reversed(list(zip(*corpus)))))
e2f_train = ibmmodel2._train(e2f_corpus, loop_count=10)
e2f = ibmmodel2.viterbi_alignment(fs, es, *e2f_train).items()
return alignment(es, fs, e2f, f2e)
def symmetrization(es, fs, corpus):
'''
forpus
for translation from fs to es
return
alignment **from fs to es**
'''
f2e_train = ibmmodel2._train(corpus, loop_count=10)
f2e = ibmmodel2.viterbi_alignment(es, fs, *f2e_train).items()
e2f_corpus = list(zip(*reversed(list(zip(*corpus)))))
e2f_train = ibmmodel2._train(e2f_corpus, loop_count=10)
e2f = ibmmodel2.viterbi_alignment(fs, es, *e2f_train).items()
return alignment(es, fs, e2f, f2e)