Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
seth-mg committed Jan 18, 2018
2 parents 402876b + 2fb4601 commit 83b6690
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
^README\.Rmd$ # An Rmarkdown file used to generate README.md
^cran-comments\.md$ # Comments for CRAN submission
^NEWS.md$ # A news file written in Markdown
^NEWS.md$ # A news file written in Markdown
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
examples$
^Jenkinsfile
13 changes: 8 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Package: rosetteApi
Type: Package
Title: Rosette API
Version: 1.8.0
Date: 2017-10-24
Author: Sam Hausmann [aut, cre],
Chris Park [ctb],
Hannah Gaudet [ctb]
Version: 1.9.0
Date: 2018-01-18
Authors@R: c(
person("Chris", "Park", email = "cpark@basistech.com", role = c("aut", "cre")),
person("Sam", "Hausmann", role = "aut"),
person("Hannah", "Gaudet", role = "ctb"),
person("Seth", "Gransky", email = "seth@basistech.com", role = "ctb"),
person("Basis", "Technology Corp.", role ="cph"))
Maintainer: Chris Park <cpark@basistech.com>
Description: Rosette is an API for multilingual text analysis and information
extraction. More information can be found at <https://developer.rosette.com>.
Expand Down
4 changes: 3 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ node {
checkout scm
}
stage("Test with Docker") {
withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) {
echo "${env.ALT_URL}"
def useUrl = ("${env.ALT_URL}" == "null") ? "${env.BINDING_TEST_URL}" : "${env.ALT_URL}"
withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${useUrl}"]) {
sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-r"
}
}
Expand Down
9 changes: 7 additions & 2 deletions R/Api.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ api <- function(user_key, endpoint, parameters=FALSE, custom_headers=NULL, url_p
#' Provides the binding Version
#' @return current binding version
get_binding_version <- function() {
bindingVersion <- "1.8.0"
bindingVersion <- "1.9.0"
return(bindingVersion)
}

Expand Down Expand Up @@ -214,13 +214,18 @@ error_check <- function(response) {
#' @param custom_headers - custom headers for the Rosette API
#' @return Returns the combined h
get_headers <- function(user_key, content_type="application/json", custom_headers=NULL) {
headers <- c("X-RosetteAPI-Key" = user_key, "Content-Type" = content_type, "X-RosetteAPI-Binding" = "R", "X-RosetteAPI-Binding-Version" = get_binding_version(), "user-agent" = "ruseragent")
headers <- c("X-RosetteAPI-Key" = user_key, "Content-Type" = content_type, "X-RosetteAPI-Binding" = "R", "X-RosetteAPI-Binding-Version" = get_binding_version(), "user-agent" = get_user_agent())
if (!is.null(custom_headers)) {
return(c(headers, custom_headers))
}
return(headers)
}

get_user_agent <- function() {
version <- paste(R.Version()$platform, R.Version()$major, R.Version()$minor, sep=".")
return(paste("R", get_binding_version(), version, sep="/"))
}

#' serialize Rosette API parameters
#' @param parameters - parameters list to be passed to specified Rosette API endpoint
#' @return Returns the serialized parameters for the Rosette API
Expand Down
2 changes: 1 addition & 1 deletion examples/entities.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option_list = list( make_option(c("-k", "--key"), action="store", default=NA, ty
opt_parser = OptionParser(option_list=option_list)
opt = parse_args(opt_parser)

entities_text_data <- "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS"
entities_text_data <- "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country."

parameters <- list()
parameters[[ "content" ]] <- entities_text_data
Expand Down
27 changes: 27 additions & 0 deletions examples/language_multilingual.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
source("../R/Api.R")
library(jsonlite)
library("optparse")

option_list = list( make_option(c("-k", "--key"), action="store", default=NA, type='character',
help="Rosette API key"), make_option(c("-u", "--url"), action="store", default=NA, type='character',
help="Rosette API url"))
opt_parser = OptionParser(option_list=option_list)
opt = parse_args(opt_parser)

language_multilingual_data <- "On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times. Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان."

options <- list()
options[[ "multilingual" ]] <- "true"

parameters <- list()
parameters[[ "content" ]] <- language_multilingual_data
parameters[[ "options" ]] <- options
custom_headers <- c("X-RosetteAPI-App" = "r-application-test")

if (is.na(opt$url)){
result <- api(opt$key, "language", parameters = parameters, custom_headers = custom_headers)
} else {
result <- api(opt$key, "language", parameters = parameters, custom_headers = custom_headers, NULL, url = opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/morphology_complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option_list = list( make_option(c("-k", "--key"), action="store", default=NA, ty
opt_parser = OptionParser(option_list=option_list)
opt = parse_args(opt_parser)

morphology_complete_data <- "The quick brown fox jumped over the lazy dog. Yes he did."
morphology_complete_data <- "The quick brown fox jumped over the lazy dog. 👍🏾 Yes he did. B)"

parameters <- list()
parameters[[ "content" ]] <- morphology_complete_data
Expand Down
2 changes: 1 addition & 1 deletion examples/name_deduplication.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option_list = list( make_option(c("-k", "--key"), action="store", default=NA, ty
opt_parser = OptionParser(option_list=option_list)
opt = parse_args(opt_parser)

name_dedupe_data <- "John Smith,Johnathon Smith,Fred Jones"
name_dedupe_data <- "Alice Terry,Alice Thierry,Betty Grable,Betty Gable,Norma Shearer,Norm Shearer,Brigitte Helm,Bridget Helem,Judy Holliday,Julie Halliday"


text <- unlist(strsplit(name_dedupe_data, ","))
Expand Down
2 changes: 1 addition & 1 deletion examples/relationships.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option_list = list( make_option(c("-k", "--key"), action="store", default=NA, ty
opt_parser = OptionParser(option_list=option_list)
opt = parse_args(opt_parser)

relationships_text_data <- "Bill Gates, Microsoft's former CEO, is a philanthropist."
relationships_text_data <- "FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC’s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR’s security cameras to the same government officials. At the time, Timms was the head of FLIR’s Middle East office in Dubai."

parameters <- list()
parameters[[ "content" ]] <- relationships_text_data
Expand Down
2 changes: 1 addition & 1 deletion examples/sentences.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option_list = list( make_option(c("-k", "--key"), action="store", default=NA, ty
opt_parser = OptionParser(option_list=option_list)
opt = parse_args(opt_parser)

sentences_data <- "This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me."
sentences_data <- "This land is your land. This land is my land, from California to the New York island; from the red wood forest to the Gulf Stream waters. This land was made for you and Me. As I was walking that ribbon of highway, I saw above me that endless skyway: I saw below me that golden valley: This land was made for you and me."

parameters <- list()
parameters[[ "content" ]] <- sentences_data
Expand Down
2 changes: 1 addition & 1 deletion examples/transliteration.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option_list = list( make_option(c("-k", "--key"), action="store", default=NA, ty
opt_parser = OptionParser(option_list=option_list)
opt = parse_args(opt_parser)

transliteration_data <- "معمر محمد أبو منيار القذاف"
transliteration_data <- "ana r2ye7 el gam3a el sa3a 3 el 3asr"

parameters <- list()
parameters[[ "content" ]] <- transliteration_data
Expand Down
6 changes: 5 additions & 1 deletion man/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@
- New transliteration example

# rosetteApi 1.8.0
- New topics endpoint
- New topics endpoint

# rosetteApi 1.9.0
- New multilingual language example
- User Agent now includes runtime version
Binary file removed man/rosetteApi_1.5.0.pdf
Binary file not shown.
Binary file added man/rosetteApi_1.9.0.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions man/serialize_name_deduplication_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ test_that("The parameters object is valid", {
expect_equal(check_content_parameters(parameters), parameters)
})

test_that("The User-Agent is valid", {
version <- paste(R.Version()$platform, R.Version()$major, R.Version()$minor, sep=".")
ua <- paste("R", get_binding_version(), version, sep="/")
expect_equal(get_user_agent(), ua)
})

0 comments on commit 83b6690

Please sign in to comment.