From 43785124c18df1426847c4d9c8bf974a770f82b6 Mon Sep 17 00:00:00 2001 From: Ajda Pretnar Date: Wed, 19 Sep 2018 15:06:59 +0200 Subject: [PATCH 1/2] Output corresponding duplicate cluster --- orangecontrib/text/widgets/owduplicates.py | 13 +++++---- .../text/widgets/tests/test_owduplicates.py | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 orangecontrib/text/widgets/tests/test_owduplicates.py diff --git a/orangecontrib/text/widgets/owduplicates.py b/orangecontrib/text/widgets/owduplicates.py index 0abe3550a..f2afeaa19 100644 --- a/orangecontrib/text/widgets/owduplicates.py +++ b/orangecontrib/text/widgets/owduplicates.py @@ -228,13 +228,16 @@ def send_corpus_without_duplicates(self): self.Outputs.corpus_without_duplicates.send(None) def send_duplicates(self): - index = self.table_view.selectionModel().currentIndex().row() - cluster = self.table_model[index][0] - mask = np.flatnonzero(self.clustering_mask == cluster.id) - c = self.corpus[mask] - c.name = '{} {}'.format(self.Outputs.duplicates.name, cluster) + c = None + indices = self.table_view.selectionModel().selectedIndexes() + if indices: + cluster = self.table_view.model().data(indices[0], Qt.EditRole) + mask = np.flatnonzero(self.clustering_mask == cluster.id) + c = self.corpus[mask] + c.name = '{} {}'.format(self.Outputs.duplicates.name, cluster) self.Outputs.duplicates.send(c) + def send_report(self): self.report_items([ ('Linkage', self.LINKAGE[self.linkage_method]), diff --git a/orangecontrib/text/widgets/tests/test_owduplicates.py b/orangecontrib/text/widgets/tests/test_owduplicates.py new file mode 100644 index 000000000..52700824e --- /dev/null +++ b/orangecontrib/text/widgets/tests/test_owduplicates.py @@ -0,0 +1,27 @@ +import unittest + +from Orange.data import Table +from Orange.distance import Euclidean +from Orange.widgets.tests.base import WidgetTest + +from orangecontrib.text.widgets.owduplicates import OWDuplicates + + +class TestCorpusViewerWidget(WidgetTest): + def setUp(self): + self.widget = self.create_widget(OWDuplicates) + self.data = Table.from_file('iris') + self.distances = Euclidean(self.data) + + def test_duplicates(self): + self.send_signal(self.widget.Inputs.distances, self.distances) + self.widget.table_view.selectRow(0) + out_corpus = self.get_output(self.widget.Outputs.duplicates) + self.assertEqual(len(out_corpus), 2) + self.widget.table_view.selectRow(3) + out_corpus = self.get_output(self.widget.Outputs.duplicates) + self.assertEqual(len(out_corpus), 1) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From 1886ecb019510f55a20eef1f76106fa431ee0054 Mon Sep 17 00:00:00 2001 From: Ajda Date: Thu, 27 Sep 2018 10:39:37 +0200 Subject: [PATCH 2/2] Update test_owduplicates.py --- orangecontrib/text/widgets/tests/test_owduplicates.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/orangecontrib/text/widgets/tests/test_owduplicates.py b/orangecontrib/text/widgets/tests/test_owduplicates.py index 52700824e..55b0f3112 100644 --- a/orangecontrib/text/widgets/tests/test_owduplicates.py +++ b/orangecontrib/text/widgets/tests/test_owduplicates.py @@ -22,6 +22,15 @@ def test_duplicates(self): out_corpus = self.get_output(self.widget.Outputs.duplicates) self.assertEqual(len(out_corpus), 1) + def test_deselecting(self): + self.send_signal(self.widget.Inputs.distances, self.distances) + self.widget.table_view.selectRow(0) + out_corpus = self.get_output(self.widget.Outputs.duplicates) + self.assertTrue(out_corpus) + self.widget.table_view.clearSelection() + out_corpus = self.get_output(self.widget.Outputs.duplicates) + self.assertIsNone(out_corpus) if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() +