Skip to content

Instantly share code, notes, and snippets.

@rkaplan
Created April 11, 2015 04:16
Show Gist options
  • Save rkaplan/042198c5b56e37871dd8 to your computer and use it in GitHub Desktop.
Save rkaplan/042198c5b56e37871dd8 to your computer and use it in GitHub Desktop.
MetaMind Sentiment Classification: Java
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://www.metamind.io/language/classify")
httppost.setHeader("Authorization: Basic", "YOUR API KEY");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("classifier_id", 155));
nameValuePairs.add(new BasicNameValuePair("value", "This movie is so great"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
// Get data out of response
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
JSONTokener tokener = new JSONTokener(json);
JSONArray finalResult = new JSONArray(tokener);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment