private async Task OnNamedEntityRecognize() { try { resBosonNamedEntity = await BosonAIHelper.NamedEntityRecognize(textInput.Text.Trim()); if (resBosonNamedEntity.entity.Count > 0) { for (int i = 0; i <= resBosonNamedEntity.entity.Count - 1; i++) { int nStart = Convert.ToInt32(resBosonNamedEntity.entity[i][0]); int nEnd = Convert.ToInt32(resBosonNamedEntity.entity[i][1]); List <string> list = resBosonNamedEntity.word.Skip(nStart).Take(nEnd - nStart).ToList(); string strEntity = ""; foreach (var item in list) { strEntity += item; } NLPWord nlp = new NLPWord { word = strEntity, width = strEntity.Length * 20, bgcolor = NameEntityHelper.GetNameEntityColor_Boson(resBosonNamedEntity.entity[i][2]) }; NamedEntityItems.Add(nlp); } } } catch { } }
private async void OnBosonAINamedEntityRecognize(object sender, RoutedEventArgs e) { animationView.Visibility = Visibility.Visible; try { resBoson = await BosonAIHelper.NamedEntityRecognize(textInput.Text.Trim()); if (resBoson.entity.Count > 0) { SampleItems.Clear(); for (int i = 0; i <= resBoson.entity.Count - 1; i++) { int nStart = Convert.ToInt32(resBoson.entity[i][0]); int nEnd = Convert.ToInt32(resBoson.entity[i][1]); List <string> list = resBoson.word.Skip(nStart).Take(nEnd - nStart).ToList(); string strEntity = ""; foreach (var item in list) { strEntity += item; } NLPWord nlp = new NLPWord { word = strEntity, width = strEntity.Length * 20, bgcolor = NameEntityHelper.GetNameEntityColor_Boson(resBoson.entity[i][2]) }; SampleItems.Add(nlp); } } } catch { } animationView.Visibility = Visibility.Collapsed; }
private async Task GetTencentAIResponse() { try { resTencentPosTag = await TencentAIHelper.WordPositionTagging(textInput.Text.Trim()); if (resTencentPosTag != null && resTencentPosTag.ret == 0 && resTencentPosTag.msg == "ok") { SegTagItems.Clear(); listBaseTokens = resTencentPosTag.data.base_tokens; listMixTokens = resTencentPosTag.data.mix_tokens; } resTencentProperNouns = await TencentAIHelper.WordProperNouns(textInput.Text.Trim()); if (resTencentProperNouns != null && resTencentProperNouns.ret == 0 && resTencentProperNouns.msg == "ok") { NamedEntityItems.Clear(); foreach (var item in resTencentProperNouns.data.ner_tokens) { NLPWord nlp = new NLPWord { word = item.word, width = item.length * 20, bgcolor = NameEntityHelper.GetNameEntityColor_Tencent(item.types[0].ToString()) }; NamedEntityItems.Add(nlp); } } resTencentSynonym = await TencentAIHelper.WordSynonym(textInput.Text.Trim()); if (resTencentSynonym != null && resTencentSynonym.ret == 0 && resTencentSynonym.msg == "ok") { SuggestItems.Clear(); foreach (var item in resTencentSynonym.data.syn_tokens) { NLPWord nlp = new NLPWord { word = item.ori_word.word, width = item.ori_word.length * 20, bgcolor = "#9acd32" }; SuggestItems.Add(nlp); foreach (var iitem in item.syn_words) { string strWeight = (Convert.ToInt32(iitem.weight * 100)).ToString(); NLPWord inlp = new NLPWord { word = iitem.word + "(" + strWeight + ")", //width = item.ori_word.length * 20, bgcolor = "#99CC67" }; SuggestItems.Add(inlp); } } } resTencentComponent = await TencentAIHelper.WordComponent(textInput.Text.Trim()); if (resTencentComponent != null && resTencentComponent.ret == 0 && resTencentComponent.msg == "ok") { sliderTencentClassify.Value = resTencentComponent.data.intent + 0.5; } else if (resTencentComponent != null && resTencentComponent.ret == 16393) { sliderTencentClassify.Value = 0.5; } resTencentEmotionPolar = await TencentAIHelper.WordEmotionPolar(textInput.Text.Trim()); if (resTencentEmotionPolar != null && resTencentEmotionPolar.ret == 0 && resTencentEmotionPolar.msg == "ok") { double positive = 0.0, negtive = 0.0; if (resTencentEmotionPolar.data.polar == 1) { positive = 1; negtive = 0; } else if (resTencentEmotionPolar.data.polar == -1) { positive = 0; negtive = 1; } else if (resTencentEmotionPolar.data.polar == 0) { positive = 1; negtive = 1; } if ((Application.Current as App).strCurrentLanguage.ToLower().Equals("zh-cn")) { // Create a new chart data point for each value you want in the PieSeries var sliceOne = new ChartDataModel { Value = positive, Title = "正面" }; var sliceTwo = new ChartDataModel { Value = negtive, Title = "负面" }; // Add those items to the list chartItems.Add(sliceOne); chartItems.Add(sliceTwo); } else { // Create a new chart data point for each value you want in the PieSeries var sliceOne = new ChartDataModel { Value = positive, Title = "Positive" }; var sliceTwo = new ChartDataModel { Value = negtive, Title = "Negtive" }; // Add those items to the list chartItems.Add(sliceOne); chartItems.Add(sliceTwo); } MyDoughnutSeries.ItemsSource = chartItems; } TipServices.TipRecognizeSucceed(); } catch { if (resTencentPosTag.ret < 0) { TipServices.TipSystemError(); } else { TipServices.TipRecognizeFailed(); } } }