Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dandelion/datatxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
18 changes: 18 additions & 0 deletions docs/datatxt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_.
5 changes: 5 additions & 0 deletions tests/datatxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down