我遵循这个文档实现了一个文本分析应用程序,使用微软认知服务。
首先,我创建了一个订阅,并获得了api键这里。然后我创建了一个新的R项目。我在我的工作目录中创建了一个名为.mscskeys.json
的json文件。它包括:
{
"textanalyticsurl": "https://westus.api.cognitive.microsoft.com/texta/analytics/v2.0/",
"textanalyticskey": "--my API key--"
}
这是我R脚本中的代码。
install.packages("mscstexta4r")
library(mscstexta4r)
textaInit()
docsText <- c(
"Loved the food, service and atmosphere! We'll definitely be back.",
"Very good food, reasonable prices, excellent service.",
"It was a great restaurant.",
"If steak is what you want, this is the place.",
"The atmosphere is pretty bad but the food is quite good.",
"The food is quite good but the atmosphere is pretty bad.",
"The food wasn't very good.",
"I'm not sure I would come back to this restaurant.",
"While the food was good the service was a disappointment.",
"I was very disappointed with both the service and my entree."
)
docsLanguage <- rep("en", length(docsText))
tryCatch({
textaDetectLanguages('love', numberOfLanguagesToDetect = 1L)
# Perform sentiment analysis
textaSentiment(
documents = docsText, # Input sentences or documents
languages = docsLanguage
# "en"(English, default)|"es"(Spanish)|"fr"(French)|"pt"(Portuguese)
)
}, error = function(err) {
# Print error
geterrmessage()
})
但是,当我运行它时,我会得到以下错误:
错误: mscstexta4r: Not (HTTP404)。-{ "statusCode":404,“消息”:“资源未找到”}
我做错什么了?
发布于 2016-11-07 07:57:36
发布于 2018-07-19 07:45:35
在我的例子中,我不得不修改
https://eastus.api.cognitive.microsoft.com/text/analytics/v2.0
至
https://eastus.api.cognitive.microsoft.com/text/analytics/v2.0/
请注意附加的/
,它允许应用程序连接到适当的服务,例如
.../sentiment
https://stackoverflow.com/questions/40155057
复制相似问题