Functions
Config
dataclass
Configuration for NLP input paths and processing flags.
Source code in src/pydistintox/common/config.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
calculate_rank_correlation(results)
Calculates the Kendall rank correlation coefficients between all pairs of measures in the input dictionary. It returns them as a 2-d matrix (np.ndarray)
As the input arrays are uniformly scaled, only rank correlation is meaningful. The resulting matrix is symmetric, with each entry representing the correlation between two measures.
Source code in src/pydistintox/distinct_measures/core.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
calculate_scores(matrices, config)
This is the main funktion, doing all the calculation. it takes and gives out a dictionary containing these keys: ['zeta_sd0', 'zeta_sd2', 'rrf_dr0', 'eta_sg0', 'welch_t_value', 'ranksumtest_value', 'chi_square_value', 'LLR_value', 'tf_idf'] This function implements several distinctive measures.
Source code in src/pydistintox/distinct_measures/core.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
compute_td_matrices_and_measures(parsed_corp_tar, parsed_corp_ref, config)
Computes term-document matrices and TF-IDF-based measures for target and reference corpora.
Expects input corpora in a format compatible with Gensim's corpus structure: A list of documents, where each document is a list of tokenized lemmas (strings). The function internally converts the input into Gensim's BoW (Bag-of-Words) format for further processing.
Source code in src/pydistintox/td_matrices/core.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
generate_parsed_corpora(config)
Generates parsed target and reference corpora from input texts or pre-saved JSON files.
The output format is compatible with Gensim's corpus input requirements: A list of documents, where each document is represented as a list of tokenized lemmas. The returned tuples contain (filename_chunk_index, lemma_list) pairs, where lemma_list is a list of strings (tokens) for a single document or chunk.
Source code in src/pydistintox/td_matrices/core.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
save_as_sparse(dense_matrix, output_dir, file_prefix, format)
Saves a dense matrix as sparse in the given directory using scipy.sparse.save_npz with the suffix 'npz'.
Source code in src/pydistintox/common/utils.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
save_results(result, path, write_header=True)
store results as textfile in csv format in given directory.
Source code in src/pydistintox/visualize/core.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
visualize_rank_correlations(matrix, index, dir_path)
visualize rank correlations between scores
Source code in src/pydistintox/visualize/core.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
visualize_score(score_processed, title, path)
Visualizes the top and bottom terms from a score DataFrame as a horizontal bar chart.
Displays the top 25 terms (highest scores) in lightgreen and the bottom 25 terms (lowest scores) in lightblue. The chart is saved as an interactive HTML file in the specified directory.
Source code in src/pydistintox/visualize/core.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |