How to Perform Subjectivity and Objectivity Analysis on Text with Java

Cloudmersive
1 min readApr 6, 2022

--

We all have different opinions on different subjects, and sometimes the facts can get lost amongst our feelings when we write about them. Subjectivity analysis via Natural Language Processing is a great tool for finding out how a given writer feels about a given subject, without leaning on other potentially biased people for their personal interpretations.

Take advantage of our Subjectivity Analysis API in Java following just a few simple steps below, or check out the Cloudmersive API Console page to find ready-to-run code available in 12 additional programming languages. Calling this API will return a Subjectivity Score Result with lower values indicating more objective writing, and higher values indicating more subjective writing.

For installation with Maven, first add a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Next add a reference to the dependency in pom.xml:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

To wrap things up, add in the import classes and complete the function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.AnalyticsApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
AnalyticsApi apiInstance = new AnalyticsApi();
SubjectivityAnalysisRequest input = new SubjectivityAnalysisRequest(); // SubjectivityAnalysisRequest | Input subjectivity analysis request
try {
SubjectivityAnalysisResponse result = apiInstance.analyticsSubjectivity(input);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AnalyticsApi#analyticsSubjectivity");
e.printStackTrace();
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet