Skip to content

Instantly share code, notes, and snippets.

@brendandawes
Last active August 15, 2018 19:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save brendandawes/7d9fc84d94c538d8a2355daaec961a44 to your computer and use it in GitHub Desktop.
import http.requests.*;
void setup(){
size(640,640);
String txt = "The Quick Brown Fox Jumped Over the Lazy Dog";
JSONObject json = getJSONForText(txt);
PostRequest post = new PostRequest("https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19");
post.addUser(USERNAME,PASSWORD);
post.addHeader("Content-Type", "application/json");
post.addJson(json.toString());
post.send();
println(post.getContent());
}
void draw(){
}
JSONObject getJSONForText(String txt){
JSONObject json = new JSONObject();
json.setString("text",txt);
JSONObject empty = new JSONObject();
JSONObject features = new JSONObject();
features.setJSONObject("sentiment",empty);
features.setJSONObject("keywords",empty);
features.setJSONObject("emotion",empty);
json.setJSONObject("features",features);
return json;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment