How to Implement a Subjectivity & Objectivity Analysis API in PHP
Was that comment you just read a fact, or was it an opinion? While the answer to that question isn’t always crystal clear from rhetoric alone, we can certainly determine a writer’s bias based on the words they choose when discussing a certain topic.
Our free-to-use Subjectivity Analysis API makes it easy to quantify the degree to which written text is either subjective or objective (at scale) based on the language used in each input. The API response provides a score ranging from 0.0–1.0, where scores closer to 0.0 indicate subjective writing, and scores closer to 1.0 indicate objective writing.
You can easily take advantage of this API by using the ready-to-run PHP code examples below to structure your API calls. All you need to do is copy & paste, authenticate with a free-tier API key (get one by visiting our website and registering a free account), and you’re ready to get your analysis underway.
To install the client SDK, run the following command:
omposer require cloudmersive/cloudmersive_nlp_api_client
To structure your API call, copy & paste the below code examples and include your free-tier API key:
<?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\SubjectivityAnalysisRequest(); // \Swagger\Client\Model\SubjectivityAnalysisRequest | Input subjectivity analysis request
try {
$result = $apiInstance->analyticsSubjectivity($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AnalyticsApi->analyticsSubjectivity: ', $e->getMessage(), PHP_EOL;
}
?>
Just like that, you’re all done. Easy!