Skip to content

Instantly share code, notes, and snippets.

@metasyn
Created December 15, 2015 02:09
Show Gist options
  • Save metasyn/82b61e65771659ba291e to your computer and use it in GitHub Desktop.
Save metasyn/82b61e65771659ba291e to your computer and use it in GitHub Desktop.
splunk sentiment analysis with idibon
import httplib
import json
import splunk.Intersplunk
connection = httplib.HTTPConnection("localhost:8080")
results,unused1,unused2 = splunk.Intersplunk.getOrganizedResults()
for result in results:
body = json.dumps({"content": result['text']})
connection.request("GET", "/Idibon/EnglishSocialSentiment", body)
response = connection.getresponse()
res = response.read()
json_res = dict(json.loads(res[1:-1]))
result['sentiment'] = json_res['class']
result['confidence'] = json_res['confidence']
splunk.Intersplunk.outputResults(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment