def test_pos(self): """ Test post tags count - test with corpus that has no pos tags - warning raised - test with corpus that has pos tags """ self.send_signal(self.widget.Inputs.corpus, self.corpus) self._set_feature("POS tag", "NN") self.widget.apply() self.wait_until_finished() res = self.get_output(self.widget.Outputs.corpus) self.assertEqual(0, res.X.shape[1]) self.assertTrue(self.widget.Warning.not_computed.is_shown()) tagger = AveragedPerceptronTagger() result = tagger(self.corpus) self.send_signal(self.widget.Inputs.corpus, result) self._set_feature("POS tag", "NN") self.widget.apply() self.wait_until_finished() res = self.get_output(self.widget.Outputs.corpus) self.assertTupleEqual((len(self.corpus), 1), res.X.shape) np.testing.assert_array_almost_equal(res.X.flatten(), [6, 5, 4, 5]) self.assertFalse(self.widget.Warning.not_computed.is_shown())
def test_yule(self): """ Test Yule's I - complexity index. - test with corpus that has no pos tags - warning raised - test with corpus that has pos tags """ self.send_signal(self.widget.Inputs.corpus, self.corpus) self._set_feature("Yule's I") self.widget.apply() self.wait_until_finished() res = self.get_output(self.widget.Outputs.corpus) self.assertEqual(0, res.X.shape[1]) self.assertTrue(self.widget.Warning.not_computed.is_shown()) with self.corpus.unlocked(): self.corpus[1][-1] = "simple" tagger = AveragedPerceptronTagger() result = tagger(self.corpus) self.send_signal(self.widget.Inputs.corpus, result) self._set_feature("Yule's I") self.widget.apply() self.wait_until_finished() res = self.get_output(self.widget.Outputs.corpus) self.assertTupleEqual((len(self.corpus), 1), res.X.shape) # the second document will have lower complexity than the first one self.assertLess(res[1][0], res[0][0]) self.assertFalse(self.widget.Warning.not_computed.is_shown())
def setUp(self): self.pos_tagger = AveragedPerceptronTagger()