private static IEnumerable <IReadOnlyList <string> > GenerateTranslations(ThotSmtParameters parameters, IReadOnlyList <IReadOnlyList <string> > sourceCorpus) { var results = new IReadOnlyList <string> [sourceCorpus.Count]; Parallel.ForEach(Partitioner.Create(0, sourceCorpus.Count), range => { IntPtr smtModelHandle = IntPtr.Zero, decoderHandle = IntPtr.Zero; try { smtModelHandle = Thot.LoadSmtModel(parameters); decoderHandle = Thot.LoadDecoder(smtModelHandle, parameters); for (int i = range.Item1; i < range.Item2; i++) { IReadOnlyList <string> segment = sourceCorpus[i]; results[i] = Thot.DoTranslate(decoderHandle, Thot.decoder_translate, segment, false, segment, (s, t, d) => t); } } finally { if (decoderHandle != IntPtr.Zero) { Thot.decoder_close(decoderHandle); } if (smtModelHandle != IntPtr.Zero) { Thot.smtModel_close(smtModelHandle); } } }); return(results); }
public TranslationResult Translate(IReadOnlyList <string> segment) { CheckDisposed(); return(Thot.DoTranslate(_decoderHandle, Thot.decoder_translate, segment, false, segment, CreateResult)); }