Skip to content

Commit

Permalink
Corpus widget - do not reset tokens when same features selected
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed May 9, 2022
1 parent 742396d commit 3446c32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions orangecontrib/text/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@ def set_text_features(self, feats: Optional[List[Variable]]) -> None:
raise ValueError('Feature "{}" not found.'.format(f))
if len(set(feats)) != len(feats):
raise ValueError('Text features must be unique.')
self.text_features = feats
if feats != self.text_features:
# when new features are same than before it is not required
# to invalidate tokens
self.text_features = feats
self._tokens = None # invalidate tokens
else:
self._infer_text_features()
self._tokens = None # invalidate tokens

def set_title_variable(
self, title_variable: Union[StringVariable, str, None]
Expand Down
4 changes: 2 additions & 2 deletions orangecontrib/text/widgets/owcorpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def _load_corpus(path: str, data: Table, state: TaskState) -> Corpus:
corpus = Corpus.from_table(data.domain, data)
elif path:
corpus = Corpus.from_file(path)
corpus.name = os.path.splitext(os.path.basename(path))[0]
if not hasattr(corpus, "name") or not corpus.name:
corpus.name = os.path.splitext(os.path.basename(path))[0]
return corpus

def open_file(self, path=None, data=None):
Expand Down Expand Up @@ -224,7 +225,6 @@ def _setup_title_dropdown(self):

def update_feature_selection(self):
self.Error.no_text_features_used.clear()
# TODO fix VariablesListItemView so it does not emit
# duplicated data when reordering inside a single window
def remove_duplicates(l):
unique = []
Expand Down

0 comments on commit 3446c32

Please sign in to comment.