Last active
June 12, 2020 17:28
-
-
Save anuraj/5d8db30e489b84b14a9add1eefe32086 to your computer and use it in GitHub Desktop.
Extract Key Phrases using Text Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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