Im using Google's NLP Api to analyze sentences and retrieve part of speech tokens form cells in a google drive sheet using appScript.
The problem is I can't retrieve or identify any of the words in the sentence as gerunds. From documentation GERUND is token of Form.
For example, in this sentence "She enjoys dancing and singing" "dancing" and "singing" are both gerunds, but all the words return FORM_UNKNOWN
AppScript .gs code
function analyzeTest(){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName(“My Sheet“);
var commentEnCellVal = ws.getRange('C24').getValue();
console.log("C24 value " + commentEnCellVal);//the value in cell C24 is “She enjoys dancing and singing”
var aTag = [];
var aForm = [];
var aTense = [];
//…
if (commentEnCellVal) {
var nlData = retrieveEntitySentiment(commentEnCellVal);
var newValues = []
for (var token of nlData.tokens) {
var row = [token.partOfSpeech.tag,
token.partOfSpeech.form,
token.partOfSpeech.tense];
//I’m retrieveing all available tags, tense, moon, aspect…etc including dependecy tags
//and pushing into the arrays
aTag.push(token.partOfSpeech.tag);
aForm.push(token.partOfSpeech.form);
aTense.push(token.partOfSpeech.tense);
}
}
var tags = aTag;
var form = aForm;
var tense = aTense;
console.log("tags " + tags);
console.log("form " + form);
console.log("tense "+ tense);
}
The console log
C24 value She enjoys dancing and singing.
tags PRON,VERB,VERB,CONJ,NOUN,PUNCT
form FORM_UNKNOWN,FORM_UNKNOWN,FORM_UNKNOWN,FORM_UNKNOWN,FORM_UNKNOWN,FORM_UNKNOWN
tense TENSE_UNKNOWN,PAST,TENSE_UNKNOWN,TENSE_UNKNOWN,TENSE_UNKNOWN,TENSE_UNKNOWN
This the NLP function (I've also tried language.googleapis.com/v1, same result)
function retrieveEntitySentiment(line) {
var apiKey = “****”;
var apiEndpoint = 'https://language.googleapis.com/v1beta2/documents:analyzeSyntax?key=' + apiKey;
// Create json request, w/ text, language, type & encoding
var nlData = {
document: {
language: 'en-us',
type: 'PLAIN_TEXT',
content: line
},
encodingType: 'UTF8'
//apiVersion: '2.9.0'
};
// Package all of the options and the data together for the call
var nlOptions = {
method: 'post',
modelType:'latest',
modelVersion:'latest',
apiVersion: '2.9.0',
contentType: 'application/json',
payload: JSON.stringify(nlData)
};
// And make the call
var response = UrlFetchApp.fetch(apiEndpoint, nlOptions);
return JSON.parse(response);
};
I guess I can set some sort of rule/conditions checking diff tags to know if it's a Gerund, but I'd like to know if there is something wrong in the code which Im not seeing. Thanks.