Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output corresponding duplicate cluster #379

Merged
merged 2 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions orangecontrib/text/widgets/owduplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
36 changes: 36 additions & 0 deletions orangecontrib/text/widgets/tests/test_owduplicates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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)

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()