diff --git a/orangecontrib/text/widgets/owwordcloud.py b/orangecontrib/text/widgets/owwordcloud.py index c1cb25766..fc1b8a6b4 100644 --- a/orangecontrib/text/widgets/owwordcloud.py +++ b/orangecontrib/text/widgets/owwordcloud.py @@ -17,6 +17,7 @@ from Orange.widgets.widget import Input, Output, OWWidget from orangecontrib.text.corpus import Corpus from orangecontrib.text.topics import Topic +from orangecontrib.text.widgets.utils.words import create_words_table COLORS = ["#da1", "#629", "#787"] GRAY_COLORS = ["#000", "#444", "#777", "#aaa"] @@ -477,16 +478,12 @@ def commit(self): out = self.corpus[rows] self.Outputs.corpus.send(out) - topic = None + words_table = None words = list(self.selected_words) if words: - topic = Topic.from_numpy( - Domain([], metas=[StringVariable("Words")]), - X=np.empty((len(words), 0)), - metas=np.c_[words].astype(object), - ) - topic.name = "Selected Words" - self.Outputs.selected_words.send(topic) + words_table = create_words_table(words) + words_table.name = "Selected Words" + self.Outputs.selected_words.send(words_table) def send_report(self): if self.webview: diff --git a/orangecontrib/text/widgets/tests/test_owwordcloud.py b/orangecontrib/text/widgets/tests/test_owwordcloud.py index 237416fe3..03f846089 100644 --- a/orangecontrib/text/widgets/tests/test_owwordcloud.py +++ b/orangecontrib/text/widgets/tests/test_owwordcloud.py @@ -1,8 +1,7 @@ import unittest import numpy as np -import pkg_resources - +from AnyQt.QtCore import QItemSelectionModel from Orange.widgets.tests.base import WidgetTest from Orange.data import StringVariable, Domain from scipy.sparse import csr_matrix @@ -155,6 +154,20 @@ def test_no_tokens(self): self.send_signal(self.widget.Inputs.corpus, self.corpus) self.wait_until_finished() + def test_select_words_output(self): + self.send_signal(self.widget.Inputs.corpus, self.corpus) + self.assertIsNone(self.get_output(self.widget.Outputs.selected_words)) + + mode = QItemSelectionModel.Rows | QItemSelectionModel.Select + view = self.widget.tableview + view.clearSelection() + view.selectionModel().select(self.widget.tablemodel.index(2, 0), mode) + view.selectionModel().select(self.widget.tablemodel.index(3, 0), mode) + + output = self.get_output(self.widget.Outputs.selected_words) + self.assertEqual(2, len(output)) + self.assertEqual("words", output.domain["Words"].attributes["type"]) + if __name__ == "__main__": unittest.main()