Skip to content

Commit

Permalink
Merge pull request #993 from PrimozGodec/statistics-fix-settings
Browse files Browse the repository at this point in the history
[FIX] Statistics - Fix settings
  • Loading branch information
PrimozGodec authored Aug 7, 2023
2 parents 9c0faca + 29811ff commit c00b1a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
12 changes: 4 additions & 8 deletions orangecontrib/text/widgets/owstatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from AnyQt.QtWidgets import QComboBox, QGridLayout, QLabel, QLineEdit, QSizePolicy

from Orange.widgets import gui
from Orange.widgets.settings import ContextSetting
from Orange.widgets.settings import Setting
from Orange.widgets.utils.concurrent import ConcurrentWidgetMixin, TaskState
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.widget import Input, Output, OWWidget
Expand All @@ -22,8 +22,8 @@
from orangecontrib.text.preprocess import (
LowercaseTransformer,
RegexpTokenizer,
PreprocessorList)
from orangecontrib.text.widgets.utils.context import AlmostPerfectContextHandler
PreprocessorList
)


def num_words(document: str, callback: Callable) -> int:
Expand Down Expand Up @@ -493,11 +493,10 @@ class Warning(OWWidget.Warning):

want_main_area = False
mainArea_width_height_ratio = None
settingsHandler = AlmostPerfectContextHandler(0.9)

# settings
default_rules = [(0, ""), (1, "")] # rules used to reset the active rules
active_rules: List[Tuple[int, str]] = ContextSetting(default_rules[:])
active_rules: List[Tuple[int, str]] = Setting(default_rules[:])
# rules active at time of apply clicked
applied_rules: Optional[List[Tuple[int, str]]] = None

Expand Down Expand Up @@ -641,10 +640,7 @@ def _sync_edit_line(self) -> None:

@Inputs.corpus
def set_data(self, corpus) -> None:
self.closeContext()
self.corpus = corpus
self.active_rules = self.default_rules[:]
self.openContext(corpus)
self.adjust_n_rule_rows()
self.result_dict = {} # empty computational results when new data
# reset old output - it also handle case with corpus == None
Expand Down
7 changes: 2 additions & 5 deletions orangecontrib/text/widgets/tests/test_owstatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,14 @@ def test_dictionary_statistics(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.assertListEqual([], list(self.widget.result_dict.keys()))

def test_context(self):
def test_settings(self):
""" Test whether context correctly restore rules """
rules = [(0, ""), (1, ""), (2, None)]
self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.widget.active_rules = rules[:]

self.send_signal(self.widget.Inputs.corpus, self.book_data)
self.assertListEqual([(0, ""), (1, "")], self.widget.active_rules)

self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.assertListEqual(rules, self.widget.active_rules)
self.assertListEqual([(0, ""), (1, ""), (2, None)], self.widget.active_rules)

def test_compute_values(self):
""" Test compute values on new data """
Expand Down

0 comments on commit c00b1a2

Please sign in to comment.