Skip to content

Commit

Permalink
Word cloud - add type to the selected words output
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Jun 21, 2022
1 parent 5523d02 commit fa936e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
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()

0 comments on commit fa936e5

Please sign in to comment.