Skip to content

Commit

Permalink
removes redundant selected data outputs for actor and action widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
kodymoodley committed Apr 18, 2024
1 parent e757e5e commit 5f43031
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 87 deletions.
47 changes: 6 additions & 41 deletions orangecontrib/storynavigation/widgets/OWSNActionAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
43 changes: 4 additions & 39 deletions orangecontrib/storynavigation/widgets/OWSNActorAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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(
Expand Down
8 changes: 1 addition & 7 deletions orangecontrib/storynavigation/widgets/OWSNTagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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_)
previewer.run(set_stories=corpus_, no_exit=True)

0 comments on commit 5f43031

Please sign in to comment.