Problem Statement: Extract key phrases from a sentence or a paragraph.
Solution:
Azure documentation link : What is key phrase extraction in Azure Cognitive Service for Language? - Azure Cognitive Services | Microsoft Learn
(Step-1) In Azure Portal create a 'Language Service' under 'cognitive services'.
(Step-2) Select 'Custom text classification & Custom names entity recognition' as shown above.
(Step-3) Create a service.
(Step-4) When the services is created extract the key & uri:
(Step-5) Use the following C# code, insert the key, URI and a sentence. [I used visual studio and installed all the right packages]. That's it :)
using Azure;
using System;
using Azure.AI.TextAnalytics;
namespace KeyPhraseExtractionExample
{
class Program
{
private static readonly AzureKeyCredential credentials = new AzureKeyCredential(<<INSERT KEY>>);
private static readonly Uri endpoint = new Uri(<<INSERT URI>>);
// Example method for extracting key phrases from text
static void KeyPhraseExtractionExample(TextAnalyticsClient client)
{
try
{
var response = client.ExtractKeyPhrases(<<INSERT SENTENSE>>);
// Printing key phrases
Console.WriteLine("Key phrases:");
foreach (string keyphrase in response.Value)
{
Console.WriteLine($"\t{keyphrase}");
}
}
catch (RequestFailedException e)
{
Console.WriteLine(e);
}
}
static void Main(string[] args)
{
var client = new TextAnalyticsClient(endpoint, credentials);
KeyPhraseExtractionExample(client);
Console.Write("Press any key to exit.");
Console.ReadKey();
}
}
}