Esempio n. 1
0
    def runTest(self):
        # empty list
        ds = sentdoc.PottsDocSentiScore()
        L = sentlex.MobyLexicon()
        ds.verbose = True
        ds.set_lexicon(L)

        negated_sent = 'not/DT good/JJ'

        ds.set_active_pos(True, False, False, False)
        ds.set_parameters(negation=True, negation_window=15)
        (dpos, dneg) = ds.classify_document(negated_sent)
        self.assertTrue(dneg > dpos, 'Negation did not invert scores.')

        ds.set_parameters(negation=True,
                          negation_window=15,
                          atenuation=True,
                          at_pos=0.5,
                          at_neg=0.5)
        (dpos, dneg) = ds.classify_document(negated_sent)
        ds.set_parameters(negation=True,
                          negation_window=15,
                          atenuation=True,
                          at_pos=1.0,
                          at_neg=1.0)
        (dposfull, dnegfull) = ds.classify_document(negated_sent)
        self.assertTrue(dpos > dneg, 'Negation did not atenuate scores.')
        self.assertTrue(dposfull > dpos, 'Negation did not atenuate scores.')
Esempio n. 2
0
def ds(moby):
    ds = sentdoc.PottsDocSentiScore()
    ds.verbose = False
    ds.set_lexicon(moby)
    ds.set_parameters(a=True,
                      v=False,
                      n=False,
                      r=False,
                      negation=True,
                      negation_window=15,
                      negation_adjustment=0.5)
    return ds
    def runTest(self):
        # load lexicon
        L = sentlex.MobyLexicon()
        self.assertTrue(L.is_loaded, 'Test lexicon did not load correctly')

        # create a class that scores only adjectives
        ds = sentdoc.PottsDocSentiScore()
        ds.verbose = True
        ds.set_active_pos(True, False, False, False)
        ds.set_parameters(score_mode=ds.SCOREALL,
                          score_freq=False,
                          negation=True,
                          negation_adjustment=0.5)
        ds.set_lexicon(L)

        # separator ok?
        self.assertEqual(ds._detect_tag(TESTDOC_ADJ), '/',
                         'Unable to detect correct separator')

        # now score!
        (dpos, dneg) = ds.classify_document(TESTDOC_ADJ, verbose=True)
        self.assertTrue(ds.resultdata and ds.resultdata.has_key('doc') and ds.resultdata.has_key('annotated_doc')\
            and ds.resultdata.has_key('resultpos') and ds.resultdata.has_key('resultneg'), 'Did not populate resultdata after scoring doc')

        self.assertTrue(dpos > 0.0,
                        'Did not find positive words on positive doc')
        print 'TESTDOC_ADJ (pos,neg): %2.2f %2.2f' % (dpos, dneg)

        # again, for negative text
        (dpos, dneg) = ds.classify_document(TESTDOC_BADADJ, verbose=True)
        self.assertTrue(dneg > 0.0,
                        'Did not find negative words on negative doc')
        print 'TESTDOC_BADADJ (pos,neg): %2.2f %2.2f' % (dpos, dneg)

        # negated text
        ds.set_neg_detection(True, 5)
        (dpos, dneg) = ds.classify_document(TESTDOC_NEGATED, verbose=True)
        self.assertTrue(dpos > 0.0,
                        'Did not find positive words on TESTDOC_NEGATED')
        print 'TESTDOC_NEGATED (pos,neg): %2.2f %2.2f' % (dpos, dneg)

        # currupt data - should still work
        (dpos, dneg) = ds.classify_document(TESTDOC_CORRUPT, verbose=True)
        self.assertTrue(dpos > dneg,
                        'Did not process corrupt document correctly')
Esempio n. 4
0
    def runTest(self):
        # empty list
        ds = sentdoc.PottsDocSentiScore()
        ds.verbose = False

        ds.set_active_pos(True, False, False, False)
        ds.set_parameters(negation_adjustment=0.5,
                          negation=True,
                          negation_window=15)

        self.assertEqual((ds.a, ds.v, ds.n, ds.r), (True, False, False, False),
                         'Failed set POS parameters')
        self.assertEqual((ds.negation, ds.negation_window), (True, 15),
                         'Failed set negation')

        ds.set_parameters(score_mode=ds.SCOREONCE, score_freq=True)
        self.assertEqual(ds.score_mode, ds.SCOREONCE,
                         'Unable to set parameters via kwards')
        self.assertEqual(ds.score_freq, True,
                         'Unable to set parameters via kwards')