google-apps-script - 如何将我的输出格式化为彼此重叠而不是并排?
问题描述
我在 Apps Scripts 中使用 Googles NLP 并且数据正在通过。但是,我的输出是水平显示的,而不是相互重叠的。可能是一个简单的更改,但我无法弄清楚。在我分享的屏幕截图中,我希望数字 0.3 低于指标 2.10(黄色)。任何意见将是有益的。
function SentimentAnalysis(text)
{
if (text == undefined || text == null || text == "")
{
throw "No text was specified for performing sentiment analysis."
}
var URL_PREFIX = "https://language.googleapis.com/v1/documents:analyzeSentiment?fields=documentSentiment&key=";
// retrieve api key;
var apiKey = PropertiesService.getScriptProperties().getProperty("GOOGLE_CLOUD_API_KEY");
if (apiKey == null || apiKey == "REPLACEME" || apiKey == "") {
PropertiesService.getScriptProperties().setProperty("GOOGLE_CLOUD_API_KEY", "REPLACEME");
throw "Specify your GOOGLE_CLOUD_API_KEY via User Properties (File->Project Properties, Script Properties)";
}
var url = URL_PREFIX + apiKey;
// define the request
var data = {
"document": {
"content": text,
"type": "PLAIN_TEXT"
},
"encodingType": "UTF8"
};
var options = {
"method" : "POST",
"contentType" : "application/json",
"payload" : JSON.stringify(data)
};
// make the request
var response = UrlFetchApp.fetch(url, options);
// get the response
if (response.getResponseCode() != 200) {
throw "Unexpected response code from Google.";
}
var responseText = response.getContentText();
if (responseText == null || responseText == "") {
throw "Empty response from Facebook.";
}
// parse the response
var magnitude = 0, score = 0;
try
{
var sentimentResponse = JSON.parse(responseText, false);
magnitude = parseFloat(sentimentResponse.documentSentiment.magnitude);
score = parseFloat(sentimentResponse.documentSentiment.score);
}
catch (e)
{
throw "Unreadable response from Google: " + e;
}
return [[magnitude, score]];
}
解决方案
我相信你的目标如下。
- 您想将
magnitude
和的值放在score
垂直方向。 - 您正在使用的功能
SentimentAnalysis
作为自定义功能。 magnitude
并且score
是您期望的正确值。
在这种情况下,如何进行以下修改?
从:
return [[magnitude, score]];
至:
return [magnitude, score];
或者
return [[magnitude], [score]];
推荐阅读
- python-3.x - python集合计数器无法显示直方图
- asp.net - ASMX 服务的 Ninject 依赖解决问题
- python-3.x - 如何在Python中先按日期然后按时间对列表进行排序?
- android - 如何设置工具栏内的约束布局宽度以匹配父级?
- java - 无法为 unitName 检索 EntityManagerFactory
- amazon-ecs - 在 ECS Fargate 中从 Dockerhub 拉取公共镜像
- java - 带有 Spring Boot 和 Data JPA 的 RESTful Web 服务始终公开活动的 oracle 表
- php - 如何使下拉菜单反映 PHP 和 HTML 中的表单动作?
- python - 每组另一个常见的数据框中查找最常见的单元格
- kotlin - 在 ArrayList 中组合元素 [Kotlin]