| import pandas as pd |
| from preprocess import split_sentences, split_words_from_text |
| from anal import analyze_text, analyze_word_length, analyze_punctuation, readability |
|
|
| |
| def table_basic_stats(files): |
| data = [] |
| for file in files: |
| with open(file.name, 'r', encoding='utf-8') as f: |
| text = f.read() |
| |
| |
| from preprocess import clean_text |
| cleaned = clean_text(text) |
| |
| |
| char_count = len(cleaned.replace(' ', '')) |
| |
| |
| sentences = split_sentences(text) |
| words = split_words_from_text(text) |
| word_count = len(words) |
| sent_count = len(sentences) |
| |
| data.append({ |
| "Файл": file.name.split('/')[-1], |
| "Символы": char_count, |
| "Слова": word_count, |
| "Предложения": sent_count |
| }) |
| |
| return pd.DataFrame(data) |
|
|
| |
| def table_avg_stats(files): |
| data = [] |
| for file in files: |
| with open(file.name, 'r', encoding='utf-8') as f: |
| text = f.read() |
| |
| word_count, avg_word_len = analyze_word_length(text) |
| _, avg_sent_len, disp, _ = analyze_text(text) |
| |
| data.append({ |
| "Файл": file.name.split('/')[-1], |
| "Ср. длина слова": round(avg_word_len, 2), |
| "Ср. длина предложения": round(avg_sent_len, 2), |
| "Дисперсия": round(disp, 2) |
| |
| }) |
| |
| return pd.DataFrame(data) |
|
|
| |
| def table_punctuation(files): |
| |
| all_puncts = set() |
| file_data = [] |
| |
| for file in files: |
| with open(file.name, 'r', encoding='utf-8') as f: |
| text = f.read() |
| |
| counts, _ = analyze_punctuation(text) |
| all_puncts.update(counts.keys()) |
| file_data.append((file.name.split('/')[-1], counts)) |
| |
| |
| punct_order = [ |
| '.', ',', ';', ':', '!', '?', '...', |
| '—', '-', |
| '()', '[]', '{}', '<>', '⟨⟩', |
| '«»', '“”', '„“', '‹›', '""', "''", |
| "'", '"' |
| ] |
| sorted_puncts = [p for p in punct_order if p in all_puncts] |
|
|
| data = [] |
| for file_name, counts in file_data: |
| row = {"Файл": file_name} |
| for p in sorted_puncts: |
| row[p] = counts.get(p, 0) |
| data.append(row) |
| |
| return pd.DataFrame(data) |
|
|
| |
| def table_readability(files): |
| data = [] |
| for file in files: |
| with open(file.name, 'r', encoding='utf-8') as f: |
| text = f.read() |
| |
| read_score = readability(text) |
| |
| data.append({ |
| "Файл": file.name.split('/')[-1], |
| "Индекс удобочитаемости": round(read_score, 2) |
| }) |
| |
| return pd.DataFrame(data) |