Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Commit 9b68e80

Browse files
committed
fix #1 - add model param where needed, bumped ver
1 parent 9fc18bc commit 9b68e80

File tree

13 files changed

+69
-19
lines changed

13 files changed

+69
-19
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
^CONDUCT\.md$
55
^README\.Rmd$
66
cran-comments.md
7+
notes.md

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Description: The 'Microsoft Academic Knowledge' API provides programmatic access
66
(<https://academic.microsoft.com/>). Includes methods matching all 'Microsoft
77
Academic' API routes, including search, graph search, text similarity, and
88
interpret natural language query string.
9-
Version: 0.1.0.9219
9+
Version: 0.1.9.9110
1010
Authors@R: person("Scott", "Chamberlain", email = "myrmecocystus+r@gmail.com",
1111
role = c("aut", "cre"))
1212
License: MIT + file LICENSE

R/abstract.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#' ma_abstract(query = "Y=[2010, 2012)", count = 10)
88
#' }
99
ma_abstract <- function(query, count = 10, offset = 0, orderby = NULL,
10-
key = NULL, ...) {
11-
out <- ma_evaluate(query, count, offset, orderby, c("Id", "E"), key, ...)
10+
model = "latest", key = NULL, ...) {
11+
out <- ma_evaluate(query, count, offset, orderby, c("Id", "E"), model, key, ...)
1212
unname(vapply(out$E, function(z) invabs2abs(jsonlite::fromJSON(z)$IA), ""))
1313
}
1414

R/calchistogram.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
#' res$histograms$histogram
99
#' }
1010
ma_calchist <- function(query, count = 10, offset = 0,
11-
atts = c("Id", "AA.AuN", "J.JN", "Ti", "Y", "E", "CC"), key = NULL, ...) {
11+
atts = c("Id", "AA.AuN", "J.JN", "Ti", "Y", "E", "CC"), model = "latest",
12+
key = NULL, ...) {
1213

14+
assert(model, "character")
15+
if (!model %in% c('latest', 'beta-2015')) {
16+
stop("model must be one or 'latest' or 'beta-2015'")
17+
}
1318
if (!is.null(atts)) atts <- paste0(atts, collapse = ",")
1419
args <- comp(list(expr = query, count = count, offset = offset,
15-
attributes = atts))
20+
attributes = atts, model = model))
1621
ma_HTTP("academic/v1.0/calchistogram", args, key, ...)
1722
}

R/evaluate.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#' @param atts (character) fields to return, in a character vector. See
99
#' <https://docs.microsoft.com/en-us/azure/cognitive-services/academic-knowledge/entityattributes>
1010
#' for details.
11+
#' @param model (character) Name of the model that you wish to query. One of 'latest'
12+
#' or 'beta-2015'. Default: latest
1113
#' @param key (character) microsoft academic API key, see Details.
1214
#' @param ... curl options passed on to [crul::HttpClient]
1315
#' @return a list of length two, with `expr` (character) and
@@ -31,11 +33,16 @@
3133
#' ma_evaluate(x)
3234
#' }
3335
ma_evaluate <- function(query, count = 10, offset = 0, orderby = NULL,
34-
atts = c("Id", "AA.AuN", "J.JN", "Ti", "Y", "E", "CC"), key = NULL, ...) {
36+
atts = c("Id", "AA.AuN", "J.JN", "Ti", "Y", "E", "CC"), model = "latest",
37+
key = NULL, ...) {
3538

39+
assert(model, "character")
40+
if (!model %in% c('latest', 'beta-2015')) {
41+
stop("model must be one or 'latest' or 'beta-2015'")
42+
}
3643
if (!is.null(atts)) atts <- paste0(atts, collapse = ",")
3744
args <- comp(list(expr = query, count = count, offset = offset,
38-
orderby = orderby, attributes = atts))
45+
orderby = orderby, attributes = atts, model = model))
3946
tibble::as_tibble(
4047
ma_HTTP("academic/v1.0/evaluate", args, key, ...)$entities
4148
)

R/search.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#' }
1414
ma_search <- function(query, count = 10, offset = 0, orderby = NULL,
1515
atts = c("Id", "AA.AuN", "J.JN", "Ti", "Y", "E", "CC"),
16-
key = NULL, ...) {
16+
model = "latest", key = NULL, ...) {
1717

1818
if (!is.null(atts)) atts <- paste0(atts, collapse = ",")
19-
out <- ma_evaluate(query, count, offset, orderby, atts, key, ...)
19+
out <- ma_evaluate(query, count, offset, orderby, atts, model, key, ...)
2020
ee <- dfrbl(lapply(out$E, function(z) {
2121
dat <- jsonlite::fromJSON(z)
2222
dat <- dat[names(dat) %in% c('DN', 'VFN', 'DOI', 'D')]

R/similarity.R

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
#' @export
44
#' @param s1,s2 (character) strings 1 and 2. required
55
#' @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
68
#' @param key (character) microsoft academic API key, see [microdemic]
79
#' @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.
814
#' @examples \dontrun{
915
#' s1 <- "Using complementary priors, we derive a fast greedy algorithm that
1016
#' can learn deep directed belief networks one layer at a time, provided the
@@ -18,14 +24,21 @@
1824
#'
1925
#' ma_similarity(s1, s2, method = "POST")
2026
#' }
21-
ma_similarity <- function(s1, s2, method = "GET", key = NULL, ...) {
27+
ma_similarity <- function(s1, s2, method = "GET", model = "latest", key = NULL, ...) {
2228
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+
2335
if (method == "GET") {
24-
args <- comp(list(s1 = s1, s2 = s2))
36+
args <- comp(list(s1 = s1, s2 = s2, model = model))
2537
ma_HTTP("academic/v1.0/similarity", args, key, ...)
2638
} 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)
2841
ma_HTTP("academic/v1.0/similarity", NULL, key = key,
29-
method = 'POST', body = args, ...)
42+
method = 'POST', args = args, body = body, ...)
3043
}
3144
}

R/zzz.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ma_HTTP <- function(path, args, key, method = "GET", body = list(),
1111
`Ocp-Apim-Subscription-Key` = key
1212
)
1313
)
14+
if (method == "POST") cli$headers$`Content-Type` <- "application/x-www-form-urlencoded"
1415
if (!is.null(ctype)) cli$headers <- c(cli$headers, `Content-Type` = ctype)
1516
res <- switch(
1617
method,

man/ma_abstract.Rd

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ma_calchist.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)