Skip to content

Commit

Permalink
Merge pull request #1046 from ajdapretnar/annot-heuristics
Browse files Browse the repository at this point in the history
OWAnnotator: add heuristics for choosing the right x and y
  • Loading branch information
VesnaT authored Mar 21, 2024
2 parents 6c692b4 + a399811 commit 7456311
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 9 additions & 2 deletions orangecontrib/text/widgets/owannotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions orangecontrib/text/widgets/tests/test_owannotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7456311

Please sign in to comment.