Skip to content

Instantly share code, notes, and snippets.

@anuraj
Last active June 12, 2020 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anuraj/5d8db30e489b84b14a9add1eefe32086 to your computer and use it in GitHub Desktop.
Save anuraj/5d8db30e489b84b14a9add1eefe32086 to your computer and use it in GitHub Desktop.
Extract Key Phrases using Text Analytics
//Add reference of Azure.AI.TextAnalytics
using Azure;
using Azure.AI.TextAnalytics;
using Microsoft.Azure.CognitiveServices.Search.NewsSearch.Models;
public static async Task<string> GetKeywords(string text)
{
var client = new TextAnalyticsClient(Endpoint, Credentials);
var response = await client.ExtractKeyPhrasesAsync(text);
var tags = new List<string>();
if (response.Value?.Count >= 1)
{
foreach (var keyphrase in response.Value)
{
var tag = keyphrase.Replace(" ", "").Replace("-", "_");
tags.Add($"#{tag}");
}
}
return string.Join(" ", tags);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment