Skip to content

Instantly share code, notes, and snippets.

@erikgregorywebb
Created May 27, 2019 22:44
Show Gist options
  • Save erikgregorywebb/e1bce79d903bb50fea6948595e2be132 to your computer and use it in GitHub Desktop.
Save erikgregorywebb/e1bce79d903bb50fea6948595e2be132 to your computer and use it in GitHub Desktop.
# define functions
uClassifyURL = function(key, classifierName, text) {
text = gsub(" ", "+", text)
url = sprintf("https://api.uclassify.com/v1/uClassify/%s/classify/?readKey=%s&text=%s", classifierName, key, text)
return(url)
}
categoryMatch = function(url) {
raw = httr::GET(url)
content = rawToChar(raw$content)
categories = fromJSON(content) %>% stack() %>% mutate(ind = as.character(ind)) %>%
arrange(desc(values)) %>% pull(ind)
return(categories)
}
# demo use
text = "a deodorizer for both breath and hands"
url = uClassifyURL('39POGBwKCbXf', 'business-topics', text)
url = uClassifyURL('39POGBwKCbXf', 'topics', text)
categories = categoryMatch(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment