コード例 #1
0
        public static SkillSet <PageImage> CreateCognitiveSkillSet()
        {
            var skillSet = SkillSet <PageImage> .Create("page", page => page.Id);

            // prepare the image
            var resizedImage = skillSet.AddSkill("resized-image",
                                                 page => page.GetImage().ResizeFit(2000, 2000).CorrectOrientation().UploadMedia(blobContainer),
                                                 skillSet.Input);

            // Run OCR on the image using the Vision API
            var cogOcr = skillSet.AddSkill("ocr-result",
                                           imgRef => visionClient.RecognizeTextAsync(imgRef.Url),
                                           resizedImage);

            // extract text from handwriting
            var handwriting = skillSet.AddSkill("ocr-handwriting",
                                                imgRef => visionClient.GetHandwritingTextAsync(imgRef.Url),
                                                resizedImage);

            // Get image descriptions for photos using the computer vision
            var vision = skillSet.AddSkill("computer-vision",
                                           imgRef => visionClient.AnalyzeImageAsync(imgRef.Url, new[] { VisualFeature.Tags, VisualFeature.Description }),
                                           resizedImage);

            // extract entities linked to wikipedia using the Entity Linking Service
            var linkedEntities = skillSet.AddSkill("linked-entities",
                                                   (ocr, hw, vis) => GetLinkedEntitiesAsync(ocr.Text, hw.Text, vis.Description.Captions[0].Text),
                                                   cogOcr, handwriting, vision);

            // combine the data as an annotated document
            var cryptonyms = skillSet.AddSkill("cia-cryptonyms",
                                               ocr => DetectCIACryptonyms(ocr.Text),
                                               cogOcr);

            // combine the data as an annotated page that can be used by the UI
            var pageContent = skillSet.AddSkill("page-metadata",
                                                CombineMetadata,
                                                cogOcr, handwriting, vision, cryptonyms, linkedEntities, resizedImage);

            return(skillSet);
        }