Ejemplo n.º 1
0
 def test_udpipe_no_models(self):
     editor = NormalizationModule()
     button = editor._SingleMethodModule__group.button(editor.UDPipe)
     self.assertFalse(button.isEnabled())
     combo = editor._NormalizationModule__combo_udl
     self.assertFalse(combo.isEnabled())
     check = editor._NormalizationModule__check_use
     self.assertFalse(check.isEnabled())
Ejemplo n.º 2
0
 def setUp(self):
     self.editor = NormalizationModule()
Ejemplo n.º 3
0
class TestNormalizationModule(WidgetTest):
    def setUp(self):
        self.editor = NormalizationModule()

    @property
    def buttons(self):
        return self.editor._SingleMethodModule__group.buttons()

    @property
    def combo_sbl(self):
        return self.editor._NormalizationModule__combo_sbl

    @property
    def combo_udl(self):
        return self.editor._NormalizationModule__combo_udl

    @property
    def combo_lemm(self):
        return self.editor._NormalizationModule__combo_lemm

    @property
    def check_use(self):
        return self.editor._NormalizationModule__check_use

    def test_init(self):
        self.assertTrue(self.buttons[0].isChecked())
        for i in range(1, 4):
            self.assertFalse(self.buttons[i].isChecked())
        self.assertEqual(self.combo_sbl.currentText(), "English")
        self.assertEqual(self.combo_udl.currentText(), "English")
        self.assertFalse(self.check_use.isChecked())

    def test_parameters(self):
        params = {
            "method": NormalizationModule.Porter,
            "snowball_language": "English",
            "udpipe_language": "English",
            "lemmagen_language": "English",
            "udpipe_tokenizer": False
        }
        self.assertDictEqual(self.editor.parameters(), params)

    def test_set_parameters(self):
        params = {
            "method": NormalizationModule.UDPipe,
            "snowball_language": "Dutch",
            "udpipe_language": "Finnish",
            "lemmagen_language": "Bulgarian",
            "udpipe_tokenizer": True
        }
        self.editor.setParameters(params)
        self.assertDictEqual(self.editor.parameters(), params)
        self.assertEqual(self.combo_sbl.currentText(), "Dutch")
        self.assertEqual(self.combo_udl.currentText(), "Finnish")
        self.assertEqual(self.combo_lemm.currentText(), "Bulgarian")
        self.assertTrue(self.check_use.isChecked())

    def test_createinstance(self):
        pp = self.editor.createinstance(self.editor.parameters())
        self.assertIsInstance(pp, PorterStemmer)

        params = {"method": NormalizationModule.Snowball}
        pp = self.editor.createinstance(params)
        self.assertIsInstance(pp, SnowballStemmer)
        self.assertIn("<EnglishStemmer>", str(pp.normalizer))

        params = {
            "method": NormalizationModule.Snowball,
            "snowball_language": "Dutch"
        }
        pp = self.editor.createinstance(params)
        self.assertIsInstance(pp, SnowballStemmer)
        self.assertIn("<DutchStemmer>", str(pp.normalizer))

        params = {
            "method": NormalizationModule.UDPipe,
            "udpipe_language": "Finnish",
            "udpipe_tokenizer": True
        }
        pp = self.editor.createinstance(params)
        self.assertIsInstance(pp, UDPipeLemmatizer)
        self.assertEqual(pp._UDPipeLemmatizer__language, "Finnish")
        self.assertEqual(pp._UDPipeLemmatizer__use_tokenizer, True)

    def test_repr(self):
        self.assertEqual(str(self.editor), "Porter Stemmer")

    @patch("orangecontrib.text.preprocess.normalize.UDPipeModels.online",
           PropertyMock(return_value=False))
    @patch("orangecontrib.text.preprocess.normalize.UDPipeModels.model_files",
           PropertyMock(return_value=[]))
    def test_udpipe_no_models(self):
        editor = NormalizationModule()
        button = editor._SingleMethodModule__group.button(editor.UDPipe)
        self.assertFalse(button.isEnabled())
        combo = editor._NormalizationModule__combo_udl
        self.assertFalse(combo.isEnabled())
        check = editor._NormalizationModule__check_use
        self.assertFalse(check.isEnabled())