All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prerna.io.connector.google.GoogleSentimentAnalyzer Maven / Gradle / Ivy

The newest version!
package prerna.io.connector.google;

import java.util.HashMap;
import java.util.Map;

import prerna.auth.AccessToken;
import prerna.auth.AuthProvider;
import prerna.auth.User;
import prerna.io.connector.IConnectorIOp;
import prerna.om.SentimentAnalysis;
import prerna.security.HttpHelperUtility;
import prerna.util.BeanFiller;

public class GoogleSentimentAnalyzer implements IConnectorIOp {

	String url = "https://language.googleapis.com/v1/documents:analyzeSentiment";
	
	String [] beanProps = {"sentence", "magnitude", "score"};
	String jsonPattern = "sentences[].{sentence: text.content, magnitude: sentiment.magnitude, score:sentiment.score}";
	
	@Override
	public Object execute(User user, Map params) {
		// if no input, unsure what you will get...
		if(params == null) {
			params = new HashMap<>();
		}
		
		AccessToken googToken = user.getAccessToken(AuthProvider.GOOGLE);
		String accessToken = googToken.getAccess_token();
		
		// make the API call
		String jsonString = HttpHelperUtility.makePostCall(url, accessToken, params , true);
//		System.out.println("Output >>>>> " + jsonString);
		
//		// fill the bean with the return
		Object returnObj = BeanFiller.fillFromJson(jsonString, jsonPattern, beanProps, new SentimentAnalysis());
		return returnObj;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy