Perform Subjectivity and Objectivity Analysis on Text in Python

Cloudmersive
2 min readJan 14, 2022

Detecting the subjectivity or objectivity of content based on descriptive language is an extremely useful NLP capability, arming you & your applications with the ability to more wisely interpret any given piece of writing. Using the Cloudmersive NLP API v2 iteration /nlp-v2/analytics/subjectivity, you can give your application the ability to find out the extent to which a given text input was objective or subjective based on a variety of cues in the language. A successful API call will provide you with a Subjectivity Score Result equal to or greater than zero.

Your first step to leveraging this API in Python is to install the Python SDK:

pip install cloudmersive-nlp-api-clientfrom __future__ import print_function
import time
import cloudmersive_nlp_api_client
from cloudmersive_nlp_api_client.rest import ApiException
from pprint import pprint

Following this step, you’ll next need to copy in the below snippet to capture your API authorization key (obtained by creating a free account on Cloudmersive.com):

# Configure API key authorization: Apikey configuration = cloudmersive_nlp_api_client.Configuration() configuration.api_key['Apikey'] = 'YOUR_API_KEY'

Once completed, you can finish up by copying in the callback function code snippet below:

# create an instance of the API class
api_instance = cloudmersive_nlp_api_client.AnalyticsApi(cloudmersive_nlp_api_client.ApiClient(configuration))
input = cloudmersive_nlp_api_client.SubjectivityAnalysisRequest() # SubjectivityAnalysisRequest | Input subjectivity analysis request
try:
# Perform Subjectivity and Objectivity Analysis on Text
api_response = api_instance.analytics_subjectivity(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling AnalyticsApi->analytics_subjectivity: %s\n" % e)

--

--

Cloudmersive

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