tommy.controller.graph_controller.GraphController

class tommy.controller.graph_controller.GraphController[source]

Bases: object

The central interface for extracting results from topic modelling results and creating visualizations. Contains an event for when the plots are changed and a publisher for when the topics have changed.

NX_EXPORTS: list[NxExporterOnData | NxExporter] = [<tommy.controller.visualizations.document_topic_nx_exporter.DocumentTopicNxExporter object>, <tommy.controller.visualizations.word_topic_nx_exporter.WordTopicNxExporter object>]
VISUALIZATIONS: list[AbstractVisualization] = [<tommy.controller.visualizations.document_word_count_creator.DocumentWordCountCreator object>, <tommy.controller.visualizations.k_value_creator.KValueCreator object>, <tommy.controller.visualizations.documents_over_time_creator.DocumentsOverTimeCreator object>, <tommy.controller.visualizations.sum_topics_in_documents.SumTopicsInDocuments object>, <tommy.controller.visualizations.correlation_matrix_creator.CorrelationMatrixCreator object>, <tommy.controller.visualizations.word_topic_network_creator.WordTopicNetworkCreator object>, <tommy.controller.visualizations.document_topic_network_summary_creator.DocumentTopicNetworkSummaryCreator object>, <tommy.controller.visualizations.word_cloud_creator.WordCloudCreator object>, <tommy.controller.visualizations.top_words_bar_plot_creator.TopWordsBarPlotCreator object>, <tommy.controller.visualizations.documents_over_time_per_topic_creator.DocumentsOverTimePerTopicCreator object>, <tommy.controller.visualizations.welcome_screen.WelcomeScreen object>]
__init__() None[source]

Initialize the graph-controller and its two publishers

clear_graphs(_)[source]

Clear all graphs when the input folder path changes

get_all_nx_exports() list[NxExport][source]

Get all the networkx graphs for the possible visualization for the current run :return: A list of nx.graph objects of all possible visualizations

get_all_visualizations(ignore_cache: bool = False) list[MatplotLibExport][source]

Get all the possible visualization for the current run :param ignore_cache: Whether to ignore the cache and always create a

new figure, defaults to False

Returns:

A list of matplotlib Figures of all possible visualizations

get_model_type() str[source]

Get the model type in the topic modelling results :return: the model type in the topic modelling results :raises RuntimeError: if the topic runner has not finished running yet.

get_number_of_topics() int[source]

Get the number of topics in the topic modelling results :return: the number of topics in the topic modelling results :raises RuntimeError: if the topic runner has not finished running yet.

get_topic_name(topic_index: int) str[source]

Get the name of the topic with the given index :param topic_index: The index of the topic :return: The name of the topic

get_topic_with_scores(topic_id, n_words) TopicWithScores[source]

Return a topic object containing top n terms and their corresponding score for the topic identified by the topic_id.

Parameters:
  • topic_id – the index of the requested topic

  • n_words – number of terms in the resulting topic object

Returns:

topic object containing top n terms and their corresponding scores

get_visualization(vis_index: int, override_topic: int | None = None, ignore_cache: bool = False) tuple[Figure, str][source]

Returns the visualization corresponding to the given index in the list of all visualizations. :param vis_index: Index of the visualization to be requested :param override_topic: A topic index used to override the selected

topic, default to None, which doesn’t override the selected topic

Parameters:

ignore_cache – Whether to ignore the cache and always create a new figure, defaults to False

Returns:

matplotlib figure of visualization corresponding to the index

and the type of the visualization :raises IndexError: if the index is negative or bigger than the number

of visualizations or if the visualization corresponding to that index is not possible in the current topic model.

property has_topic_runner: bool
on_model_swap()[source]

Notify the frontend that the topic name model has changed

on_new_topic_runner(topic_runner: TopicRunner) None[source]

Signal the graph-controller that a topic runner has finished training and is ready to provide results. Notify the subscribes of the plots and topics :param topic_runner: The newly trained topic runner object :return: None

on_topic_runner_switched(topic_runner: TopicRunner) None[source]

Signal the graph-controller that a topic runner has been switched :param topic_runner: The newly trained topic runner object :return: None

property possible_plots_changed_event: EventHandler[list[PossibleVisualization]]

Get event that triggers when the list of possible plots changes.

property refresh_name_event: EventHandler[None]

Get the event that triggers when the config name changes.

property refresh_plots_event: EventHandler[None]

Get the event that triggers when the content of any plots changes.

reset_graph_view_state() None[source]

Reset the state of the graph view

set_controller_refs(topic_modelling_controller: TopicModellingController, corpus_controller: CorpusController, project_settings_controller: ProjectSettingsController) None[source]

Set reference to the TM controller corpus controller and add self to model trained event

set_model_refs(topic_name_model: TopicNameModel) None[source]

Set the reference to the topic name model :param topic_name_model: The topic name model :return: None

set_selected_topic(topic_index: int | None) None[source]

Set the currently selected topic to the given index or None if no topic is to be selected.

Parameters:

topic_index – the index of the topic to select

Returns:

None

set_topic_name(topic_index: int, name: str) None[source]

Set the name of the topic with the given index :param topic_index: The index of the topic :param name: The new name of the topic :return: None

property topics_changed_event: EventHandler[None]

Get the eventhandler that triggers when the topics are changed.

visualizations_available() bool[source]

Check if there are any visualizations available for the current topic model. :return: True if there are visualizations available, False otherwise