From b545ece26a4eb15b729d7339f472e5ff1ffb945a Mon Sep 17 00:00:00 2001 From: Ajda Date: Wed, 20 Mar 2024 09:04:22 +0100 Subject: [PATCH 1/2] OWAnnotator: add attribute selection heuristics --- orangecontrib/text/widgets/owannotator.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/orangecontrib/text/widgets/owannotator.py b/orangecontrib/text/widgets/owannotator.py index e3cd5f25f..5cb71511b 100644 --- a/orangecontrib/text/widgets/owannotator.py +++ b/orangecontrib/text/widgets/owannotator.py @@ -444,8 +444,15 @@ def init_attr_values(self): model = self.controls.attr_x.model() model.set_domain(domain) - self.attr_x = model[0] if model else None - self.attr_y = model[1] if len(model) >= 2 else self.attr_x + x_id = 0 + y_id = 1 + for i in range(len(model)): + if model[i].name == "t-SNE-x": + x_id = i + if model[i].name == "t-SNE-y": + y_id = i + self.attr_x = model[x_id] if model else None + self.attr_y = model[y_id] if len(model) >= 2 else (self.attr_x) model = self.controls.cluster_var.model() model.set_domain(domain) From a399811c57b68565d52942d10380944b9364e421 Mon Sep 17 00:00:00 2001 From: Ajda Date: Wed, 20 Mar 2024 11:37:18 +0100 Subject: [PATCH 2/2] Test Annotator heuristics --- .../text/widgets/tests/test_owannotator.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/orangecontrib/text/widgets/tests/test_owannotator.py b/orangecontrib/text/widgets/tests/test_owannotator.py index 19e4951d2..552659d52 100644 --- a/orangecontrib/text/widgets/tests/test_owannotator.py +++ b/orangecontrib/text/widgets/tests/test_owannotator.py @@ -197,6 +197,28 @@ def test_attr_label_metas(self): simulate.combobox_activate_item(self.widget.controls.attr_label, self.corpus.domain[-1].name) + @patch("Orange.projection.manifold.TSNE", DummyTSNE) + @patch("Orange.projection.manifold.TSNEModel", DummyTSNEModel) + def test_attr_heuristics(self): + c = Corpus.from_file("slo-opinion-corpus.tab")[:20] + + for pp in (LowercaseTransformer(), RegexpTokenizer(r"\w+"), + StopwordsFilter("sl"), FrequencyFilter(0.25, 0.5)): + corpus = pp(c) + corpus = BowVectorizer().transform(corpus) + + owtsne = self.create_widget(OWtSNE) + self.send_signal(owtsne.Inputs.data, corpus, widget=owtsne) + self.wait_until_finished(widget=owtsne) + tsne_output = self.get_output(owtsne.Outputs.annotated_data, owtsne) + + widget = self.create_widget(OWAnnotator) + self.send_signal(widget.Inputs.corpus, tsne_output) + self.wait_until_finished(widget=widget) + + self.assertEqual(widget.attr_x.name, "t-SNE-x") + self.assertEqual(widget.attr_y.name, "t-SNE-y") + def test_attr_models(self): self.send_signal(self.widget.Inputs.corpus, self.corpus[::30]) self.wait_until_finished()