public void SearchTranslationUnits_ManySegments_NoBlanks() { TranslationProviderLanguageDirection dir = new TranslationProviderLanguageDirection(provider, engFraLP); Segment[] segments = SegmentParser.Parser.ParseFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LargeFile_English.txt")); // Chunk the segments to simulate Trados splitting up a document Segment[][] chunkedUnits = ChunkArray(segments, 10); Parallel.ForEach(chunkedUnits, new ParallelOptions { MaxDegreeOfParallelism = 5 }, (segmentChunk) => { try { SearchResults[] results = dir.SearchSegments(settings, segmentChunk); for (int i = 0; i < results.Length; i++) { if (!string.IsNullOrWhiteSpace(segmentChunk[i].ToPlain())) { Assert.IsFalse(string.IsNullOrWhiteSpace( results[i].First().MemoryTranslationUnit.TargetSegment.ToPlain())); } } // If an Aggregate Exception is thrown, it's the result of a WebException and likely a timeout // issue. Just ignore it. } catch (AggregateException) { } catch (WebException) { } } ); }
public void SearchTranslationUnits_WithAndWithoutTags_ValidTranslations() { TranslationProviderLanguageDirection dir = new TranslationProviderLanguageDirection(provider, engFraLP); TranslationUnit[] units = new TranslationUnit[] { new TranslationUnit(TestTags.BasicSegment, null), new TranslationUnit(TestTags.TaggedSegment, null) }; SearchResults[] results = dir.SearchTranslationUnits(settings, units); if (results.Length != 2) { Assert.Fail("Expected results, but received none"); } foreach (SearchResults result in results) { if (result[0].MemoryTranslationUnit == null) { Assert.Fail("Expected translation unit, but received none"); } if (result[0].MemoryTranslationUnit.TargetSegment == null) { Assert.Fail("Expected translation segment, but received none"); } } Assert.AreEqual(StringResource.BasicTranslation, results[0][0].MemoryTranslationUnit.TargetSegment.ToString()); Assert.AreEqual(StringResource.TaggedTranslation, results[1][0].MemoryTranslationUnit.TargetSegment.ToString()); }
public void Translate_Masked(string[] sources, bool[] masks, string[] translations, string[] expectedTargets) { // Ensure that the input data are correct Assert.True(sources.Length == masks.Length && sources.Length == expectedTargets.Length); var toTranslate = sources .Zip(masks, (source, mask) => new { source, mask }) .Where(x => x.mask) .Select(x => x.source).ToList(); var translationList = translations.ToList(); string srcLang = "en"; string trgLang = "lv"; // Another check for input data Assert.True(toTranslate.Count == translationList.Count); var mock = new Mocks.MockClient().MockTranslate(toTranslate, translationList, srcLang, trgLang); IClient client = mock.Object; var langPair = new LanguagePair(srcLang, trgLang); var langDir = new TranslationProviderLanguageDirection(langPair, client, null); Segment[] sourceSegments = sources.Select(x => x.ToSegment()).ToArray(); SearchResults[] results = langDir.SearchSegmentsMasked(null, sourceSegments, masks); string[] resultTargets = results .SelectMany(x => x?.Select(elem => elem.TranslationProposal.TargetSegment.ToPlain()) ?? new string[] { null }) .ToArray(); Assert.Equal(expectedTargets, resultTargets); }
public void SearchSegment_PlainString_ValidTranslation() { TranslationProviderLanguageDirection dir = new TranslationProviderLanguageDirection(provider, engFraLP); SearchResults results = dir.SearchSegment(settings, TestTags.BasicSegment); if (results.Count == 0) { Assert.Fail("Expected results, but received none"); } if (results[0].MemoryTranslationUnit == null) { Assert.Fail("Expected translation unit, but received none"); } if (results[0].MemoryTranslationUnit.TargetSegment == null) { Assert.Fail("Expected translation segment, but received none"); } Assert.AreEqual(StringResource.BasicTranslation, results[0].MemoryTranslationUnit.TargetSegment.ToString()); }
public void SearchSegmentsMasked_FirstIgnored_DontTranslateFirst() { var dir = new TranslationProviderLanguageDirection(provider, engFraLP); var results = dir.SearchSegmentsMasked( settings, new Segment[] { TestTags.BasicSegment, TestTags.TaggedSegment }, new bool[] { false, true }); Assert.IsNull(results[0]); if (results[1][0].MemoryTranslationUnit == null) { Assert.Fail("Expected translation unit, but received none"); } if (results[1][0].MemoryTranslationUnit.TargetSegment == null) { Assert.Fail("Expected translation segment, but received none"); } Assert.AreEqual(UTStringResource.TaggedTranslation, results[1][0].MemoryTranslationUnit.TargetSegment.ToString()); }