def top_words(): """Handles the topword page functionality. :return: a response object (often a render_template call) to flask and eventually to the browser. """ # Detect the number of active documents. num_active_docs = detect_active_docs() file_manager = FileManagerModel().load_file_manager() labels = file_manager.get_active_labels_with_id() # 'GET' request occurs when the page is first loaded if 'topwordoption' not in session: session['topwordoption'] = constants.DEFAULT_TOPWORD_OPTIONS if 'analyoption' not in session: session['analyoption'] = constants.DEFAULT_ANALYZE_OPTIONS # get the class division map. class_division_map = file_manager.get_class_division_map() return render_template( 'topword.html', itm='topwords', labels=labels, numActiveDocs=num_active_docs, classDivisionMap=class_division_map)
def topword_html(): # 'POST' request occurs when html form is submitted num_active_docs = detect_active_docs() file_manager = utility.load_file_manager() labels = file_manager.get_active_labels_with_id() # get the class division map and number of existing classes class_division_map = FileManagerModel().load_file_manager().\ get_class_division_map() num_class = class_division_map.shape[0] if 'get-topword' in request.form: # download topword path = TopwordModel().get_topword_csv_path( class_division_map=class_division_map) session_manager.cache_analysis_option() session_manager.cache_top_word_options() return send_file(path, attachment_filename=constants.TOPWORD_CSV_FILE_NAME, as_attachment=True) else: session_manager.cache_analysis_option() session_manager.cache_top_word_options() topword_result = TopwordModel().get_readable_result( class_division_map=class_division_map) return render_template('topword.html', result=topword_result.results, labels=labels, header=topword_result.header, numclass=num_class, topwordsgenerated='True', classmap=[], itm='topwords', numActiveDocs=num_active_docs)
def bct_analysis(): """Display the web page when first got to bootstrap consensus analysis. :return: The rendered template. """ # Detect the number of active documents. num_active_docs = detect_active_docs() # Get labels with their ids. id_label_map = \ FileManagerModel().load_file_manager().get_active_labels_with_id() # Fill in default options. if 'analyoption' not in session: session['analyoption'] = constants.DEFAULT_ANALYZE_OPTIONS if 'bctoption' not in session: session['bctoption'] = constants.DEFAULT_BCT_OPTIONS try: from lexos.models.bct_model import BCTModel # Use a black hole variable to hold the model to get rid of warning. _ = BCTModel() # Render the HTML template. return render_template('bct_analysis.html', itm="bct-analysis", labels=id_label_map, numActiveDocs=num_active_docs) except ImportError: return render_template('bct_analysis_import_error.html', itm="bct-analysis")
def _file_id_content_map(self) -> FileIDContentMap: """Get result from higher level class: file manager of current session. :return: a file manager object """ return self._test_file_id_content_map \ if self._test_file_id_content_map is not None \ else FileManagerModel().load_file_manager() \ .get_content_of_active_with_id()
def dendrogram(): # Detect the number of active documents. num_active_docs = detect_active_docs() if 'analyoption' not in session: session['analyoption'] = constants.DEFAULT_ANALYZE_OPTIONS if 'hierarchyoption' not in session: session['hierarchyoption'] = constants.DEFAULT_HIERARCHICAL_OPTIONS labels = FileManagerModel().load_file_manager().get_active_labels_with_id() return render_template('dendrogram.html', labels=labels, numActiveDocs=num_active_docs, itm="hierarchical")
def rolling_window(): """Handles the functionality on the rollingwindow page. It analyzes the various texts using a rolling window of analysis. :return: a response object (often a render_template call) to flask and eventually to the browser. """ # Detect the number of active documents. num_active_docs = detect_active_docs() file_manager = FileManagerModel().load_file_manager() # Get active labels with id and sort all labels. labels = file_manager.get_active_labels_with_id() labels = OrderedDict(natsorted(list(labels.items()), key=lambda x: x[1])) # Fill in the default options if the option was not already there. if 'rwoption' not in session: session['rwoption'] = constants.DEFAULT_ROLLINGWINDOW_OPTIONS # Return the rendered template. return render_template('rwanalysis.html', itm="rolling-windows", labels=labels, numActiveDocs=num_active_docs)
def _passage(self) -> str: """Get the passage to run rolling windows on. :return: the content of the passage as a string. """ # if test option is specified if self._test_file_id_content_map is not None and \ self._test_front_end_options is not None: file_id = self._test_front_end_options.passage_file_id file_id_content_map = self._test_file_id_content_map # if test option is not specified, get option from front end else: file_id = RollingWindowsReceiver().options_from_front_end() \ .passage_file_id file_id_content_map = FileManagerModel().load_file_manager() \ .get_content_of_active_with_id() return file_id_content_map[file_id]
def statistics(): """Handles the functionality on the Statistics page. :return: a response object (often a render_template call) to flask and eventually to the browser. """ # Detect the number of active documents. num_active_docs = detect_active_docs() # Get labels with their ids. id_label_map = \ FileManagerModel().load_file_manager().get_active_labels_with_id() # "GET" request occurs when the page is first loaded. if 'analyoption' not in session: session['analyoption'] = constants.DEFAULT_ANALYZE_OPTIONS return render_template('statistics.html', itm="statistics", labels=id_label_map, numActiveDocs=num_active_docs)
def similarity(): """Handles the similarity query page functionality. Returns ranked list of files and their cosine similarities to a comparison document. :return: a response object (often a render_template call) to flask and eventually to the browser. """ # Detect the number of active documents. num_active_docs = detect_active_docs() id_label_map = \ FileManagerModel().load_file_manager().get_active_labels_with_id() # 'GET' request occurs when the page is first loaded if 'analyoption' not in session: session['analyoption'] = constants.DEFAULT_ANALYZE_OPTIONS if 'similarities' not in session: session['similarities'] = constants.DEFAULT_SIM_OPTIONS return render_template( 'similarity.html', itm="similarity-query", labels=id_label_map, numActiveDocs=num_active_docs, )
def _class_division_map(self) -> pd.DataFrame: """:return: a pandas data frame that holds the class division map.""" return self._test_class_division_map \ if self._test_class_division_map is not None else \ FileManagerModel().load_file_manager().get_class_division_map()