Created
May 27, 2019 22:44
-
-
Save erikgregorywebb/e1bce79d903bb50fea6948595e2be132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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