def setUpClass(cls): tokenizer = Tokenizer() cls.bj = bag_jag() cls.bd0 = bag_dict().read(tokenizer, { '_id': '0', 'title': 'テストデータ', 'body': 'テスト', 'anchor': 'モニタ', }) cls.bj.append(cls.bd0) cls.bd1 = bag_dict().read(tokenizer, { '_id': '1', 'title': 'テストデータ', 'body': 'テスト', }) cls.bj.append(cls.bd1) cls.bd2 = bag_dict().read(tokenizer, { '_id': '2', 'body': 'テスト', }) cls.bj.append(cls.bd2) cls.bd3 = bag_dict().read(tokenizer, { '_id': '3', }) cls.bj.append(cls.bd3) cls.query = bag_of_words() cls.query['テスト'] = 1 cls.query['モニタ'] = 1
def test_bag_jag_rw_continuous(self): expect = bag_jag() bd = bag_dict().read(self.tokenizer, { '_id': 'テスト用のデータ001', '~pv': 123.0, }) expect.append(bd) d = tempfile.TemporaryDirectory() p = '%s/tmp.txt' % d.name expect.write(p) actual = bag_jag() actual.read(p) d.cleanup() self.assertEqual(expect.body, actual.body) self.assertEqual(expect.df, actual.df) self.assertTrue(123.0 not in expect.df) self.assertTrue('123.0' not in actual.df) self.assertEqual(expect.total_len, actual.total_len)
def test_bag_jag_rw(self): expect = self.bj d = tempfile.TemporaryDirectory() p = '%s/tmp.txt' % d.name expect.write(p) actual = bag_jag() actual.read(p) d.cleanup() self.assertEqual(expect.body, actual.body) self.assertEqual(expect.df, actual.df) self.assertEqual(expect.total_len, actual.total_len)
def test_weight_continuous(self): tokenizer = Tokenizer() bj = bag_jag() bd0 = bag_dict().read(tokenizer, {'~pv': 1}) bj.append(bd0) bd1 = bag_dict().read(tokenizer, {'~pv': 10}) bj.append(bd1) bd2 = bag_dict().read(tokenizer, {'~pv': 100}) bj.append(bd2) self.assertEqual((1 * 1.0), weight('ダミー', bd0, bj)) self.assertEqual((10 * 1.0), weight('ダミー', bd1, bj)) self.assertEqual((100 * 1.0), weight('ダミー', bd2, bj))
def test_bag_jag_iadd(self): bj = bag_jag() bj += self.bj bj += self.bj self.assertEqual(8, len(bj)) self.assertEqual(6, bj.df['テスト']) self.assertEqual(4, bj.df['データ']) self.assertEqual(2, bj.df['モニタ']) self.assertEqual(0, bj.df['ダミー']) self.assertEqual(8, bj.total_len['title']) self.assertEqual(6, bj.total_len['body']) self.assertEqual(2, bj.total_len['anchor'])
def setUpClass(cls): cls.tokenizer = Tokenizer() cls.bj = bag_jag() bd0 = bag_dict().read(cls.tokenizer, { 'title': 'テストデータ', 'body': 'テスト', 'anchor': 'モニタ', }) bd1 = bag_dict().read(cls.tokenizer, { 'title': 'テストデータ', 'body': 'テスト', }) bd2 = bag_dict().read(cls.tokenizer, { 'body': 'テスト', }) bd3 = bag_dict().read(cls.tokenizer, {}) cls.bj.append(bd0).append(bd1).append(bd2).append(bd3)