(self)
| 25 | class EvalTest(tf.test.TestCase): |
| 26 | |
| 27 | def setUp(self): |
| 28 | super(EvalTest, self).setUp() |
| 29 | self.task = 'ic' |
| 30 | self.tmp_dir = self.create_tempdir().full_path + '/' |
| 31 | |
| 32 | # Construct sample KB. |
| 33 | ent0, rel0, ent1, rel1, rel2 = 0, 0, 1, 1, 2 |
| 34 | answers = { |
| 35 | ((ent0, (rel0,)), (ent1, (rel1,)), rel2): {3, 4, 5} |
| 36 | } |
| 37 | hard_answers = { |
| 38 | ((ent0, (rel0,)), (ent1, (rel1,)), rel2): {5} |
| 39 | } |
| 40 | kb = ['ent0\trel0\tent1\n', |
| 41 | 'ent2\trel1\tent3\n', |
| 42 | 'ent4\trel2\tent5\n'] |
| 43 | ent2ind = {'ent%d' % i: i for i in range(6)} |
| 44 | rel2ind = {'rel%d' % i: i for i in range(3)} |
| 45 | ind2ent = {ind: ent for ent, ind in ent2ind.items()} |
| 46 | ind2rel = {ind: rel for rel, ind in rel2ind.items()} |
| 47 | |
| 48 | # Dump to temp files. |
| 49 | pickle.dump(answers, |
| 50 | gfile.GFile(self.tmp_dir + 'test_ans_%s.pkl' % self.task, 'wb')) |
| 51 | pickle.dump( |
| 52 | hard_answers, |
| 53 | gfile.GFile(self.tmp_dir + 'test_ans_%s_hard.pkl' % self.task, 'wb')) |
| 54 | pickle.dump(ent2ind, gfile.GFile(self.tmp_dir + 'ent2ind.pkl', 'wb')) |
| 55 | pickle.dump(rel2ind, gfile.GFile(self.tmp_dir + 'rel2ind.pkl', 'wb')) |
| 56 | pickle.dump(ind2ent, gfile.GFile(self.tmp_dir + 'ind2ent.pkl', 'wb')) |
| 57 | pickle.dump(ind2rel, gfile.GFile(self.tmp_dir + 'ind2rel.pkl', 'wb')) |
| 58 | with gfile.GFile(self.tmp_dir + 'kb.txt', 'w') as f_kb: |
| 59 | for line in kb: |
| 60 | f_kb.write(line) |
| 61 | |
| 62 | def test_eval(self): |
| 63 | root_dir = self.tmp_dir |
nothing calls this directly
no outgoing calls
no test coverage detected