public async Task TranslateScreen() { var recognizedTextboxes = (await OcrScreenInternal()).ToList(); var textBoxesCount = recognizedTextboxes.Count; _log.LogInformation("Found {Count} textboxes", textBoxesCount); _internalOverlay.Add(recognizedTextboxes.ToArray()); if (textBoxesCount >= 60) { _log.LogWarning("More text boxes than expected: {textBoxesCount}, aborting translation. Probably means that the OCR implementation is bonkers", textBoxesCount); return; } _log.LogInformation("Translating the textboxes"); var originalTexts = recognizedTextboxes.Select(x => x.Text); var translations = (await _translate.Translate(originalTexts, _ocrTranslateOverlayConfiguration.TargetLanguage, _ocrTranslateOverlayConfiguration.SourceLanguage)).ToList(); var asSpatialText = ToSpatialTexts(recognizedTextboxes, translations); var correctedForCaptureArea = asSpatialText.Select(CorrectForCaptureArea).ToList(); _internalOverlay.ClearAll(); _log.LogInformation("Passing translated texts to overlay"); _internalOverlay.Add(correctedForCaptureArea.ToArray()); ShowOverlay(); _log.LogInformation("Showing the complete translation"); }
private async Task <bool> TryUseExisting(DbTranslatedExpression expression, Language language) { var existing = await _exprTranslator.Translate(expression.ExpressionId, language); if (existing != null) { expression.Cefr = existing.Expression.Cefr; expression.ExprType = existing.Expression.ExprType; expression.Words = existing.Words.Select( word => new DbTranslatedWord { Id = word.Word.Id, Cefr = word.Word.Cefr, PartOfSpeech = word.Word.PartOfSpeech, PictureId = word.Word.PictureId, Translation = new DbTranslation { Native = word.Native, Spoken = word.Spoken, AudioId = word.AudioId } }).ToArray(); return(true); } else { return(false); } }
public async Task <MachineTranslation?> MachineTranslate(ConsolidatedMachineAddressableOcr source) { var translated = await _translate.Translate(source.Texts.Select(x => x.Text), "en", source.Language); var basedOnSpatialTexts = ToSpatialTexts(source.Texts.ToList(), translated.ToList()); var machineTranslation = new MachineTranslation("en", basedOnSpatialTexts, MachineTranslationProvider.Deepl); return(await _translationRepository.SaveMachineTranslation(source.Id !.Value, machineTranslation)); }
public async Task <IEnumerable <Translation> > Translate(IEnumerable <string> originals, string?targetLanguage = "en", string?inputLanguage = null) { if (!_configuration.Cache) { return(await _decorated.Translate(originals, targetLanguage, inputLanguage)); } var cached = GetCached(); if (cached != null) { return(cached); } cached = (await _decorated.Translate(originals, targetLanguage, inputLanguage)).ToList(); Cache(cached); return(cached); }
public async Task <IEnumerable <Translate.Translation> > Translate(IEnumerable <string> originals, string?targetLanguage = "en", string?inputLanguage = null) { var originalsAsList = originals.ToList(); var unitUsage = originalsAsList.Sum(x => x.Length); await VerifyQuotaSpace(unitUsage); await UseQuota(unitUsage); return(await _translateImplementation.Translate(originalsAsList, targetLanguage, inputLanguage)); }
private async Task <IDictionary <Guid, TranslatedExpression>?> GetTranslations(Language language, IEnumerable <Guid> expressionIds) { var translations = await Task.WhenAll( expressionIds .Distinct() .Select(id => _translator.Translate(id, language))); if (translations.Any(x => x == null)) { return(default);
public Message Read() { var buffer = new byte[BufferSize]; _serialPort.Read(buffer, 0, buffer.Length); string header = _translator.Translate(buffer); var msg = new Message(header); return(msg); }
private void buttonApply_Click(object sender, EventArgs e) { textBoxRes.Clear(); ITranslate choise_item = factory.GetFactoryItem(selectedItem); output.WriteLine($"{choise_item.ToString()} selected \n"); output.WriteLine(" Set Dictionary to Mobile... \n"); output.WriteLine(" Start translating... \n"); choise_item.Translate("test"); }
private async Task <bool> TryUseExisting(DbTranslatedWord word, Language language) { var existing = await _wordTranslator.Translate(word.Id, language); if (existing != null) { word.Cefr = existing.Word.Cefr; word.PartOfSpeech = existing.Word.PartOfSpeech; word.PictureId = existing.Word.PictureId; word.Translation = new DbTranslation { Native = existing.Native, Spoken = existing.Spoken, AudioId = existing.AudioId }; return(true); } return(false); }
void TranslateWords(Object state) { var dic = state as Dictionary <Object, String>; //ITranslate trs = new BingTranslate(); string[] words = new string[dic.Values.Count]; dic.Values.CopyTo(words, 0); String[] rs = Translate.Translate(words); if (rs == null || rs.Length < 1) { return; } var ts = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < words.Length && i < rs.Length; i++) { String key = words[i].Replace(" ", null); if (!ts.ContainsKey(key) && !String.IsNullOrEmpty(rs[i]) && words[i] != rs[i] && key != rs[i].Replace(" ", null)) { ts.Add(key, rs[i].Replace(" ", null)); } } foreach (var item in dic) { if (!ts.ContainsKey(item.Value) || String.IsNullOrEmpty(ts[item.Value])) { continue; } if (item.Key is IDataTable) { (item.Key as IDataTable).Description = ts[item.Value]; } else if (item.Key is IDataColumn) { (item.Key as IDataColumn).Description = ts[item.Value]; } } }
public async Task <Evaluation> Evaluate(Profile profile, Submit submit) { var chapter = await _chapters.Get(submit.ChapterId) ?? throw new ObjectNotFoundException(typeof(DbChapter), submit.ChapterId); chapter.Validate(); if (submit.PageIndex < 0 || submit.PageIndex >= chapter.Pages !.Length) { throw new ArgumentOutOfRangeException(nameof(submit.PageIndex)); } var page = chapter.Pages[submit.PageIndex]; var expected = await _translator.Translate(page.ExpressionId, profile.Target) ?? throw new ObjectNotFoundException(typeof(TranslatedExpression), page.ExpressionId); var result = _checker.Evaluate(expected.Native, submit.Solution); var evaluation = new Evaluation(result, submit, profile); return(await _stats.Update(evaluation, chapter.Pages.Length)); }
static void Main(string[] args) { Console.WriteLine("Unit1"); SimCorpMobile mobile1 = new SimCorpMobile(id: 1, screen: new OLEDScreen(size: 5, pixels: new Dimensions(1280, 800)), keyboard: new KeyBoardGBoard(layout: Layouts.English, theme: Themes.FeatherLightRed)); mobile1.ShowDescription(); SimCorpMobile mobile2 = new SimCorpMobile(id: 2, screen: new RetinaScreen(), keyboard: new KeyBoardGBoard(layout: Layouts.Ukrainian, theme: Themes.FeatherDarkRed)); mobile2.ShowDescription(); Console.WriteLine(); /////////////////////////////////////////////////// Console.WriteLine("Unit2"); IOutput output = new ConsoleOutput(); FactoryDict factory = new FactoryDict(output: output); output.WriteLine("Select Dictionary (specify index)"); //output.PrintFactory(factory); factory.Print(); int choise_int = 0; if (MakeChoise(out choise_int)) { int ind = choise_int - 1; ITranslate choise_item = factory.GetFactoryItem(ind); output.WriteLine($"{choise_item.ToString()} selected"); output.WriteLine(" Set Dictionary to Mobile..."); output.WriteLine(" Start translating..."); choise_item.Translate("test"); } /////////////////////////////////////////////////// Console.ReadKey(); }
public LProduct GetProduct(string url) { LProduct product = new LProduct(); HtmlDocument doc = new HtmlDocument(); using (HtmlHelper html = new HtmlHelper()) { doc = html.GetDocument(url); } var pagewrap = doc.DocumentNode.SelectSingleNode("//body//div[@class='page-wrap']"); //var pro = pagewrap.SelectSingleNode("//section[@class='content-main']"); var content = pagewrap.ChildNodes["section"].SelectSingleNode("//div[@class='content-main--inner']//div[@class='content--wrapper']//div[@class='content product--details']"); var divDetails = content.SelectSingleNode("//div[@class='product--detail-upper block-group']"); #region images var divImages = divDetails.SelectSingleNode("//div[@class='product--image-container image-slider product--image-zoom']"); var imageMain = divImages.SelectNodes("//div[@class='image-slider--container']//div[@class='image-slider--slide']//div[@class='image--box image-slider--item']//span[@class='image--element']"); List <LeyboldImage> productImages = new List <LeyboldImage>(); foreach (var item in imageMain.Where(x => x.HasAttributes)) { LeyboldImage image = new LeyboldImage(); image.Large = item.Attributes["data-img-large"].Value; image.Small = item.Attributes["data-img-small"].Value; image.Orginal = item.Attributes["data-img-original"].Value; image.Title = item.Attributes["data-alt"].Value; productImages.Add(image); } //var imageThumbnails = divImages.SelectNodes("//div[@class='image-slider--thumbnails-slide']//img"); //List<string> imgs = new List<string>(); //foreach (var item in imageThumbnails) //{ // imgs.Add(item.Attributes["srcset"].Value.Replace(",", "")); //} #endregion #region Title Buyer product.TitleEn = divDetails.SelectSingleNode("//div[@class='product--buybox block']//header[@class='product--header']//div[@class='product--info']//h1") .InnerText.Replace("\n", " ").Replace(" ", " ").Trim(); product.Title = "پمپ وکیوم " + product.TitleEn; product.Property = divDetails.SelectSingleNode("//div[@class='product--buybox block']//header[@class='product--header']//div[@class='product--info']//div[@class='product--properties']").InnerHtml.Replace("\n", "").Trim(); #endregion #region Tabs var divTabs = content.SelectSingleNode("//div[@class='em-tabs']"); //foreach (HtmlTextNode node in textNodes) // node.Text = node.Text.Replace(node.Text, translate.Translate(node.Text).Result); var tabs = divTabs.SelectNodes("div"); foreach (var item in tabs) { if (!string.IsNullOrWhiteSpace(item.InnerHtml.Trim())) { using (HtmlHelper html = new HtmlHelper()) { string tabName = item.Attributes["id"].Value.Replace("\n", "").Trim(); if (tabName.ToLower() == "description") { string text = html.StripHTML(item.InnerText.Trim()).Replace(" ", " "); string[] paraphs = text.Split('\n'); product.Html = "<p>" + translate.Translate(new InputTranslate { Input = text }).Result + "</p>"; product.HtmlEn = "<p>" + string.Join("<p> </p>", paraphs) + "</p>"; } } } } var sssss = divTabs.SelectNodes("//div[@id='downloads']//ul//li//a"); List <ProductCatalog> catalogs = new List <ProductCatalog>(); foreach (var item in sssss) { ProductCatalog catalog = new ProductCatalog(); catalog.File = item.Attributes["href"].Value; catalog.TitleEn = item.InnerText.Replace("\n", " ").Trim(); catalog.Title = translate.Translate(new InputTranslate { Input = catalog.TitleEn }).Result; catalogs.Add(catalog); } #endregion product.URL = url; product.Catalog = catalogs; //List<string> imgss = new List<string>(); //int i = 0; //foreach (var img in imgs) //{ // var _temp = img.Split(' ').Where(x => x.Contains("http")).Distinct(); // imgss.AddRange(_temp); //} product.Images = productImages; product.Keywords = url.Replace("https://www.leyboldproducts.com/products/", "").Replace("/pumps/", "/").Split('/'); product.Category = url.Replace("https://www.leyboldproducts.com/products/", "").Replace("/pumps/", "/").Split('/').FirstOrDefault(); return(product); }