public async Task <RawMachineOcr> Save(RawMachineOcr raw)
        {
            // ReSharper disable once MethodHasAsyncOverload
            var result = _context.RawMachineOcrs.Add(raw.ToModel());
            await _context.SaveChangesAsync();

            return(result.Entity.ToBusinessModel());
        }
        private ConsolidatedMachineAddressableOcr CreateAddressableMachineOcr(RawMachineOcr rawMachineOcr)
        {
            var consolidated = _spatialTextConsolidator.Consolidate(rawMachineOcr.Texts).Select(x => new AddressableSpatialText(x.Text, x.Area));

            var consolidatedMachineOcr = new ConsolidatedMachineAddressableOcr(
                rawMachineOcr.Language, rawMachineOcr.Provider,
                ConsolidationMode.Default,
                consolidated
                )
            {
                RawMachineOcrId = rawMachineOcr.Id !.Value,
                ForImage        = rawMachineOcr.ForImage
            };

            return(consolidatedMachineOcr);
        }
        public async Task <ConsolidatedMachineAddressableOcr> MachineOcrImage(ImageReference reference, Stream content)
        {
            var(texts, language) = await _ocr.Ocr(content);

            var spatialTexts = texts as ISpatialText[] ?? texts.ToArray();

            var rawMachineOcr = new RawMachineOcr(language, MachineOcrProvider.Google, DateTime.UtcNow, spatialTexts)
            {
                ForImage = reference.Id
            };

            rawMachineOcr = await _machineOcrRepository.Save(rawMachineOcr);

            var consolidated = CreateAddressableMachineOcr(rawMachineOcr);

            return(await _machineOcrRepository.Save(consolidated));
        }