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

Method test_sentiment

test/test_fr.py:189–207  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

187 pass
188
189 def test_sentiment(self):
190 # Assert < 0 for negative adjectives and > 0 for positive adjectives.
191 self.assertTrue(fr.sentiment("fabuleux")[0] > 0)
192 self.assertTrue(fr.sentiment("terrible")[0] < 0)
193 # Assert the accuracy of the sentiment analysis.
194 # Given are the scores for 1,500 book reviews.
195 # The baseline should increase (not decrease) when the algorithm is modified.
196 from pattern.db import Datasheet
197 from pattern.metrics import test
198 reviews = []
199 for review, score in Datasheet.load(os.path.join(PATH, "corpora", "polarity-fr-amazon.csv")):
200 reviews.append((review, int(score) > 0))
201 A, P, R, F = test(lambda review: fr.positive(review), reviews)
202 #print A, P, R, F
203 self.assertTrue(A > 0.746)
204 self.assertTrue(P > 0.756)
205 self.assertTrue(R > 0.726)
206 self.assertTrue(F > 0.741)
207 print "pattern.fr.sentiment()"
208
209 def test_tokenizer(self):
210 # Assert that french sentiment() uses French tokenizer. ("t'aime" => "t' aime").

Callers

nothing calls this directly

Calls 3

testFunction · 0.90
loadMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected