
prerna.reactor.task.lambda.flatmap.GoogleEntityAnalyzerLambda Maven / Gradle / Ivy
The newest version!
package prerna.reactor.task.lambda.flatmap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import prerna.auth.AccessToken;
import prerna.auth.AuthProvider;
import prerna.engine.api.IHeadersDataRow;
import prerna.io.connector.google.GoogleEntityResolver;
import prerna.om.EntityResolution;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.PixelOperationType;
import prerna.sablecc2.om.execptions.SemossPixelException;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.util.Constants;
public class GoogleEntityAnalyzerLambda extends AbstractFlatMapLambda {
private static final Logger classLogger = LogManager.getLogger(GoogleEntityAnalyzerLambda.class);
// col index we care about to get lat/long from
private int colIndex;
// total number of columns
private int totalCols;
@Override
public List process(IHeadersDataRow row) {
Object value = row.getValues()[colIndex];
if(value == null || value.toString().isEmpty()) {
return new Vector();
}
// grab the column index we want to use as the address
Map params = new HashMap<>();
Map docParam = new HashMap<>();
docParam.put("type", "PLAIN_TEXT");
docParam.put("language", "EN");
docParam.put("content", value.toString().replace("_", " "));
params.put("document", docParam);
// construct new values to append onto the row
// add new headers
String[] newHeaders = new String[]{"entity_name", "entity_type", "wiki_url", "content", "content_subtype"};
List retList = new Vector();
try {
// loop through the results
GoogleEntityResolver goog = new GoogleEntityResolver();
Object resultObj = goog.execute(this.user, params);
if(resultObj instanceof List) {
List results = (List) resultObj;
for(int i = 0; i < results.size(); i++) {
EntityResolution entity = results.get(i);
processEntity(entity, newHeaders, row, retList);
}
} else {
EntityResolution entity = (EntityResolution) resultObj;
processEntity(entity, newHeaders, row, retList);
}
} catch(Exception e) {
classLogger.error(Constants.STACKTRACE, e);
}
return retList;
}
private void processEntity(EntityResolution entity, String[] newHeaders, IHeadersDataRow curRow, List retList) {
Object[] newValues = new Object[5];
newValues[0] = entity.getEntity_name();
newValues[1] = entity.getEntity_type();
newValues[2] = entity.getWiki_url();
newValues[3] = entity.getContent();
newValues[4] = entity.getContent_subtype();
// copy the row so we dont mess up references
IHeadersDataRow rowCopy = curRow.copy();
rowCopy.addFields(newHeaders, newValues);
retList.add(rowCopy);
}
@Override
public void init(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy