private static async Task <AnnotatedPage> CombineMetadata(OcrResult ocr, OcrResult hw, AnalysisResult vis, EntityLink[] cia, ImageReference img) { // The handwriting result also included OCR text but OCR will produce better results on typed documents // so take the result that produces the most text. Consider combining them by region to take the best of each. var result = hw.Text.Length > ocr.Text.Length ? ocr : hw; // create metadata for the vision caption and tags var captionLines = vis.Description.Captions.Select(caption => new lineResult() { words = caption .Text .Split(' ') .Select(word => new WordResult() { text = word }) .ToArray() }); var tagLines = new[] { new lineResult() { words = new[] { "(" } .Concat(vis.Tags.Select(t => t.Name)) .Concat(new[] { ")" }) .Select(t => new WordResult() { text = t }).ToArray() } }; var newResult = new OcrResult() { lines = result .lines .Concat(captionLines) .Concat(tagLines).ToArray() }; // rotate the image if needed var pageImg = ocr.Orientation == "Up" || ocr.Orientation == "NotDetected" ? img : await img.GetImage().Rotate(ocr.Orientation).UploadMedia(blobContainer); // TODO: merge annotations for Linked Entities and Cryptonyms return(new AnnotatedPage(newResult, pageImg)); }