How to Implement a Semantic Similarity Comparison API in PHP
The goal of semantic similarity comparison is to identify the degree to which two sentences mean the same thing. There are lots of applications for this type of analysis; it offers independent benefits (e.g., retrieving relevant information from an awkwardly formed request) and also helps improve other fields of NLP analysis (e.g., Sentiment Analysis).
Our Semantic Similarity Comparison API is easy to implement and use within your applications and data analysis projects. Just follow steps to copy and paste ready-to-run PHP code examples (provided below), and authenticate your API calls for free by registering a free account on our website (this will grant you a free-tier API key which you can easily copy and paste into the $config line input).
Let’s first install the client SDK by running the following command:
composer require cloudmersive/cloudmersive_nlp_api_client
And after that, let’s use the below code examples to structure our API calls:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\AnalyticsApi(
new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\SimilarityAnalysisRequest(); // \Swagger\Client\Model\SimilarityAnalysisRequest | Input similarity analysis request
try {
$result = $apiInstance->analyticsSimilarity($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AnalyticsApi->analyticsSimilarity: ', $e->getMessage(), PHP_EOL;
}
?>
And just like that — with minimal code — you’re already done and ready to start analyzing. Enjoy!