From 5f43031bd22e839d547ec3a761121fb138a09a5e Mon Sep 17 00:00:00 2001 From: "kody.moodley@gmail.com" Date: Thu, 18 Apr 2024 21:43:27 +0200 Subject: [PATCH] removes redundant selected data outputs for actor and action widgets --- .../widgets/OWSNActionAnalysis.py | 47 +++---------------- .../widgets/OWSNActorAnalysis.py | 43 ++--------------- .../storynavigation/widgets/OWSNTagger.py | 8 +--- 3 files changed, 11 insertions(+), 87 deletions(-) diff --git a/orangecontrib/storynavigation/widgets/OWSNActionAnalysis.py b/orangecontrib/storynavigation/widgets/OWSNActionAnalysis.py index f7d325c..0bcbbda 100644 --- a/orangecontrib/storynavigation/widgets/OWSNActionAnalysis.py +++ b/orangecontrib/storynavigation/widgets/OWSNActionAnalysis.py @@ -321,12 +321,12 @@ class Inputs: story_elements = Input("Story elements", Table) class Outputs: - selected_story_results = Output("Action stats: selected", Table) - story_collection_results = Output("Action stats: all", Table) - selected_customfreq_table = Output("Custom tag stats: selected", Table) - customfreq_table = Output("Custom tag stats: all", Table) - actor_action_table_selected = Output("Action table: selected", Table) - actor_action_table_full = Output("Action table: all", Table) + # selected_story_results = Output("Action stats: selected", Table) + story_collection_results = Output("Action stats", Table) + # selected_customfreq_table = Output("Custom tag stats: selected", Table) + customfreq_table = Output("Custom tag stats", Table) + # actor_action_table_selected = Output("Action table: selected", Table) + actor_action_table_full = Output("Action table", Table) class Error(OWWidget.Error): wrong_input_for_stories = error_handling.wrong_input_for_stories @@ -567,31 +567,13 @@ def on_done(self, res : int) -> None: ) ) - self.Outputs.selected_story_results.send( - table_from_frame( - self.selected_action_results_df - ) - ) - self.Outputs.actor_action_table_full.send( table_from_frame( self.full_action_table_df ) ) - self.Outputs.actor_action_table_selected.send( - table_from_frame( - self.selected_action_table_df - ) - ) - if util.frame_contains_custom_tag_columns(self.story_elements): - self.Outputs.selected_customfreq_table.send( - table_from_frame( - self.selected_custom_freq - ) - ) - self.Outputs.customfreq_table.send( table_from_frame( self.full_custom_freq @@ -771,33 +753,16 @@ def update_selected_action_results(self): self.selected_action_results_df = self.action_results_df[self.action_results_df['storyid'].isin(selected_storyids)] self.selected_action_results_df = self.selected_action_results_df.drop(columns=['storyid']) # assume single story is selected - self.Outputs.selected_story_results.send( - table_from_frame( - self.selected_action_results_df - ) - ) - only_actions_df = self.story_elements[~self.story_elements['associated_action_lowercase'].str.contains(r'\?')] selected_only_actions_df = only_actions_df[only_actions_df['storyid'].isin(otherids)] selected_action_table_df = selected_only_actions_df.groupby(['associated_action_lowercase', 'story_navigator_tag'])[self.word_col].agg(lambda x: ', '.join(set(x))).reset_index() self.selected_action_table_df = selected_action_table_df.rename(columns={'associated_action_lowercase': 'action', 'story_navigator_tag': 'entities_type', self.word_col : 'entities'}) - self.Outputs.actor_action_table_selected.send( - table_from_frame( - self.selected_action_table_df - ) - ) - if util.frame_contains_custom_tag_columns(self.story_elements): self.custom_tags.setEnabled(True) self.selected_custom_freq = self.actiontagger.calculate_customfreq_table(self.story_elements, selected_stories=otherids) self.full_custom_freq = self.actiontagger.calculate_customfreq_table(self.story_elements, selected_stories=None) - self.Outputs.selected_customfreq_table.send( - table_from_frame( - self.selected_custom_freq - ) - ) self.Outputs.customfreq_table.send( table_from_frame( diff --git a/orangecontrib/storynavigation/widgets/OWSNActorAnalysis.py b/orangecontrib/storynavigation/widgets/OWSNActorAnalysis.py index 2ac1b52..e1bb0df 100644 --- a/orangecontrib/storynavigation/widgets/OWSNActorAnalysis.py +++ b/orangecontrib/storynavigation/widgets/OWSNActorAnalysis.py @@ -327,10 +327,10 @@ class Inputs: story_elements = Input("Story elements", Table) class Outputs: - selected_story_results = Output("Actor stats: selected", Table) - story_collection_results = Output("Actor stats: all", Table) - selected_customfreq_table = Output("Custom tag stats: selected", Table) - customfreq_table = Output("Custom tag stats: all", Table) + # selected_story_results = Output("Actor stats: selected", Table) + story_collection_results = Output("Actor stats", Table) + # selected_customfreq_table = Output("Custom tag stats: selected", Table) + customfreq_table = Output("Custom tag stats", Table) class Error(OWWidget.Error): wrong_input_for_stories = error_handling.wrong_input_for_stories @@ -781,23 +781,11 @@ def update_selected_actor_results(self): self.selected_actor_results_df = self.actor_results_df[self.actor_results_df['storyid'].isin(selected_storyids)] self.selected_actor_results_df = self.selected_actor_results_df.drop(columns=['storyid']) # assume single story is selected - self.Outputs.selected_story_results.send( - table_from_frame( - self.selected_actor_results_df - ) - ) - if util.frame_contains_custom_tag_columns(self.story_elements): self.custom_tags.setEnabled(True) self.selected_custom_freq = self.actortagger.calculate_customfreq_table(self.story_elements, selected_stories=otherids) self.full_custom_freq = self.actortagger.calculate_customfreq_table(self.story_elements, selected_stories=None) - self.Outputs.selected_customfreq_table.send( - table_from_frame( - self.selected_custom_freq - ) - ) - self.Outputs.customfreq_table.send( table_from_frame( self.full_custom_freq @@ -953,8 +941,6 @@ def on_done(self, res: int): # deal with stories that do not have entry in story elements frame if self.stories is not None: - # print("3. (on_done func): ", self.stories) - # print() domain = Domain([], metas=self.display_features) metas = [] for item in self.valid_stories: @@ -968,20 +954,7 @@ def on_done(self, res: int): ) ) - self.Outputs.selected_story_results.send( - table_from_frame( - self.selected_actor_results_df - ) - ) - if util.frame_contains_custom_tag_columns(self.story_elements): - - self.Outputs.selected_customfreq_table.send( - table_from_frame( - self.selected_custom_freq - ) - ) - self.Outputs.customfreq_table.send( table_from_frame( self.full_custom_freq @@ -993,18 +966,10 @@ def on_exception(self, ex): @gui.deferred def commit(self): - # self.pos_checkboxes = [self.sc, self.nc] - # matched = unmatched = annotated_corpus = None if self.stories is not None: selected_docs = sorted(self.get_selected_indexes()) - # matched = self.stories[selected_docs] if selected_docs else None mask = np.ones(len(self.stories), bool) mask[selected_docs] = 0 - # unmatched = self.stories[mask] if mask.any() else None - # annotated_corpus = create_annotated_table(self.stories, selected_docs) - # self.Outputs.matching_docs.send(matched) - # self.Outputs.other_docs.send(unmatched) - # self.Outputs.corpus.send(annotated_corpus) def send_report(self): self.report_items( diff --git a/orangecontrib/storynavigation/widgets/OWSNTagger.py b/orangecontrib/storynavigation/widgets/OWSNTagger.py index 0f177e4..e5479a7 100644 --- a/orangecontrib/storynavigation/widgets/OWSNTagger.py +++ b/orangecontrib/storynavigation/widgets/OWSNTagger.py @@ -28,7 +28,6 @@ class Outputs: class Error(OWWidget.Error): wrong_story_input_for_elements = error_handling.wrong_story_input_for_elements - # wrong_input_for_customtagselements = error_handling.wrong_input_for_elements residual_error = error_handling.residual_error settingsHandler = DomainContextHandler() @@ -58,7 +57,6 @@ def __init__(self): sizePolicy=QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) ) self.controlArea.layout().addWidget(self.select_language_combo) - self.select_word_column_combo = gui.comboBox( widget=self.controlArea, master=self, @@ -82,7 +80,6 @@ def __init__(self): ) self.controlArea.layout().addWidget(self.select_n_segments_combo) - self.select_language_combo.setEnabled(True) self.select_word_column_combo.setEnabled(True) self.select_n_segments_combo.setEnabled(True) @@ -195,11 +192,8 @@ def __generate_dataset_level_data(self): from orangecontrib.text.preprocess import BASE_TOKENIZER - # corpus_ = Corpus.from_file("book-excerpts") corpus_ = Corpus.from_file("orangecontrib/storynavigation/tests/storynavigator-testdata.tab") corpus_ = corpus_[:3] corpus_ = BASE_TOKENIZER(corpus_) previewer = WidgetPreview(OWSNTagger) - # breakpoint() - previewer.run(set_stories=corpus_, no_exit=True) - # WidgetPreview(OWSNTagger).run(set_stories=corpus_) \ No newline at end of file + previewer.run(set_stories=corpus_, no_exit=True) \ No newline at end of file