Beispiel #1
0
class BagOfWordsTest(TestBodyAttribute):
    @classmethod
    def setUpClass(cls):
        print "###################### Begin Testing BagOfWords Class ######################" + "\n"

    @classmethod
    def tearDownClass(cls):
        print "\n" + "###################### End Testing BagOfWords Class ######################"

    def setUp(self):
        test_name = self.shortDescription()
        self.token_list = res.token_list
        super(BagOfWordsTest, self).setUp()

        if test_name == "Test routine build_model() in BagOfWords":
            print "setting up for testing build_model()"
            self.mock_obj = BagOfWords()
            self.mock_obj._text_set = self.test_data.r_D_text_set
            self.mock_obj.build_model()

        elif test_name == "Test routine compute() in BagOfWords":
            print "setting up for testing compute()"

            self.test_data.attach_feature("bag_of_words")
            self.term_freq = res.term_frequency

    def tearDown(self):
        test_name = self.shortDescription()

        self.korpus_file = None
        self.anno_file = None
        self.test_korpus = None
        self.test_data = None
        self.token_list = None

        if test_name == "Test routine build_model() in BagOfWords":
            print "cleaning up for testing build_model()"
            self.mock_obj = None
            print "--------------------------------------------------------------"

        elif test_name == "Test routine compute() in BagOfWords":
            print "cleaning up for testing compute()"
            self.term_freq = None
            print "--------------------------------------------------------------"

    def test__bag_of_words__build_model(self):
        """ Test routine build_model() in BagOfWords """

        self.assertListEqual(sorted(self.token_list),
                             sorted(self.mock_obj.model.keys()))

    def test__bag_of_words__compute(self):
        """ Test routine compute() in BagOfWords """

        for textpair in self.test_data.real_data.values():
            self.assertListEqual(textpair.text1.features["bag_of_words"],
                                 self.term_freq[textpair.text1.id])
            self.assertListEqual(textpair.text2.features["bag_of_words"],
                                 self.term_freq[textpair.text2.id])
Beispiel #2
0
class BagOfWordsTest(TestBodyAttribute):
    @classmethod
    def setUpClass(cls):
        print "###################### Begin Testing BagOfWords Class ######################" + "\n"

    @classmethod
    def tearDownClass(cls):
        print "\n" + "###################### End Testing BagOfWords Class ######################"

    def setUp(self):
        test_name = self.shortDescription()
        self.token_list = res.token_list
        super(BagOfWordsTest, self).setUp()

        if test_name == "Test routine build_model() in BagOfWords":
            print "setting up for testing build_model()"
            self.mock_obj = BagOfWords()
            self.mock_obj._text_set = self.test_data.r_D_text_set
            self.mock_obj.build_model()

        elif test_name == "Test routine compute() in BagOfWords":
            print "setting up for testing compute()"

            self.test_data.attach_feature("bag_of_words")
            self.term_freq = res.term_frequency

    def tearDown(self):
        test_name = self.shortDescription()

        self.korpus_file = None
        self.anno_file = None
        self.test_korpus = None
        self.test_data = None
        self.token_list = None

        if test_name == "Test routine build_model() in BagOfWords":
            print "cleaning up for testing build_model()"
            self.mock_obj = None
            print "--------------------------------------------------------------"

        elif test_name == "Test routine compute() in BagOfWords":
            print "cleaning up for testing compute()"
            self.term_freq = None
            print "--------------------------------------------------------------"

    def test__bag_of_words__build_model(self):
        """ Test routine build_model() in BagOfWords """

        self.assertListEqual(sorted(self.token_list), sorted(self.mock_obj.model.keys()))

    def test__bag_of_words__compute(self):
        """ Test routine compute() in BagOfWords """

        for textpair in self.test_data.real_data.values():
            self.assertListEqual(textpair.text1.features["bag_of_words"], self.term_freq[textpair.text1.id])
            self.assertListEqual(textpair.text2.features["bag_of_words"], self.term_freq[textpair.text2.id])