我正在尝试通过R
使用Microsoft Cognitive API来处理文本数据。我创建了一个帐户并获得了密钥。代码如下。出于隐私原因,我没有提供密钥。
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
我想知道是否应该安装额外的必备工具/包?提前谢谢!
答案 0 :(得分:1)
这里似乎需要更正端点。它应该是:
cogapi <- "https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0/languages"
端点中缺少/ langauges 。