Ejemplo n.º 1
0
        public static async Task <KeyPhrasesResult> GetKeyPhrasesAsync(string input, string language = "en")
        {
            KeyPhrasesResult keyPhrasesResult = new KeyPhrasesResult()
            {
                KeyPhrases = Enumerable.Empty <string>()
            };

            if (!string.IsNullOrEmpty(input))
            {
                KeyPhraseBatchResult result = await AnalyticsClient.KeyPhrasesAsync(new MultiLanguageBatchInput(
                                                                                        new List <MultiLanguageInput>()
                {
                    new MultiLanguageInput(language, "0", input)
                }));

                if (result.Documents != null)
                {
                    List <string> phrases = new List <string>();

                    foreach (string keyPhrase in result.Documents[0].KeyPhrases)
                    {
                        phrases.Add(keyPhrase);
                    }

                    keyPhrasesResult.KeyPhrases = phrases;
                }

                if (result.Errors != null)
                {
                    // Just return the empty IEnumerable
                }
            }

            return(keyPhrasesResult);
        }