From 5c7047690dd0d2a024156ed56bd913be8e469367 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 11 Oct 2018 11:11:38 -0400 Subject: [PATCH] adding sent analysis endpt and test --- dandelion/datatxt.py | 5 +++++ docs/datatxt.rst | 18 ++++++++++++++++++ tests/datatxt.py | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/dandelion/datatxt.py b/dandelion/datatxt.py index be173dd..23194f7 100644 --- a/dandelion/datatxt.py +++ b/dandelion/datatxt.py @@ -23,5 +23,10 @@ def li(self, text, **params): dict(params, text=text), ('li', 'v1') ) + def sent(self, text, **params): + return self.do_request( + dict(params, text=text), ('sent', 'v1') + ) + def _get_uri_tokens(self): return 'datatxt', diff --git a/docs/datatxt.rst b/docs/datatxt.rst index dcab68e..ac716bd 100644 --- a/docs/datatxt.rst +++ b/docs/datatxt.rst @@ -81,3 +81,21 @@ You can identify the language of a text with:: 'timestamp': '2042-01-01T01:02:03'} Check out the `dataTXT-LI documentation on dandelion.eu`_. + + +SENT: Sentiment Analysis +--------------------------- +dataTXT-SENT is a sentiment analysis API that analyses a text and tells whether the expressed opinion is positive, negative, or neutral. Given a short sentence, it returns a label representing the identified sentiment, along with a numeric score ranging from strongly positive (1.0) to extremely negative (-1.0). + +You can identify the sentiment of a text with:: + + >>> datatxt.sent('I really love your APIs') + {"sentiment": { + "type": "positive", + "score": 0.9 + }, + "lang": "en", + "time": 0, + "timestamp": "2018-10-11T14:45:15.529"} + +Check out the `dataTXT-SENT documentation on dandelion.eu`_. \ No newline at end of file diff --git a/tests/datatxt.py b/tests/datatxt.py index c8f0091..443631b 100644 --- a/tests/datatxt.py +++ b/tests/datatxt.py @@ -43,6 +43,11 @@ def test_li(self): self.assertGreater(res.detectedLangs[0].confidence, 0.9999) + def test_sent(self): + res = self.datatxt.sent("I really love your APIs") + + self.assertEqual(res.sentiment.score, 0.9) + def test_raises_on_error(self): with self.assertRaises(DandelionException): self.datatxt.nex(text=None)