Пример #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])
Пример #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])
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    def init_attribute(self, attribute_name):
        """Create attribute instance

        Parameter
        ---------
        attribute_name : string
            Contains the feature name, to create an attribute
            instance.
        """
        if attribute_name == "bag_of_words":
            attribute = BagOfWords(self.bow_model)
            return attribute
        elif attribute_name == "tf_idf":
            attribute = TfIdf(self.bow_model)
            return attribute
        elif attribute_name == "readability":
            attribute = Readability()
            return attribute
        elif attribute_name == "variety":
            attribute = Variety()
            return attribute
        elif attribute_name == "perfect_tense":
            attribute = PerfectTense()
            return attribute
        elif attribute_name == "nested_sentence":
            attribute = NestedSentence()
            return attribute
        elif attribute_name == "passive":
            attribute = Passive()
            return attribute
        elif attribute_name == "adjective":
            attribute = Adjective()
            return attribute
        elif attribute_name == "sentence_start":
            attribute = SentenceStart()
            return attribute
        elif attribute_name == "bag_of_pos":
            attribute = BagOfPos(self.bow_model)
            return attribute
        elif attribute_name == "modal_verb":
            attribute = ModalVerb()
            return attribute
        else:
            raise FeatureNotExistException(attribute_name)