This library can be used to consume HPE Haven OnDemand - https://dev.havenondemand.com/apis from R language scripts.
Haven OnDemand is a set of over 70 APIs for handling all sorts of unstructured data. Here are just some of our APIs' capabilities:
For a full list of all the APIs and to try them out, check out https://www.havenondemand.com/developer/apis.
Development version from github:
install.packages("devtools") devtools::install_github("chok68/havenondemand-r")
# include havenondemand library
library(havenondemand)
# with apikey and version
client <- HODClient(apikey = "your-api-key", version = "v1")
# with apikey (version will default to v1)
client <- HODClient(apikey = "your-api-key")
# include havenondemand library
library(havenondemand)
# initialize HOD Client
client <- HODClient(apikey = apikey)
# get response
# include havenondemand library
library(havenondemand)
# initialize HOD Client
client <- HODClient(apikey = "your-api-key")
# call that result in error ('ur' parameter is wrong, it should be 'url')
result <- tryCatch({
client$postRequest(params = list(index = "test"), hodApp = HODApp$INDEX_STATUS, mode = HODClientConstants$REQUEST_MODE$SYNC)
}, warning = function(w) {
print('Warning block called.')
}, error = function(e) {
print('Error block called.')
print(e)
}, finally = {
print('Finally block called.')
})
# print result
print(result)
# include havenondemand library
library(havenondemand)
# initialize HOD Client
client <- HODClient(apikey = "your-api-key")
result <- tryCatch({
# create client get job id
r <- client$postRequest(params =
list(flavor = 'standard', flavor = 'explorer', type = 'content', type = 'connector')
, hodApp = HODApp$LIST_RESOURCES, mode = HODClientConstants$REQUEST_MODE$ASYNC)
# get job id
jobID = r$jobID
print (jobID)
# check job status using the getJobStatus method call
# If job status is finished then getJobStatus method itself will return job data as part of response
jobStatus <- client$getJobStatus(jobID)
print (jobStatus)
# get job data using the getJobResult method
jobResult <- client$getJobResult(jobID = jobID)
print(jobResult)
}, warning = function(w) {
print('Warning block called.')
}, error = function(e) {
print('Error block called.')
print(e)
}, finally = {
print('Finally block called.')
})
# print result
print(result)
# include havenondemand library
library(havenondemand)
# initialize HOD Client
client <- HODClient(apikey = "your-api-key")
result <- tryCatch({
# create client get job id
# upload a file named 'broch.pdf' in drive c: (windows os), adjust path to your os / file name.
r <- client$postRequest(params = list(
file = httr::upload_file("c:/broch.pdf"),
file = httr::upload_file("c:/HP_License_terms_may2012.doc"))
, hodApp = HODApp$TEXT_EXTRACTION, mode = HODClientConstants$REQUEST_MODE$ASYNC)
# get job id
jobID = r$jobID
print (jobID)
# check job status using the getJobStatus method call
# If job status is finished then getJobStatus method itself will return job data as part of response
jobStatus <- client$getJobStatus(jobID)
print (jobStatus)
# get job data using the getJobResult method
jobResult <- client$getJobResult(jobID = jobID)
print(jobResult)
}, warning = function(w) {
print('Warning block called.')
}, error = function(e) {
print('Error block called.')
print(e)
}, finally = {
print('Finally block called.')
})
# print result
print(result)
This code illustrates how to create, add to, and query index. This code is also explained in the Wiki: https://github.com/chok68/havenondemand-r/wiki/Hello-World-R-Script
# include havenondemand library
library(havenondemand)
# initialize HOD Client
client <- HODClient(apikey = "your-api-key")
result <- tryCatch({
# STEP 1: call create text index (this call is required
# one time only per index life)
client$postRequest(params = list(index = "myindex", flavor = "explorer"), hodApp = HODApp$CREATE_TEXT_INDEX,
mode = HODClientConstants$REQUEST_MODE$SYNC)
# STEP 2: call add to text index (we're indexing this entry:
# https://en.wikipedia.org/wiki/Hewlett_Packard_Enterprise_Software
client$postRequest(params = list(url = "https://en.wikipedia.org/wiki/Hewlett_Packard_Enterprise_Software",
index = "myindex"), hodApp = HODApp$ADD_TO_TEXT_INDEX, mode = HODClientConstants$REQUEST_MODE$SYNC)
# STEP 3: call add to text index (we're indexing this entry:
# https://en.wikipedia.org/wiki/HP_Information_Management_Software
client$postRequest(params = list(url = "https://en.wikipedia.org/wiki/HP_Information_Management_Software",
index = "myindex"), hodApp = HODApp$ADD_TO_TEXT_INDEX, mode = HODClientConstants$REQUEST_MODE$SYNC)
# STEP 4: query text index
r <- client$postRequest(params = list(text = "their applications and databases are growing",
indexes = "myindex"), hodApp = HODApp$QUERY_TEXT_INDEX, mode = HODClientConstants$REQUEST_MODE$SYNC)
d = r$documents
# STEP 5: show the reference (for document index=1) that matched our search
print(d[[1]]$reference)
}, warning = function(w) {
print('Warning block called.')
}, error = function(e) {
print('Error block called.')
print(e)
}, finally = {
print('Finally block called.')
})
All the calls call stop(message) if an error is detected:
# include havenondemand library
library(havenondemand)
# initialize HOD Client
client <- HODClient(apikey = "your-api-key")
# call that result in error ('ur' parameter is wrong, it should be 'url')
result <- tryCatch({
client$postRequest(params = list(ur = "https://www.havenondemand.com/sample-content/videos/hpnext.mp4"), hodApp = "recognizespeech", mode = "aSyNc")
}, warning = function(w) {
print('Warning block called.')
}, error = function(e) {
print('Error block called.')
print(e)
}, finally = {
print('Finally block called.')
})
# calls POST Request
#
# @param params params to be passed
# @param hodApp end point to be called
# @param mode sync/async
# @return json response
postRequest = function(params, hodApp, mode)
# Get status of the job submitted
# @param jobId id of the job submitted
getJobStatus = function(jobID)
# Get result of the job submitted
# @param jobId id of the job submitted
getJobResult = function(jobID)
We encourage you to contribute to this repo! Please send pull requests with modified and updated code.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.