Using R with Dandelion

116 views
Skip to first unread message

Giorgio Alfredo Spedicato

unread,
Apr 15, 2015, 11:39:03 AM4/15/15
to dand...@spaziodati.eu
Hi all,
thank you for your great products. Is it possible for you to post some code snippets that show how to call your APIs directly within CRAN R code?

It would be very very useful...

sam...@spaziodati.eu

unread,
Apr 16, 2015, 10:06:06 AM4/16/15
to dand...@spaziodati.eu
Hi Giorgio,
try with this:
https://gist.github.com/nicolasambin/083a237dc8eb438188b1

I've simply use "RCurl" to make a request to dataTXT fed with the right parameters.
It doesn't handle requests exceptions. It allows you to input either a url or a string besides tuning other dataTXT parameters. It outputs a nice data.frame.

Let us now whether there are problems and feel free to share with us your impressions and results. We're always looking for improving our service.

Nicola

Giorgio Spedicato

unread,
May 21, 2015, 4:31:49 PM5/21/15
to dand...@spaziodati.eu
I'm sorry but I tried to use your API and I got this error:
library("jsonlite")
library("RCurl")


# the following function picks as parameters:
# either a text or a url
# app_id
# app_key
# include (a list of comma separated fields (you may insert: image,abstract,categories,types,lod))
# min_confidence (set by deafault to 0.6)
# language (set to automatic detection)
# social (which enables to parse hashtags etc. (set to false))

# it returns (unless no request errors (uncaught) occur) either a data.frame having as many rows as the annotations and 
# columns based on the include parameter or a message 'No entities found'

# it corresponds to the followings GET requests:
# &min_confidence=min_confidence&lang=language&social=social

dataTxtNex <- function(input, app_id, app_key, include, min_confidence=.6, language='auto', social=F) {
  params <- list()
  params['$app_id'] <- app_id
  params['$app_key'] <- app_key
  if (grepl("^https?://", input)){
    params['url'] <- input
  } else {
    params['text'] <- input
  }
  params['min_confidence'] <- min_confidence
  params['social'] <- social
  params['include'] <- include
  params['lang'] <- language
  dataTxtReply <- fromJSON(getForm(nex, .params=params, .checkParams = TRUE))
  annotations <- dataTxtReply$annotations
  if (length(annotations) > 1) {
    return(annotations)
  } else {
    return('No entities found')
  }
}

ciao<-dataTxtNex(input = "Quest'anno ci saranno le elezioni del rettore. Speriamo che vinca la lista di Francesca.",
                 app_id="myappid",
                 app_key="myappkey",
                 include="categories")


Error in function (type, msg, asError = TRUE)  : 
  SSL certificate problem: self signed certificate in certificate chain.

 I used myappid and myappkey as shown in my dashboard

sam...@spaziodati.eu

unread,
May 21, 2015, 6:31:28 PM5/21/15
to dand...@spaziodati.eu
That's seems to be an issue with SSL verification with getForm and, in general the RCurl library. (See, e.g., http://stackoverflow.com/questions/17411313/ssl-verification-causes-rcurl-and-httr-to-break-on-a-website-that-should-be-le)

I could not replicate the error, but I understood there are two possibilities:
- either setting ssl.verifypeer = FALSE in the RCurl options (but it is not a really good practice), i.e. replace:
getForm(nex, .params=params, .checkParams = TRUE)
with
getForm(nex, .params=params, .checkParams = TRUE, ssl.verifypeer = FALSE)

- or type
cert <- system.file("CurlSSL/cacert.pem", package = "RCurl")
and then add cainfo = cert to getForm, i.e. replace:
getForm(nex, .params=params, .checkParams = TRUE)
with
getForm(nex, .params=params, .checkParams = TRUE, cainfo = cert)

Tell us whether this fixed your problem.
Reply all
Reply to author
Forward
0 new messages