-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
287cf2c
commit 4e19fd3
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import unittest | ||
|
||
from AnyQt.QtCore import Qt | ||
from Orange.widgets.tests.base import WidgetTest | ||
|
||
from orangecontrib.text import Corpus | ||
from orangecontrib.text import preprocess | ||
from orangecontrib.text.widgets.owcollocations import OWCollocations | ||
|
||
|
||
class TestOWCollocations(WidgetTest): | ||
|
||
def setUp(self) -> None: | ||
self.widget: OWCollocations = self.create_widget(OWCollocations) | ||
|
||
# create corpus | ||
self.corpus = Corpus.from_file("book-excerpts") | ||
|
||
def test_set_data(self): | ||
self.send_signal(self.widget.Inputs.corpus, self.corpus) | ||
output = self.get_output(self.widget.Outputs.corpus) | ||
self.assertEqual(len(self.widget.collModel), 20) | ||
self.assertEqual(len(output), 69309) | ||
|
||
def test_preprocessed(self): | ||
pp_list = [ | ||
preprocess.LowercaseTransformer(), | ||
preprocess.PunktSentenceTokenizer(), | ||
preprocess.SnowballStemmer(), | ||
] | ||
for p in pp_list: | ||
self.pp_corpus = p(self.corpus) | ||
|
||
self.send_signal(self.widget.Inputs.corpus, self.pp_corpus) | ||
self.assertEqual(len(self.widget.collModel), 20) | ||
|
||
def test_trigrams(self): | ||
model = self.widget.collModel | ||
self.send_signal(self.widget.Inputs.corpus, self.corpus) | ||
bigram = len(self.widget.collModel[0][0].split(" ")) | ||
|
||
# trigrams | ||
self.widget.controls.type_index.buttons[1].click() | ||
trigram = len(self.widget.collModel[0][0].split(" ")) | ||
|
||
self.assertGreater(trigram, bigram) | ||
|
||
def test_change_scorer(self): | ||
model = self.widget.collModel | ||
self.send_signal(self.widget.Inputs.corpus, self.corpus) | ||
self.assertEqual(len(model[0]), 2) | ||
|
||
for i, _ in enumerate(self.widget.controls.selected_method.buttons): | ||
self.widget.controls.selected_method.buttons[i].click() | ||
self.assertTrue(self.widget.Outputs.corpus) | ||
|
||
def test_sort_table(self): | ||
"""Test that sorting the table for one method doesn't crash the | ||
widget when changing method""" | ||
view = self.widget.collView | ||
self.send_signal(self.widget.Inputs.corpus, self.corpus) | ||
score = self.widget.collModel[0][1] | ||
|
||
view.horizontalHeader().setSortIndicator(0, Qt.AscendingOrder) | ||
|
||
# change method | ||
self.widget.controls.selected_method.buttons[1].click() | ||
self.assertNotEqual(self.widget.collModel[0][1], score) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |