private List <Command> BuildCommands() { var cmds = new List <Command>(); // Add and retain the supported cognitive service options so we can build out the specific options for each one var cvCmd = new Command("-cv", "Use the Computer Vision Cognitive Service"); cvCmd.AddAlias($"--{cvName}"); cvCmd.AddOption(new Option <FileInfo>(new string[] { "-f", "--filename" }, "File to read as input for the operation")); cvCmd.Handler = CommandHandler.Create <ComputerVisionOptions>(async options => { var handler = new ComputerVisionHandler(options); var result = await handler.ExecuteAsync(); return(result ? 0 : 1); }); cmds.Add(cvCmd); var taCmd = new Command("-ta", "Use the Text Analytics Cognitive Service"); taCmd.AddAlias($"--{taName}"); taCmd.AddOption(new Option <bool>(new string[] { "-sa", "--sentiment-analysis" }, () => { return(true); }, "Perform sentiment analysis")); taCmd.AddOption(new Option <bool>(new string[] { "-ka", "--keyphrase-analysis" }, () => { return(false); }, "Perform keyphrase analysis")); taCmd.AddOption(new Option <bool>(new string[] { "-ld", "--language-detection" }, () => { return(false); }, "Perform language detection")); taCmd.AddOption(new Option <string>(new string[] { "-txt", "--text-to-analyse" }, "The text to analyse")); taCmd.AddOption(new Option <FileInfo>(new string[] { "-f", "--filename" }, "File to read as input for the operation")); taCmd.Handler = CommandHandler.Create <TextAnalyticsOptions>(async options => { var handler = new TextAnalyticHandler(options); var result = await handler.ExecuteAsync(); return(result ? 0 : 1); }); cmds.Add(taCmd); return(cmds); }
public static string Run( [QueueTrigger("imagestoanalyze", Connection = StorageConnectionString)] string blobNameInQueue, [Blob("images/{queueTrigger}", FileAccess.Read, Connection = StorageConnectionString)] Stream blob, TraceWriter log) { var result = new JObject { { "file", blobNameInQueue } }; log.Info("Started ImageAnalyzer function."); var computerVisionApiKey = CloudConfigurationManager.GetSetting("ComputerVisionApiKey"); using (blob) { log.Info($"Starting computer vision analysis for {blobNameInQueue}..."); byte[] image = ReadStream(blob); var computerVision = new ComputerVisionHandler(computerVisionApiKey); var analysisResult = computerVision.AnalyzeImage(image).Result; result.Add("computer vision", analysisResult); log.Info($"Completed computer vision analysis for {blobNameInQueue}."); } log.Info($"ImageAnalyzer completed for {blobNameInQueue}."); return(result.ToString(Formatting.Indented)); }