2017-11-04 6 views
0

RからMicrosoft Cognitive APIを使用してテキストデータを処理しようとしています。私はアカウントを作成し、鍵を取得しました。コードは以下の通りです。私はプライバシーの理由から鍵を含めていません。Microsoft Text Analysis APIでhttr :: POST()を使用中に状態404が返されました

library(httr) 
library(jsonlite) 
library(data.table) 
library(dplyr) 

cogapikey <- "xxxx" 
cogapi <- "https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0" 
text=c("is this english?" 
     ,"tak er der mere kage" 
     ,"merci beaucoup" 
     ,"guten morgen" 
     ,"bonjour" 
     ,"merde" 
     ,"That's terrible" 
     ,"R is awesome") 
df <- data_frame(id=1:length(text),text) 
mydata<- list(documents=df) 

# language detection 
## construct a request 
response <- POST(cogapi,add_headers(`Ocp-Apim-Subscription-Key`=cogapikey), 
       body=toJSON(mydata)) 
print(response) 

応答変数を出力すると、次のようになります。

Response [https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0] 
    Date: 2017-11-04 13:29 
    Status: 404 
    Content-Type: application/json 
    Size: 54 B 

hereのチュートリアルを再現しようとしています。 私はインストールする必要があり、追加の前提条件のツール/パッケージがある場合、私は思っていた

R version 3.4.0 (2017-04-21) 
Platform: x86_64-apple-darwin15.6.0 (64-bit) 
Running under: macOS Sierra 10.12.6 

Matrix products: default 
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib 

locale: 
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 

attached base packages: 
[1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] RCurl_1.95-4.8  bitops_1.0-6  dplyr_0.7.4   data.table_1.10.4-3 jsonlite_1.5  
[6] httr_1.3.1   tm_0.7-1   NLP_0.1-11   tidytext_0.1.4  

loaded via a namespace (and not attached): 
[1] Rcpp_0.12.13  compiler_3.4.0 plyr_1.8.4  bindr_0.1   tokenizers_0.1.4 tools_3.4.0  
[7] tibble_1.3.4  nlme_3.1-131  lattice_0.20-35 pkgconfig_2.0.1 rlang_0.1.2  Matrix_1.2-9  
[13] psych_1.7.8  curl_3.0   parallel_3.4.0 bindrcpp_0.2  janeaustenr_0.1.5 stringr_1.2.0  
[19] grid_3.4.0  glue_1.2.0  R6_2.2.2   foreign_0.8-67 reshape2_1.4.2 tidyr_0.7.2  
[25] purrr_0.2.4  magrittr_1.5  SnowballC_0.5.1 assertthat_0.2.0 mnormt_1.5-5  stringi_1.1.5  
[31] slam_0.1-40  broom_0.4.2 

を次のように私のセッション情報がありますか?前もって感謝します!

答えて

1

エンドポイントがここで修正が必要なようです。それは次のようになります。

cogapi <- "https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0/languages" 

/langaugesは、エンドポイントにありません。

関連する問題