Beispiel #1
0
        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;
        }
Beispiel #3
0
        private async Task OnSegTag()
        {
            resBosonSegTag = await BosonAIHelper.WordSegAndTag(textInput.Text.Trim());

            if (resBosonSegTag != null && resBosonSegTag.tag.Count > 0)
            {
                for (int i = 0; i <= resBosonSegTag.tag.Count - 1; i++)
                {
                    NLPWord nlp = new NLPWord
                    {
                        word    = resBosonSegTag.word[i],
                        width   = resBosonSegTag.word[i].Length * 20,
                        bgcolor = PosTagHelper.GetPosColor_Boson(resBosonSegTag.tag[i])
                    };
                    SegTagItems.Add(nlp);
                }
            }
        }
Beispiel #4
0
        private async void OnMixTokens(object sender, RoutedEventArgs e)
        {
            animationView.Visibility = Visibility.Visible;
            ResetAll();
            await GetTencentAIResponse();

            listMixTokens.ForEach((x) =>
            {
                NLPWord nlp = new NLPWord
                {
                    word    = x.word,
                    width   = x.length * 20,
                    bgcolor = PosTagHelper.GetPosColor_Tencent(x.pos_code.ToString())
                };
                SegTagItems.Add(nlp);
            });
            animationView.Visibility = Visibility.Collapsed;
        }
Beispiel #5
0
        private async Task OnGetSuggest()
        {
            List <string> list = await BosonAIHelper.GetSuggest(textInput.Text.Trim());

            if (list != null && list.Count > 0)
            {
                var brush = (SolidColorBrush)Application.Current.Resources["SystemControlHighlightListAccentLowBrush"];

                for (int i = 0; i <= list.Count - 1; i++)
                {
                    string[] arr      = list[i].Split(',');
                    int      relative = Convert.ToInt32(Convert.ToDouble(arr[0]) * 100);

                    NLPWord nlp = new NLPWord
                    {
                        word = arr[1] + " (" + relative + ")",
                        //width = resBosonSegTag.word[i].Length * 20,
                        bgcolor = "#99CC67"//brush.Color.ToString()
                    };
                    SuggestItems.Add(nlp);
                }
            }
        }
Beispiel #6
0
        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();
                }
            }
        }