Пример #1
0
    def generateDataBase(self):
        """
            This function generates traning database base on list of text files

            Input:
            Nothing

            Returns:
            Training database
        """
        from database import TrainingDataBase
        from wordparser import WordParser

        database = TrainingDataBase()

        for file_path in self._file_list:
            contents = self._readFileContents(file_path)

            for line in contents.split("\n"):
                data = line.split(";")
                if len(data) == 2:
                    request = WordParser(data[0]).wordsList()
                    answer = WordParser(data[1]).wordsList()
                    database.add(request, answer)

        return database
Пример #2
0
    def setUp(self):
        from trainer import Trainer
        from database import TrainingDataBase,WordDataBase,WordRecord

        self.tr_empty = Trainer(WordDataBase(),TrainingDataBase())

        wdb = WordDataBase()
        wdb.addWord(WordRecord("aaa"))
        wdb.addWord(WordRecord("bbb"))
        wdb.addWord(WordRecord("ccc"))
        tdb = TrainingDataBase()
        tdb.add([WordRecord("aaa"),WordRecord("bbb"),WordRecord("ccc")],[WordRecord("ccc"),WordRecord("bbb")])
        tdb.add([WordRecord("aaa"),WordRecord("ccc")],[WordRecord("ccc"),WordRecord("ccc")])

        self.tr_notempty = Trainer(wdb,tdb)
Пример #3
0
 def setUp(self):
     from database import TrainingDataBase
     self.db = TrainingDataBase()
Пример #4
0
class TrainingDataBaseTest(unittest.TestCase):
    def setUp(self):
        from database import TrainingDataBase
        self.db = TrainingDataBase()

    def test_add_invalidinput(self):
        from database import DataBaseException

        with self.assertRaises(DataBaseException):
            self.db.add(None,None)

    def test_add_validinput(self):
        from database import WordRecord
        self.db.add([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")],[WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")])

    def test_getAll_dbempty(self):
        data = self.db.getAll()
        self.assertEqual(data,[])

    def test_getAll_dbnotempty(self):
        from database import WordRecord
        self.db.add([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")],[WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")])
        self.db.add([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")],[WordRecord("kkk"),WordRecord("kkk"),WordRecord("kkk")])
        self.db.add([WordRecord("bbb"),WordRecord("bbb"),WordRecord("bbb")],[WordRecord("bbb"),WordRecord("bbb"),WordRecord("bbb")])
        self.db.add([WordRecord("ccc"),WordRecord("ccc"),WordRecord("ccc")],[WordRecord("ccc"),WordRecord("ccc"),WordRecord("ccc")])

        data = self.db.getAll()
        self.assertNotIn(([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")],[WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")]),data)
        self.assertIn(([WordRecord("bbb"),WordRecord("bbb"),WordRecord("bbb")],[WordRecord("bbb"),WordRecord("bbb"),WordRecord("bbb")]),data)
        self.assertIn(([WordRecord("ccc"),WordRecord("ccc"),WordRecord("ccc")],[WordRecord("ccc"),WordRecord("ccc"),WordRecord("ccc")]),data)
        self.assertIn(([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")],[WordRecord("kkk"),WordRecord("kkk"),WordRecord("kkk")]),data)

    def test_maxRequestWordCount(self):
        from database import WordRecord
        self.db.add([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc"),WordRecord("ccc")],[WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")])
        self.db.add([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")],[WordRecord("Abc"),WordRecord("abc")])
        size = self.db.maxRequestWordCount()
        self.assertEqual(size,4)

    def test_maxAnswerWordCount(self):
        from database import WordRecord
        self.db.add([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc"),WordRecord("ccc")],[WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")])
        self.db.add([WordRecord("Abc"),WordRecord("abc"),WordRecord("abc")],[WordRecord("Abc"),WordRecord("abc")])
        size = self.db.maxAnswerWordCount()
        self.assertEqual(size,3)

    def test_maxRequestWordCount_empty(self):
        size = self.db.maxRequestWordCount()
        self.assertEqual(size,0)

    def test_maxAnswerWordCount_empty(self):
        size = self.db.maxAnswerWordCount()
        self.assertEqual(size,0)