How to solve Not Found (HTTP 404) in package mscstexta4r in R?

时间:2016-10-20 12:53:47

标签: r microsoft-cognitive text-analysis

I followed this documentation to implement a text analysis application using the Microsoft Cognitive Services.

First I created a subscription and got the api keys here. Then I created a new R project. I created a json file named .mscskeys.json in my working directory. It contains:

{
"textanalyticsurl": "https://westus.api.cognitive.microsoft.com/texta/analytics/v2.0/",
"textanalyticskey": "--my API key--"
}

This the code in my R script.

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()

})

But when I run it, I get the following error:

Error: mscstexta4r: Not Found (HTTP 404). - { "statusCode": 404, "message": "Resource not found" }

what I am doing wrong?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

就我而言,我必须进行修改

https://eastus.api.cognitive.microsoft.com/text/analytics/v2.0

https://eastus.api.cognitive.microsoft.com/text/analytics/v2.0/

请注意,附加的/允许应用程序连接到适当的服务,例如

.../sentiment