Perform Semantic Similarity Comparison of Two Strings in C#

Cloudmersive
2 min readFeb 28, 2022

--

Semantic similarity comparisons are a huge help for retrieving information, paraphrasing text, and much more. You can easily take advantage of the Semantic Similarity Comparison iteration of our NLP API in C# using the below code examples from the Cloudmersive API Console to connect.

Before you get started — if you don’t currently have a Cloudmersive API key, head to the Cloudmersive website (Home — Cloudmersive APIs) and make a free account to receive one. You’ll get 800 API calls per month with your free-tier account and zero financial commitments.

If you’re working in .NET, run the below command & copy the following code snippet:

Install-Package Cloudmersive.APIClient.NET.NLP -Version 4.1.0using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.NLP.Api;
using Cloudmersive.APIClient.NET.NLP.Client;
using Cloudmersive.APIClient.NET.NLP.Model;

For .NET Core, use this instead:

Install-Package Cloudmersive.APIClient.NETCore.NLP -Version 2.1.3using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.NLP.Api;
using Cloudmersive.APIClient.NETCore.NLP.Client;
using Cloudmersive.APIClient.NETCore.NLP.Model;

After that, use the below code to call the API:

namespace Example
{
public class AnalyticsSimilarityExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new AnalyticsApi();
var input = new SimilarityAnalysisRequest(); // SimilarityAnalysisRequest | Input similarity analysis request
try
{
// Perform Semantic Similarity Comparison of Two Strings
SimilarityAnalysisResponse result = apiInstance.AnalyticsSimilarity(input);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling AnalyticsApi.AnalyticsSimilarity: " + e.Message );
}
}
}
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet