MCPcopy Index your code
hub / github.com/clips/pattern / test_sentiment

Method test_sentiment

test/test_nl.py:243–261  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

241 pass
242
243 def test_sentiment(self):
244 # Assert < 0 for negative adjectives and > 0 for positive adjectives.
245 self.assertTrue(nl.sentiment("geweldig")[0] > 0)
246 self.assertTrue(nl.sentiment("verschrikkelijk")[0] < 0)
247 # Assert the accuracy of the sentiment analysis.
248 # Given are the scores for 3,000 book reviews.
249 # The baseline should increase (not decrease) when the algorithm is modified.
250 from pattern.db import Datasheet
251 from pattern.metrics import test
252 reviews = []
253 for score, review in Datasheet.load(os.path.join(PATH, "corpora", "polarity-nl-bol.com.csv")):
254 reviews.append((review, int(score) > 0))
255 A, P, R, F = test(lambda review: nl.positive(review), reviews)
256 #print A, P, R, F
257 self.assertTrue(A > 0.818)
258 self.assertTrue(P > 0.790)
259 self.assertTrue(R > 0.867)
260 self.assertTrue(F > 0.827)
261 print "pattern.nl.sentiment()"
262
263#---------------------------------------------------------------------------------------------------
264

Callers

nothing calls this directly

Calls 3

testFunction · 0.90
loadMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected