def get_author_details(): if request.method == 'GET': author_id = request.args.get('author_id') doc_num = request.args.get('doc_num') if author_id is None and doc_num is None: return render_template('data_visualize/select_author.html', title='Select an author', content=u'Select an author in the following list and the system will display the ' u'details of that author you selected', authors_list=data_warehouse.get_all_author_id_and_name() ) if request.method == 'POST': try: author_id = int(request.form['author_id']) doc_num = data_warehouse.get_num_of_doc_written_by_an_author(author_id) except ValueError: abort(403) try: author_id = int(author_id) doc_num = int(doc_num) except ValueError: abort(403) author_name = data_warehouse.get_author_name_by_id(author_id) return render_template('data_visualize/author_details.html', title=author_name, content=Markup(u'You are now looking at <strong>{}</strong>. There are <strong>{}</strong> ' u'of documents written by {} stored in our database.' .format(author_name, doc_num, author_name)), doc_list=data_warehouse.get_all_docs_by_author_id(author_id) )
def get_author_details(): if request.method == 'GET': author_id = request.args.get('author_id') doc_num = request.args.get('doc_num') if author_id is None and doc_num is None: return render_template('data_visualize/select_author.html', title='Select an author', content=u'Select an author in the following list and the system will display the ' u'details of that author you selected', authors_list=data_warehouse.get_all_author_id_and_name() ) if request.method == 'POST': try: author_id = int(request.form['author_id']) doc_num = data_warehouse.get_num_of_doc_written_by_an_author(author_id) except ValueError: abort(403) try: author_id = int(author_id) doc_num = int(doc_num) except ValueError: abort(403) author_name = data_warehouse.get_author_name_by_id(author_id) return render_template('data_visualize/author_details.html', title=author_name, content=Markup(u'You are now looking at <strong>{}</strong>. There are <strong>{}</strong> ' u'of documents written by {} stored in our database.' .format(author_name, doc_num, author_name)), doc_list=data_warehouse.get_all_docs_by_author_id(author_id) )
def get_knn_statics(): if request.method != 'POST': abort(403) results = [] prefix_path = '/var/tmp/stylometric_app/knn_upload/' f = request.files['file'] path = os.path.join(prefix_path, secure_filename(f.filename)) f.save(path) if not os.path.exists(path): abort(403) qp = plaintext_data_etl.read_file_and_get_doc_list(path) author_hash = dict([(row['author_id'], row['author_name']) for row in data_warehouse.get_all_author_id_and_name()]) try: authors = session['authors'] feature_list, author_list = data_warehouse.get_features_from_database_fact_by_list_of_author_id(authors) except KeyError: feature_list, author_list = data_warehouse.get_all_features_from_database_fact() knn_proba = cknn.get_query_set_probabilistic(feature_list, author_list, qp) authors = list(set(author_list)) for idx in range(len(set(authors))): results.append((author_hash.get(authors[idx]), knn_proba[idx])) session.clear() return jsonify(dict(results))
def get_knn_statics(): if request.method != 'POST': abort(403) results = [] prefix_path = '/var/tmp/stylometric_app/knn_upload/' f = request.files['file'] path = os.path.join(prefix_path, secure_filename(f.filename)) f.save(path) if not os.path.exists(path): abort(403) qp = plaintext_data_etl.read_file_and_get_doc_list(path) author_hash = dict([(row['author_id'], row['author_name']) for row in data_warehouse.get_all_author_id_and_name()]) try: authors = session['authors'] feature_list, author_list = data_warehouse.get_features_from_database_fact_by_list_of_author_id(authors) except KeyError: feature_list, author_list = data_warehouse.get_all_features_from_database_fact() knn_proba = cknn.get_query_set_probabilistic(feature_list, author_list, qp) authors = list(set(author_list)) for idx in range(len(set(authors))): results.append((author_hash.get(authors[idx]), knn_proba[idx])) session.clear() return jsonify(dict(results))
def get_chars(): return render_template('data_visualize/charts.html', title='Stylometric Charts', content=Markup(u'In this page, you can compare the writing styles of <strong>at most 3 ' u'documents</strong> in terms of stylometric features. Firstly, you need to ' u'select an author from the drop-down list. Afterwards, another drop-down ' u'list is shown for you to select the document. Finally, click the button ' u'<mark>Add to Table</mark> to add the document into the cache. You will ' u'need to repeat the steps until there are at least 2 documents.'), authors_list=data_warehouse.get_all_author_id_and_name() )
def upload_file(): return render_template('data_visualize/upload.html', title='KNN Authorship Determination', content=Markup(u'In this page, you may upload a txt file to the server. The ' u'application will search the entire database to find an author with the ' u'closest writing style by using the Probabilistic K-Nearest Neighbor ' u'Algorithm. Drag and Drop a txt file to the box in order to ' u'upload the txt file to the server. The display of probabilistic values ' u'is provided in the form of CSV file.'), authors_list=data_warehouse.get_all_author_id_and_name() )
def get_chars(): return render_template('data_visualize/charts.html', title='Stylometric Charts', content=Markup(u'In this page, you can compare the writing styles of <strong>at most 3 ' u'documents</strong> in terms of stylometric features. Firstly, you need to ' u'select an author from the drop-down list. Afterwards, another drop-down ' u'list is shown for you to select the document. Finally, click the button ' u'<mark>Add to Table</mark> to add the document into the cache. You will ' u'need to repeat the steps until there are at least 2 documents.'), authors_list=data_warehouse.get_all_author_id_and_name() )
def upload_file(): return render_template('data_visualize/upload.html', title='KNN Authorship Determination', content=Markup(u'In this page, you may upload a txt file to the server. The ' u'application will search the entire database to find an author with the ' u'closest writing style by using the Probabilistic K-Nearest Neighbor ' u'Algorithm. Drag and Drop a txt file to the box in order to ' u'upload the txt file to the server. The display of probabilistic values ' u'is provided in the form of CSV file.'), authors_list=data_warehouse.get_all_author_id_and_name() )
def running_self_defined_distance(): return render_template('data_visualize/selfdistance.html', title='Self-defined Distance', content='TBC', authors_list=data_warehouse.get_all_author_id_and_name() )
def running_self_defined_distance(): return render_template('data_visualize/selfdistance.html', title='Self-defined Distance', content='TBC', authors_list=data_warehouse.get_all_author_id_and_name() )