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

[FIX] Word cloud - add type to the selected words output #868

Merged
merged 1 commit into from
Jun 21, 2022
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: 5 additions & 8 deletions orangecontrib/text/widgets/owwordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 15 additions & 2 deletions orangecontrib/text/widgets/tests/test_owwordcloud.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()