Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Park committed Oct 24, 2017
2 parents b968b2b + 37dbb95 commit 3a7662d
Show file tree
Hide file tree
Showing 44 changed files with 260 additions and 66 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: rosetteApi
Type: Package
Title: Rosette API
Version: 1.5.0
Date: 2016-12-12
Version: 1.8.0
Date: 2017-10-24
Author: Sam Hausmann [aut, cre],
Chris Park [ctb],
Hannah Gaudet [ctb]
Expand All @@ -22,4 +22,4 @@ Suggests:
URL: https://developer.rosette.com
BugReports: https://developer.rosette.com/support-ticket
VignetteBuilder: knitr
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
28 changes: 28 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
node {
def SOURCEDIR = pwd()
try {
stage("Clean up") {
step([$class: 'WsCleanup'])
}
stage("Checkout Code") {
checkout scm
}
stage("Test with Docker") {
withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) {
sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-r"
}
}
slack(true)
} catch (e) {
currentBuild.result = "FAILED"
slack(false)
throw e
}
}

def slack(boolean success) {
def color = success ? "#00FF00" : "#FF0000"
def status = success ? "SUCCESSFUL" : "FAILED"
def message = status + ": Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
slackSend(color: color, channel: "#rapid", message: message)
}
51 changes: 44 additions & 7 deletions R/Api.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ api <- function(user_key, endpoint, parameters=FALSE, custom_headers=NULL, url_p
"name-similarity"= error_check(
post_endpoint(user_key, check_names(parameters, "name-similarity"), "name-similarity", url, custom_headers, url_parameters)
),
"name-deduplication"= error_check(
post_endpoint(user_key, check_deduplication(parameters, "name-deduplication"), "name-deduplication", url, custom_headers, url_parameters)
),
"relationships"= error_check(
post_endpoint(user_key, check_content_parameters(parameters), "relationships", url, custom_headers, url_parameters)
),
"tokens"= error_check(
post_endpoint(user_key, check_content_parameters(parameters), "tokens", url, custom_headers, url_parameters)
),
"topics"= error_check(
post_endpoint(user_key, check_content_parameters(parameters), "topics", url, custom_headers, url_parameters)
),
"morphology"= error_check(
post_endpoint(user_key, check_content_parameters(parameters), check_morphology(parameters, "morphology"), url, custom_headers, url_parameters)
),
Expand All @@ -74,6 +80,9 @@ api <- function(user_key, endpoint, parameters=FALSE, custom_headers=NULL, url_p
"text-embedding"= error_check(
post_endpoint(user_key, check_content_parameters(parameters), "text-embedding", url, custom_headers, url_parameters)
),
"transliteration"= error_check(
post_endpoint(user_key, check_content_parameters(parameters), "transliteration", url, custom_headers, url_parameters)
),
"syntax/dependencies"= error_check(
post_endpoint(user_key, check_content_parameters(parameters), "syntax/dependencies", url, custom_headers, url_parameters)
),
Expand All @@ -87,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.5.0"
bindingVersion <- "1.8.0"
return(bindingVersion)
}

Expand Down Expand Up @@ -138,6 +147,19 @@ check_names <- function(parameters, endpoint) {
}
}

#' check if the required request parameters for name deduplication are correct
#' @param parameters - parameters list to be passed to specified Rosette API endpoint
#' @param endpoint - Rosette API endpoint to be utilized
#' @return Returns list of verified parameters to be sent to Rosette API
check_deduplication <- function(parameters, endpoint) {
params <- parameters
if (!("names" %in% names(params))) {
stop("Must supply a list of names to deduplicate")
} else {
return(parameters)
}
}

#' create a multipart
#' @param parameters - parameters list to be passed to specified Rosette API endpoint
#' @return Returns a multipart
Expand Down Expand Up @@ -225,6 +247,19 @@ serialize_name_parameters <- function(parameters) {
return(jsonlite::toJSON(serialized_params, auto_unbox = TRUE))
}

#' serialize Rosette API parameters
#' @param parameters - parameters list to be passed to name-deduplication
#' @return Returns the serialized parameters for the Rosette API
serialize_name_deduplication_parameters <- function(parameters) {
serialized_params <- list()
for (param in names(parameters)) {
if (param == "names" || param == "threshold") {
serialized_params[[param]] <- parameters[[param]]
}
}
return(jsonlite::toJSON(serialized_params, auto_unbox = TRUE))
}

#' Helper to check for file submission
#' @param parameters - JSON parameters
#' @return true if multipart
Expand All @@ -250,23 +285,25 @@ post_endpoint <- function(user_key, parameters, endpoint, url, custom_headers=NU
content_type <- "application/json"
if (endpoint == "name-translation" || endpoint == "name-similarity") {
request_body <- serialize_name_parameters(parameters)
} else if (endpoint == "name-deduplication") {
request_body <- serialize_name_deduplication_parameters(parameters)
} else {
request_body <- serialize_parameters(parameters)
}
}

if (is.null(url_parameters)) {
response <- httr::POST(
paste(url, endpoint, sep=""),
paste(url, endpoint, sep=""),
encode = encoding,
httr::add_headers(get_headers(user_key, content_type = content_type, custom_headers = custom_headers)),
httr::add_headers(get_headers(user_key, content_type = content_type, custom_headers = custom_headers)),
body = request_body
)
} else {
response <- httr::POST(
paste(url, endpoint, sep=""),
paste(url, endpoint, sep=""),
encode = encoding,
httr::add_headers(get_headers(user_key, content_type = content_type, custom_headers = custom_headers)),
httr::add_headers(get_headers(user_key, content_type = content_type, custom_headers = custom_headers)),
body = request_body,
query = url_parameters
)
Expand All @@ -284,12 +321,12 @@ post_endpoint <- function(user_key, parameters, endpoint, url, custom_headers=NU
get_endpoint <- function(user_key, endpoint, url, custom_headers=NULL, url_parameters=NULL) {
if (is.null(url_parameters)) {
response <- httr::GET(
paste(url, endpoint, sep=""),
paste(url, endpoint, sep=""),
httr::add_headers(get_headers(user_key, custom_headers))
)
} else {
response <- httr::GET(
paste(url, endpoint, sep=""),
paste(url, endpoint, sep=""),
httr::add_headers(get_headers(user_key, custom_headers)),
query = url_parameters
)
Expand Down
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ $ cat > installrosette.R << EOF
$ R --no-save < installrosettte.R
```

<<<<<<< HEAD
=======
If the version you are using is not [the latest from CRAN](https://cran.r-project.org/web/packages/rosetteApi/index.html)
or [github](https://github.com/rosette-api/R-Binding/releases),
please check for its [**compatibilty with api.rosette.com**](https://developer.rosette.com/features-and-functions?r).
If you have an on-premise version of Rosette API server, please contact support for
binding compatibility with your installation.

To check your installed version:

`> packageVersion("rosetteAPI")`


>>>>>>> develop
## Example using the Rosette API language detection endpoint
```R
library(rosetteApi)
Expand All @@ -35,20 +49,21 @@ print(jsonlite::toJSON(result$content, pretty = TRUE)
```
## API Parameters
| Parameter | Endpoint | Required
| ------------- |------------- |-------------
| content | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, syntax_dependencies | Either content or contentUri required |
| contentUri | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, syntax_dependencies | Either content or contentUri required |
| language | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, name similarity | No |
| documentFile | categories, entities, language, morphology, relationships, sentences, sentiment, tokens | No |
| ------------- |------------- |-------------
| content | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, topics, syntax/dependencies, transliteration (Yes) | Either content or contentUri required |
| contentUri | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, topics, syntax/dependencies | Either content or contentUri required |
| language | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, topics, name similarity | No |
| documentFile | categories, entities, language, morphology, relationships, sentences, sentiment, tokens, topics | No |
| name1 | name similarity | Yes |
| name2 | name similarity| Yes |
| name | name translation | Yes |
| targetLanguage | name translation | Yes |
| targetLanguage | name translation, transliteration (No) | Yes |
| entityType | name translation | No |
| sourceLanguageOfOrigin | name translation | No |
| sourceLanguageOfUse | name translation | No |
| sourceScript | name translation | No |
| targetScript | name translation | No |
| sourceScript | name translation, transliteration | No |
| sourceLanguage | transliteration | Yes |
| targetScript | name translation, transliteration | No |
| targetScheme | name translation | No |
| options | relationships | No |
| accuracyMode | relationships | Yes |
Expand All @@ -64,5 +79,11 @@ Additional environment settings:
`-e ALT_URL=<alternative URL>`
`-e FILENAME=<single filename>`

## Documentation
View the latest [documentation](https://cran.r-project.org/web/packages/rosetteApi/rosetteApi.pdf)

## Release Notes
See the [wiki](https://github.com/rosette-api/R-Binding/wiki/Release-Notes)

## Additional Information
See [Rosette API site](https://developer.rosette.com/)
2 changes: 1 addition & 1 deletion examples/categories.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parameters[[ "contentUri" ]] <- categories_url_data
if (is.na(opt$url)){
result <- api(opt$key, "categories", parameters)
} else {
result <- api(opt$key, "categories", parameters, NULL, opt$url)
result <- api(opt$key, "categories", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/entities.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ url_parameters <- list(output = "rosette")
if (is.na(opt$url)){
result <- api(opt$key, "entities", parameters, url_parameters = url_parameters)
} else {
result <- api(opt$key, "entities", parameters, NULL, opt$url)
result <- api(opt$key, "entities", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/info.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ opt = parse_args(opt_parser)
if (is.na(opt$url)){
result <- api(opt$key, "info")
} else {
result <- api(opt$key, "info", NULL, NULL, opt$url)
result <- api(opt$key, "info", FALSE, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/language.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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 = headers, url = opt$url)
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 @@ -17,7 +17,7 @@ parameters[[ "morphology" ]] <- "complete"
if (is.na(opt$url)){
result <- api(opt$key, "morphology", parameters)
} else {
result <- api(opt$key, "morphology", parameters, NULL, opt$url)
result <- api(opt$key, "morphology", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/morphology_compound-components.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parameters[[ "morphology" ]] <- "compound-components"
if (is.na(opt$url)){
result <- api(opt$key, "morphology", parameters)
} else {
result <- api(opt$key, "morphology", parameters, NULL, opt$url)
result <- api(opt$key, "morphology", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/morphology_han-readings.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parameters[[ "morphology" ]] <- "han-readings"
if (is.na(opt$url)){
result <- api(opt$key, "morphology", parameters)
} else {
result <- api(opt$key, "morphology", parameters, NULL, opt$url)
result <- api(opt$key, "morphology", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/morphology_lemmas.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parameters[[ "morphology" ]] <- "lemmas"
if (is.na(opt$url)){
result <- api(opt$key, "morphology", parameters)
} else {
result <- api(opt$key, "morphology", parameters, NULL, opt$url)
result <- api(opt$key, "morphology", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/morphology_parts-of-speech.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parameters[[ "morphology" ]] <- "parts-of-speech"
if (is.na(opt$url)){
result <- api(opt$key, "morphology", parameters)
} else {
result <- api(opt$key, "morphology", parameters, NULL, opt$url)
result <- api(opt$key, "morphology", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
29 changes: 29 additions & 0 deletions examples/name_deduplication.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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)

name_dedupe_data <- "John Smith,Johnathon Smith,Fred Jones"


text <- unlist(strsplit(name_dedupe_data, ","))
targetLanguage <- rep("eng", length(text))
targetScript <- rep("Latn", length(text))

names = data.frame(text, targetLanguage, targetScript)
parameters <- list()
parameters[[ "names" ]] <- names
parameters[[ "threshold" ]] <- 0.75

if (is.na(opt$url)){
result <- api(opt$key, "name-deduplication", parameters)
} else {
result <- api(opt$key, "name-deduplication", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/name_similarity.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ parameters[[ "name2" ]] <- matched_name_data2
if (is.na(opt$url)){
result <- api(opt$key, "name-similarity", parameters)
} else {
result <- api(opt$key, "name-similarity", parameters, NULL, opt$url)
result <- api(opt$key, "name-similarity", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/name_translation.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ parameters[[ "targetScript" ]] <- "Latn"
if (is.na(opt$url)){
result <- api(opt$key, "name-translation", parameters)
} else {
result <- api(opt$key, "name-translation", parameters, NULL, opt$url)
result <- api(opt$key, "name-translation", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/ping.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ opt = parse_args(opt_parser)
if (is.na(opt$url)){
result <- api(opt$key, "ping")
} else {
result <- api(opt$key, "ping", NULL, NULL, opt$url)
result <- api(opt$key, "ping", FALSE, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
2 changes: 1 addition & 1 deletion examples/relationships.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parameters[[ "content" ]] <- relationships_text_data
if (is.na(opt$url)){
result <- api(opt$key, "relationships", parameters)
} else {
result <- api(opt$key, "relationships", parameters, NULL, opt$url)
result <- api(opt$key, "relationships", parameters, NULL, NULL, opt$url)
}
print(jsonlite::toJSON(result$header, pretty = TRUE))
print(jsonlite::toJSON(result$content, pretty = TRUE))
Loading

0 comments on commit 3a7662d

Please sign in to comment.