private static WebApiSkill CreateWebApiSkill() { List <InputFieldMappingEntry> inputMappings = new List <InputFieldMappingEntry>(); inputMappings.Add(new InputFieldMappingEntry( name: "name", source: "/document/file_name")); List <OutputFieldMappingEntry> outputMappings = new List <OutputFieldMappingEntry>(); outputMappings.Add(new OutputFieldMappingEntry( name: "greeting", targetName: "greeting")); Dictionary <string, string> headers = new Dictionary <string, string>(); // headers.Add("Accept", "*/*"); // headers.Add("Content-Type", "text/plain"); WebApiSkill webApiSkill = new WebApiSkill( description: "Hello World custom skill", uri: "https://margies7.azurewebsites.net/api/hello-world?code=QJgjMDJ67MEC/D4MEaSranE9LPVH3/kA9aGok7Njwj9/WsnZqxKb6g==", batchSize: 1, context: "/document", inputs: inputMappings, outputs: outputMappings, httpMethod: "POST", httpHeaders: headers ); return(webApiSkill); }
private static WebApiSkill CreateTopTenWordsSkill() { List <InputFieldMappingEntry> inputMappings = new List <InputFieldMappingEntry>(); inputMappings.Add(new InputFieldMappingEntry( name: "text", source: "/document/merged_text")); inputMappings.Add(new InputFieldMappingEntry( name: "languageCode", source: "/document/languageCode")); List <OutputFieldMappingEntry> outputMappings = new List <OutputFieldMappingEntry>(); outputMappings.Add(new OutputFieldMappingEntry( name: "words", targetName: "top_10_words")); Dictionary <string, string> headers = new Dictionary <string, string>(); TimeSpan timeSpan = new TimeSpan(0, 0, 215); WebApiSkill webApiSkill = new WebApiSkill( description: "Top Words skill", uri: "https://margies7.azurewebsites.net/api/tokenizer?code=dcmuJd621t8PhlKtEARg3JXE1RkNnM0ab7xBIkxvwXtWkpFbVOTcKg==", batchSize: 1, timeout: timeSpan, context: "/document", inputs: inputMappings, outputs: outputMappings, httpMethod: "POST", httpHeaders: headers ); return(webApiSkill); }
private static List <Skill> CreateSkills() { OcrSkill ocrSkill = CreateOcrSkill(); MergeSkill mergeSkill = CreateMergeSkill(); LanguageDetectionSkill languageDetectionSkill = CreateLanguageDetectionSkill(); SentimentSkill sentimentSkill = CreateSentimentSkill(); KeyPhraseExtractionSkill keyPhraseSkill = CreateKeyPhraseExtractionSkill(); EntityRecognitionSkill entityRecognitionSkill = CreateEntityRecognitionSkill(); ImageAnalysisSkill imageAnalysisSkill = CreateImageAnalysisSkill(); WebApiSkill webApiSkill = CreateWebApiSkill(); WebApiSkill topTenWordsSkill = CreateTopTenWordsSkill(); List <Skill> skills = new List <Skill>(); skills.Add(ocrSkill); skills.Add(imageAnalysisSkill); skills.Add(mergeSkill); skills.Add(sentimentSkill); skills.Add(keyPhraseSkill); skills.Add(entityRecognitionSkill); skills.Add(webApiSkill); skills.Add(topTenWordsSkill); return(skills); }
private static WebApiSkill CreateCustomSkill() { Console.WriteLine(" - Custom skill"); // inputs List <InputFieldMappingEntry> customInputs = new List <InputFieldMappingEntry>(); customInputs.Add(new InputFieldMappingEntry( name: "text", source: "/document/mergedText")); customInputs.Add(new InputFieldMappingEntry( name: "language", source: "/document/language")); // outputs List <OutputFieldMappingEntry> customOutputs = new List <OutputFieldMappingEntry>(); customOutputs.Add(new OutputFieldMappingEntry( name: "text", targetName: "topWords")); // Create skill WebApiSkill customSkill = new WebApiSkill( name: "get-top-words", description: "custom skill to get top 10 most frequent words.", uri: customSkillUri, context: "/document", inputs: customInputs, outputs: customOutputs); return(customSkill); }
private static void AddCustomTranslateSkill(ref Index index, ref Indexer indexer, ref Skillset skillset, string functionAppUrl, string functionAppKey) { var targetField = "textTranslated"; // Create the custom translate skill var translateSkill = new WebApiSkill { Description = "Custom translator skill", Context = "/document", Uri = $"{functionAppUrl}/api/Translate?code={functionAppKey}", BatchSize = 1, Inputs = new List <InputFieldMappingEntry> { new InputFieldMappingEntry("text", "/document/text"), new InputFieldMappingEntry("language", "/document/language") }, Outputs = new List <OutputFieldMappingEntry> { new OutputFieldMappingEntry("text", targetField) } }; skillset.Skills.Add(translateSkill); // 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}"; } } } } // Create a new index field var sentimentField = new Field { Name = targetField, Type = DataType.String, IsSearchable = true, IsFilterable = true, IsRetrievable = true, IsSortable = true, IsKey = false, Analyzer = AnalyzerName.StandardLucene }; index.Fields.Add(sentimentField); indexer.OutputFieldMappings.Add(CreateFieldMapping($"/document/{targetField}", targetField)); }
private static Skillset CreateTestSkillsetWebApiSkill(bool includeHeader = true) { var skills = new List <Skill>(); var inputs = new List <InputFieldMappingEntry>() { new InputFieldMappingEntry { Name = "text", Source = "/document/text" } }; var outputs = new List <OutputFieldMappingEntry>() { new OutputFieldMappingEntry { Name = "coolResult", TargetName = "myCoolResult" } }; var skill = new WebApiSkill( inputs, outputs, uri: "https://contoso.example.org", name: "mywebapi", description: "A simple web api skill", context: RootPathString) { HttpMethod = "POST", DegreeOfParallelism = 7 }; if (includeHeader) { skill.HttpHeaders = new Dictionary <string, string> { ["x-ms-example"] = "example" }; } skills.Add(skill); return(new Skillset("webapiskillset", "Skillset for testing", skills)); }
public void CreateSkillset() { IConfigurationRoot configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json").Build(); var inputMappings = new List <InputFieldMappingEntry> { new InputFieldMappingEntry( name: "text", source: "/document/Content") }; var outputMappings = new List <OutputFieldMappingEntry> { new OutputFieldMappingEntry(name: "persons", "Persons"), new OutputFieldMappingEntry(name: "locations", "Locations"), new OutputFieldMappingEntry(name: "urls", "Urls"), }; var entityCategory = new List <EntityCategory>() { EntityCategory.Location, EntityCategory.Person, EntityCategory.Url }; var entityRecognitionSkill = new EntityRecognitionSkill( description: "Recognize organizations", context: "/document", inputs: inputMappings, outputs: outputMappings, categories: entityCategory, defaultLanguageCode: EntityRecognitionSkillLanguage.En); var keyPhraseSkill = new KeyPhraseExtractionSkill( name: "keyphraseextractionskill", description: "Key Phrase Extraction Skill", context: "/document", inputs: new[] { new InputFieldMappingEntry("text", "/document/Content") }, outputs: new[] { new OutputFieldMappingEntry("keyPhrases", "KeyPhrases") } ); var imageSkill = new ImageAnalysisSkill( name: "imageanalysisskill", context: "/document/normalized_images/*", inputs: new[] { new InputFieldMappingEntry("image", "/document/normalized_images/*") }, outputs: new[] { new OutputFieldMappingEntry("/document/normalized_images/*/tags/*", "Tags"), new OutputFieldMappingEntry("/document/normalized_images/*/description", "Description") } ); var ocrSkill = new OcrSkill( name: "ocrskill", context: "/document/normalized_images/*", inputs: new[] { new InputFieldMappingEntry("image", "/document/normalized_images/*") }, outputs: new[] { new OutputFieldMappingEntry("text", "OcrText") } ); var mergeTextSkill = new MergeSkill( name: "mergeTextSkill", context: "/document", inputs: new[] { new InputFieldMappingEntry("text", "/document/Content"), new InputFieldMappingEntry("itemsToInsert", "/document/normalized_images/*/OcrText") }, outputs: new[] { new OutputFieldMappingEntry("mergedText", "MergedText") } ); /*Microsoft.Rest.Azure.CloudException : One or more skills are invalid. Details: Skill 'mergeTextSkill' is not allowed to have recursively defined inputs */ //public SentimentSkill(IList<InputFieldMappingEntry> inputs, IList<OutputFieldMappingEntry> outputs, string name = null, string description = null, string context = null, SentimentSkillLanguage? defaultLanguageCode = null); var sentimentskill = new SentimentSkill( name: "sentimentskill", description: "Our favorite Sentiment Skill", context: "/document", defaultLanguageCode: SentimentSkillLanguage.En, inputs: new[] { new InputFieldMappingEntry("text", "/document/Content") }, outputs: new[] { new OutputFieldMappingEntry("score", "Sentiment") } ); var commonWordsSkill = new WebApiSkill( name: "commonWordsSkill", description: "No description for you", batchSize: 1, httpMethod: "POST", uri: configuration["CommonWordsApiUrl"], context: "/document", inputs: new[] { new InputFieldMappingEntry("text", "/document/MergedText") }, outputs: new[] { new OutputFieldMappingEntry("words", "CommonWords") } ); var ss = new Skillset("fastracoontravelskillset", "self describing", skills: new List <Skill>() { entityRecognitionSkill, keyPhraseSkill, sentimentskill, ocrSkill, mergeTextSkill, commonWordsSkill }, cognitiveServices: new CognitiveServicesByKey(configuration["CogServicesKey"]) ); using (var serviceClient = CreateSearchServiceClient(configuration)) { serviceClient.Skillsets.CreateOrUpdate(ss); } }