Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Statistics - Fix settings #993

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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