Example #1
0
 def test_sentiment(self):
     # Assert < 0 for negative adjectives and > 0 for positive adjectives.
     self.assertTrue(nl.sentiment("geweldig")[0] > 0)
     self.assertTrue(nl.sentiment("verschrikkelijk")[0] < 0)
     # Assert the accuracy of the sentiment analysis.
     # Given are the scores for 3,000 book reviews.
     # The baseline should increase (not decrease) when the algorithm is modified.
     from pattern.db import Datasheet
     from pattern.metrics import test
     reviews = []
     for score, review in Datasheet.load(os.path.join(PATH, "corpora", "polarity-nl-bol.com.csv")):
         reviews.append((review, int(score) > 0))
     A, P, R, F = test(lambda review: nl.positive(review), reviews)
     self.assertTrue(A > 0.80)
     self.assertTrue(P > 0.77)
     self.assertTrue(R > 0.85)
     self.assertTrue(F > 0.81)
     print "pattern.nl.sentiment()"
Example #2
0
 def test_sentiment(self):
     # Assert < 0 for negative adjectives and > 0 for positive adjectives.
     self.assertTrue(nl.sentiment("geweldig")[0] > 0)
     self.assertTrue(nl.sentiment("verschrikkelijk")[0] < 0)
     # Assert the accuracy of the sentiment analysis.
     # Given are the scores for 3,000 book reviews.
     # The baseline should increase (not decrease) when the algorithm is modified.
     from pattern.db import Datasheet
     from pattern.metrics import test
     reviews = []
     for score, review in Datasheet.load(os.path.join(PATH, "corpora", "polarity-nl-bol.com.csv")):
         reviews.append((review, int(score) > 0))
     A, P, R, F = test(lambda review: nl.positive(review), reviews)
     self.assertTrue(A > 0.80)
     self.assertTrue(P > 0.77)
     self.assertTrue(R > 0.85)
     self.assertTrue(F > 0.81)
     print "pattern.nl.sentiment()"