protected override void Execute(CodeActivityContext context) { string text = Text.Get(context); string apiKey = APIKey.Get(context); string seKey = SecretKey.Get(context); try { var client = new Baidu.Aip.Nlp.Nlp(apiKey, seKey); //修改超时时间 client.Timeout = 60000; //设置可选参数 var options = new Dictionary <string, object> { { "type", type } }; //带参数调用评论观点抽取 string result = client.CommentTag(text, options).ToString(); Result.Set(context, result); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("msgErrorOccurred"), e.Message); } }
protected override void Execute(CodeActivityContext context) { var deviceID = (int)DeviceID.Get(context); var dynamicEnergyThreshold = (Boolean)DynamicEnergyThreshold.Get(context); var energyThresholdValue = (Int32)EnergyThresholdValue.Get(context); if (energyThresholdValue <= 0) { energyThresholdValue = 300; } var pauseThreshold = PauseThreshold.Get(context); if (pauseThreshold <= 0) { pauseThreshold = 0.8; } double?timeoutSeconds = TimeoutSeconds.Get(context); double?phraseTimeLimit = PhraseTimeLimit.Get(context); var inputLanguage = InputLanguage.Get(context); if (inputLanguage.Length < 2) { inputLanguage = "en-US"; } var apiKey = APIKey.Get(context); var username = Username.Get(context); var password = Password.Get(context); var engine = Engine; var filePath = FilePath.Get(context); IEnumerable <object> inputParameters = new object [] { deviceID, filePath, inputLanguage, apiKey, username, password, engine, dynamicEnergyThreshold, energyThresholdValue, pauseThreshold, timeoutSeconds, phraseTimeLimit }; OutputParameters.Set(context, inputParameters); }
protected override void Execute(CodeActivityContext context) { string path = FileName.Get(context); string API_KEY = APIKey.Get(context); string SECRET_KEY = SecretKey.Get(context); img = image.Get(context); try { if (path != null) { by = SaveImage(path); } else { by = ConvertImageToByte(img); } var client = new Ocr(API_KEY, SECRET_KEY); //修改超时时间 client.Timeout = 60000; //参数设置 var options = new Dictionary <string, object> { { "detect_direction", detect_direction.ToString().ToLower() }, { "probability", probability.ToString().ToLower() } }; //带参数调用通用文字识别(高精度版) string result = client.AccurateBasic(by, options).ToString(); Result.Set(context, result); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("msgErrorOccurred"), e.Message); } }
protected override void Execute(CodeActivityContext context) { string text1 = Text1.Get(context); string text2 = Text2.Get(context); string apiKey = APIKey.Get(context); string seKey = SecretKey.Get(context); try { var client = new Baidu.Aip.Nlp.Nlp(apiKey, seKey); //修改超时时间 client.Timeout = 60000; //设置可选参数 var options = new Dictionary <string, object> { { "model", model } }; //带参数调用短文本相似度 string result = client.Simnet(text1, text2, options).ToString(); Result.Set(context, result); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message); } }
protected override void Execute(CodeActivityContext context) { string path = FileName.Get(context); string API_KEY = APIKey.Get(context); string SECRET_KEY = SecretKey.Get(context); img = image.Get(context); try { if (path != null) { by = SaveImage(path); } else { by = ConvertImageToByte(img); } var client = new Ocr(API_KEY, SECRET_KEY); //修改超时时间 client.Timeout = 60000; //参数设置 var options = new Dictionary <string, object> { { "detect_direction", detect_direction.ToString().ToLower() }, { "detect_language", detect_language.ToString().ToLower() } }; //带参数调用网络图片文字识别 string result = client.WebImage(by, options).ToString(); Result.Set(context, result); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message); } }
protected override void Execute(CodeActivityContext context) { string content = Content.Get(context); string apiKey = APIKey.Get(context); string seKey = SecretKey.Get(context); string title = Title.Get(context); int maxlen = MaxLen.Get(context); try { var client = new Baidu.Aip.Nlp.Nlp(apiKey, seKey); // 修改超时时间 client.Timeout = 60000; //设置可选参数 var options = new Dictionary <string, object> { { "title", title } }; //带参数调用新闻摘要接口 string result = client.NewsSummary(content, maxlen, options).ToString(); Result.Set(context, result); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message); } }
protected override void Execute(CodeActivityContext context) { var aPIKey = APIKey.Get(context); Fixer.SetApiKey(aPIKey); var inputCurrency = InputCurrency.Get(context); var outputCurrency = OutputCurrency.Get(context); var rate = Fixer.Rate(inputCurrency, outputCurrency); double dblrate = rate.Convert(1); Rate.Set(context, dblrate); }
protected override void Execute(CodeActivityContext context) { var aPIKey = APIKey.Get(context); Fixer.SetApiKey(aPIKey); var inputAmount = InputAmount.Get(context); var inputCurrency = InputCurrency.Get(context); var outputCurrency = OutputCurrency.Get(context); double outputAmount = Fixer.Convert(inputCurrency, outputCurrency, inputAmount); OutputAmount.Set(context, outputAmount); }
protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { // Inputs var fileName = FileName.Get(context); var jsonConfiguration = JsonConfiguration.Get(context); var apiKey = APIKey.Get(context); var extractorHelper = new ExtractorHelper(); var dtResult = extractorHelper.DoExtraction(apiKey, fileName, jsonConfiguration); // Outputs return((ctx) => { Results.Set(ctx, dtResult); }); }
private async Task <string> ExecuteWithTimeout(AsyncCodeActivityContext context, CancellationToken cancellationToken = default) { /////////////////////////// // Get inputs from context var endpointURL = EndpointURL.Get(context); var apiKey = APIKey.Get(context); var queryData = QueryData.Get(context); /* Build request body (feature dictionary) */ // -> here we assume that the queryData is a json string with keys corresponding to features JArray jsonDataArray = JArray.Parse(queryData); JObject jsonData = (JObject)jsonDataArray.First; // -> we build the feature dictionary just by putting all keys into it var jsonQuery = new JObject(); jsonQuery.Add("features", jsonData); // -> StringContent is required for HTTP POST call var stringContent = new StringContent(jsonQuery.ToString()); /* Initialize HttpClient object */ HttpClient client = new HttpClient(); client.BaseAddress = new Uri(endpointURL); // -> Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // -> Handle authentication var authToken = Encoding.ASCII.GetBytes(apiKey + ":"); // don't forget the colon!! client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken)); /* Post query to DSS API Node */ HttpResponseMessage response = await client.PostAsync(String.Empty, stringContent); response.EnsureSuccessStatusCode(); var resp = await response.Content.ReadAsStringAsync(); // Dispose once all HttpClient calls are complete. This is not necessary if the containing object will be disposed of; for example in this case the HttpClient instance will be disposed automatically when the application terminates so the following call is superfluous. client.Dispose(); // Outputs return(resp); }
protected override void Execute(CodeActivityContext context) { string text = Text.Get(context); string apiKey = APIKey.Get(context); string seKey = SecretKey.Get(context); try { var client = new Baidu.Aip.Nlp.Nlp(apiKey, seKey); //修改超时时间 client.Timeout = 60000; //调用词向量表示 string result = client.WordEmbedding(text).ToString(); Result.Set(context, result); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message); } }
protected override void Execute(CodeActivityContext context) { string text = Text.Get(context); string apiKey = APIKey.Get(context); string seKey = SecretKey.Get(context); try { var client = new Baidu.Aip.Nlp.Nlp(apiKey, seKey); //修改超时时间 client.Timeout = 60000; //调用词法分析 string result = client.Lexer(text).ToString(); Result.Set(context, result); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("msgErrorOccurred"), e.Message); } }
protected override void Execute(NativeActivityContext context) { try { string result = string.Empty; string url = Uri.Get(context); string apiKey = APIKey.Get(context); string[] colValues = Inputs.Get(context); //ThreadInvoker.Instance.RunByUiThread(() => //{ result = Test(colValues, url, apiKey); //}); Result.Set(context, result); } catch (Exception ex) { Log.Logger.LogData(ex.Message + " in activity Cognitive: Microsoft Cognitive API", LogLevel.Error); context.Abort(); } }
protected override void Execute(CodeActivityContext context) { string path = FileName.Get(context); string API_KEY = APIKey.Get(context); string SECRET_KEY = SecretKey.Get(context); img = image.Get(context); try { if (path != null) { by = SaveImage(path); } else { by = ConvertImageToByte(img); } var client = new Ocr(API_KEY, SECRET_KEY); //修改超时时间 client.Timeout = 60000; //参数设置 var options = new Dictionary <string, object> { { "detect_direction", detect_direction.ToString().ToLower() }, { "probability", probability.ToString().ToLower() } }; //带参数调用通用文字识别(高精度版) var json = client.AccurateBasic(by, options).ToString(); Console.WriteLine(json); var result = JsonConvert.DeserializeObject <BaiDuOCRHighPrecisionResult>(json); Result.Set(context, result); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message); } }
Task <HttpResponseMessage> ExecuteAsync(CodeActivityContext context) { MultipartFormDataContent formData = new MultipartFormDataContent(); FileStream fs = null; var basePath = BasePath.Get(context); var request = new HttpRequestMessage() { RequestUri = new Uri(basePath + "/parseDocument"), Method = HttpMethod.Post, }; var apiKey = APIKey.Get(context); request.Headers.Add("X-Auth-Key", apiKey); var documentURL = DocumentURL.Get(context); if (documentURL != null && !documentURL.Equals("")) { formData.Add(new StringContent(documentURL, Encoding.UTF8), "url"); } var template = Template.Get(context); if (template != null && !template.Equals("")) { formData.Add(new StringContent(template, Encoding.UTF8), "template"); } var pdfTextExtraction = PDFTextExtraction.Get(context); if (pdfTextExtraction == PDFTextExtractionType.Fast) { formData.Add(new StringContent("fast", Encoding.UTF8), "pdf_text_extraction"); } else if (pdfTextExtraction == PDFTextExtractionType.Full) { formData.Add(new StringContent("full", Encoding.UTF8), "pdf_text_extraction"); } var userData = UserData.Get(context); if (userData != null && !userData.Equals("")) { formData.Add(new StringContent(userData, Encoding.UTF8), "user_data"); } var userDataSetExternalID = UserDataSetExternalID.Get(context); if (userDataSetExternalID != null && !userDataSetExternalID.Equals("")) { formData.Add(new StringContent(userDataSetExternalID, Encoding.UTF8), "user_data_set_external_id"); } var documentFilename = DocumentFilename.Get(context); var documentBytes = DocumentBytes.Get(context); var documentPath = DocumentPath.Get(context); var documentStream = DocumentStream.Get(context); if (documentBytes != null && documentBytes.Length > 0) { formData.Add(new ByteArrayContent(documentBytes), "document", documentFilename); } else if (documentPath != null && !documentPath.Equals("")) { fs = File.OpenRead(documentPath); formData.Add(new StreamContent(fs), "document", Path.GetFileName(documentPath)); } else if (documentStream != null && documentStream.Length > 0) { formData.Add(new StreamContent(documentStream), "document", documentFilename); } request.Content = formData; request.Properties["RequestTimeout"] = TimeSpan.FromSeconds(600); return(httpClient.SendAsync(request)); }