예제 #1
0
        private static void AddSentimentAnalysisSkill(ref Index index, ref Indexer indexer, ref Skillset skillset)
        {
            if (index.Fields.Any(f => f.Name == "sentiment"))
            {
                return;
            }

            var sentimentField = new Field("sentiment", DataType.Double)
            {
                IsSortable   = true,
                IsFilterable = true
            };

            index.Fields.Add(sentimentField);
            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping("document/sentiment", "sentiment").GetAwaiter().GetResult());
            skillset.Skills.Add(new SentimentSkill
            {
                Context             = "/document",
                Description         = "Sentiment analysis skill",
                DefaultLanguageCode = SentimentSkillLanguage.En,
                Inputs = new List <InputFieldMappingEntry> {
                    new InputFieldMappingEntry("text", "/document/text")
                },
                Outputs = new List <OutputFieldMappingEntry> {
                    new OutputFieldMappingEntry("score", "sentiment")
                }
            });
        }
예제 #2
0
        private static void AddCustomSummarizerSkill(ref Index index, ref Indexer indexer, ref Skillset skillset, FunctionAppConfig config)
        {
            var targetField = "summary";
            var headers     = new Dictionary <string, string>
            {
                { "Content-Type", "application/json" }
            };

            index.Fields.Add(new Field(targetField, AnalyzerName.StandardLucene));
            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/{targetField}", targetField).GetAwaiter().GetResult());

            // Create the custom translate skill
            skillset.Skills.Add(new WebApiSkill
            {
                Description = "Custom summarization skill",
                Context     = "/document",
                Uri         = $"{config.Url}/api/Summarize?code={config.DefaultHostKey}",
                HttpMethod  = "POST",
                //HttpHeaders = new WebApiHttpHeaders(headers),
                BatchSize = 1,
                Inputs    = new List <InputFieldMappingEntry>
                {
                    new InputFieldMappingEntry("text", "/document/textTranslated")
                },
                Outputs = new List <OutputFieldMappingEntry>
                {
                    new OutputFieldMappingEntry("summaryText", targetField)
                }
            });
        }
예제 #3
0
        private static void AddUserInfoToIndex(ref Index index, ref Indexer indexer)
        {
            var analyzer = AnalyzerName.StandardLucene;

            // Create a new index fields for userName and userLocation
            index.Fields.Add(new Field("userName", analyzer));
            index.Fields.Add(new Field("userLocation", analyzer));

            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping("/document/user/name", "userName").GetAwaiter().GetResult());
            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping("/document/user/location", "userLocation").GetAwaiter().GetResult());
        }
예제 #4
0
        private static void AddCustomTranslateSkill(ref Index index, ref Indexer indexer, ref Skillset skillset, FunctionAppConfig config)
        {
            var targetField = "textTranslated";
            var headers     = new Dictionary <string, string>
            {
                { "Content-Type", "application/json" }
            };

            index.Fields.Add(new Field(targetField, AnalyzerName.StandardLucene));
            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/{targetField}", targetField).GetAwaiter().GetResult());

            // Create the custom translate skill
            skillset.Skills.Add(new WebApiSkill
            {
                Description = "Custom translator skill",
                Context     = "/document",
                Uri         = $"{config.Url}/api/Translate?code={config.DefaultHostKey}",
                HttpMethod  = "POST",
                //HttpHeaders = new WebApiHttpHeaders(headers),
                BatchSize = 1,
                Inputs    = new List <InputFieldMappingEntry>
                {
                    new InputFieldMappingEntry("text", "/document/text"),
                    new InputFieldMappingEntry("language", "/document/Language")
                },
                Outputs = new List <OutputFieldMappingEntry>
                {
                    new OutputFieldMappingEntry("text", targetField)
                }
            });

            // Update all the other skills, except for the LanguageDetectionSkill, to use the new textTranslated field.
            foreach (var skill in skillset.Skills)
            {
                var type     = skill.GetType();
                var typeName = type.Name;

                if (typeName != "WebApiSkill" && typeName != "LanguageDetectionSkill")
                {
                    foreach (var input in skill.Inputs)
                    {
                        if (input.Source == "/document/text")
                        {
                            input.Source = $"/document/{targetField}";
                        }
                    }
                }
            }
        }
예제 #5
0
        private static void AddCustomAnomalyDetectorSkill(ref Index index, ref Indexer indexer, ref Skillset skillset, AppConfig config)
        {
            var headers = new Dictionary <string, string>
            {
                { "Content-Type", "application/json" }
            };

            var anomalyFields = new List <Field>
            {
                new Field($"isAnomaly", DataType.Boolean),
                new Field($"isPositiveAnomaly", DataType.Boolean),
                new Field($"isNegativeAnomaly", DataType.Boolean),
                new Field($"expectedValue", DataType.Double),
                new Field($"upperMargin", DataType.Double),
                new Field($"lowerMargin", DataType.Double)
            };

            index.Fields.Add(new Field("engineTemperatureAnalysis", DataType.Complex, anomalyFields));

            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/engineTemperatureAnalysis", "engineTemperatureAnalysis").GetAwaiter().GetResult());

            // Create the custom translate skill
            skillset.Skills.Add(new WebApiSkill
            {
                Description = "Custom Anomaly Detector skill",
                Context     = "/document",
                Uri         = $"{config.FunctionApp.Url}/api/DetectAnomalies?code={config.FunctionApp.DefaultHostKey}",
                HttpMethod  = "POST",
                //HttpHeaders = new WebApiHttpHeaders(), // This is broken in the SDK, so handle by sending JSON directly to Rest API.
                BatchSize = 1,
                Inputs    = new List <InputFieldMappingEntry>
                {
                    new InputFieldMappingEntry("timestamp", "/document/timestamp"),
                    new InputFieldMappingEntry("engineTemperature", "/document/engineTemperature")
                },
                Outputs = new List <OutputFieldMappingEntry>
                {
                    new OutputFieldMappingEntry("anomalyResult", "engineTemperatureAnalysis")
                }
            });
        }
예제 #6
0
        private static void AddCustomFormRecognizerSkill(ref Index index, ref Indexer indexer, ref Skillset skillset, AppConfig config, string modelId)
        {
            var headers = new Dictionary <string, string>
            {
                { "Content-Type", "application/json" }
            };

            index.Fields.Add(new Field($"formHeight", DataType.Int32));
            index.Fields.Add(new Field($"formWidth", DataType.Int32));
            index.Fields.Add(new Field($"formKeyValuePairs", DataType.Collection(DataType.String)));
            index.Fields.Add(new Field($"formColumns", DataType.Collection(DataType.String)));
            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/formHeight", "formHeight").GetAwaiter().GetResult());
            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/formWidth", "formWidth").GetAwaiter().GetResult());
            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/formKeyValuePairs", "formKeyValuePairs").GetAwaiter().GetResult());
            indexer.OutputFieldMappings.Add(CognitiveSearchHelper.CreateFieldMapping($"/document/formColumns", "formColumns").GetAwaiter().GetResult());

            // Create the custom translate skill
            skillset.Skills.Add(new WebApiSkill
            {
                Description = "Custom Form Recognizer skill",
                Context     = "/document",
                Uri         = $"{config.FunctionApp.Url}/api/AnalyzeForm?code={config.FunctionApp.DefaultHostKey}&modelId={modelId}",
                HttpMethod  = "POST",
                //HttpHeaders = new WebApiHttpHeaders(), // This is broken in the SDK, so handle by sending JSON directly to Rest API.
                BatchSize = 1,
                Inputs    = new List <InputFieldMappingEntry>
                {
                    new InputFieldMappingEntry("contentType", "/document/fileContentType"),
                    new InputFieldMappingEntry("storageUri", "/document/storageUri"),
                    new InputFieldMappingEntry("storageSasToken", "/document/sasToken")
                },
                Outputs = new List <OutputFieldMappingEntry>
                {
                    new OutputFieldMappingEntry("formHeight", "formHeight"),
                    new OutputFieldMappingEntry("formWidth", "formWidth"),
                    new OutputFieldMappingEntry("formKeyValuePairs", "formKeyValuePairs"),
                    new OutputFieldMappingEntry("formColumns", "formColumns"),
                }
            });
        }