|
3 | 3 | #' @export |
4 | 4 | #' @param s1,s2 (character) strings 1 and 2. required |
5 | 5 | #' @param method (character) one of GET (default) or POST |
| 6 | +#' @param model (character) Name of the model that you wish to query. One of 'latest' |
| 7 | +#' or 'beta-2015'. Default: latest |
6 | 8 | #' @param key (character) microsoft academic API key, see [microdemic] |
7 | 9 | #' @param ... curl options passed on to [crul::HttpClient] |
| 10 | +#' @return a single value representing the cosine similarity of the text inputs of |
| 11 | +#' s1 and s2. The output is represented by a floating point between -1.0 and +1.0. |
| 12 | +#' The similarity API evaluates the strings base on their academic concepts, |
| 13 | +#' with +1.0 being the most similar and -1.0 being the least similar. |
8 | 14 | #' @examples \dontrun{ |
9 | 15 | #' s1 <- "Using complementary priors, we derive a fast greedy algorithm that |
10 | 16 | #' can learn deep directed belief networks one layer at a time, provided the |
|
18 | 24 | #' |
19 | 25 | #' ma_similarity(s1, s2, method = "POST") |
20 | 26 | #' } |
21 | | -ma_similarity <- function(s1, s2, method = "GET", key = NULL, ...) { |
| 27 | +ma_similarity <- function(s1, s2, method = "GET", model = "latest", key = NULL, ...) { |
22 | 28 | if (!method %in% c("GET", "POST")) stop("'method' must be one of GET or POST") |
| 29 | + |
| 30 | + assert(model, "character") |
| 31 | + if (!model %in% c('latest', 'beta-2015')) { |
| 32 | + stop("model must be one or 'latest' or 'beta-2015'") |
| 33 | + } |
| 34 | + |
23 | 35 | if (method == "GET") { |
24 | | - args <- comp(list(s1 = s1, s2 = s2)) |
| 36 | + args <- comp(list(s1 = s1, s2 = s2, model = model)) |
25 | 37 | ma_HTTP("academic/v1.0/similarity", args, key, ...) |
26 | 38 | } else { |
27 | | - args <- sprintf("s1=%s&s2=%s", s1, s2) |
| 39 | + args <- comp(list(model = model)) |
| 40 | + body <- sprintf("s1=%s&s2=%s", s1, s2) |
28 | 41 | ma_HTTP("academic/v1.0/similarity", NULL, key = key, |
29 | | - method = 'POST', body = args, ...) |
| 42 | + method = 'POST', args = args, body = body, ...) |
30 | 43 | } |
31 | 44 | } |
0 commit comments