okflint.cohesion module
Semantic cohesion scoring for markdown sections (S202 calibration core).
Pure functions only: no I/O, no printing, no CLI. See scripts/calibrate_cohesion.py for the disposable scaffolding that drives this module on real files.
- class okflint.cohesion.CohesionResult(sections, components)[source]
Bases:
objectFull output of a cohesion analysis for one document.
- class okflint.cohesion.Component(section_indices)[source]
Bases:
objectA connected component of sections linked by cosine similarity > tau.
- class okflint.cohesion.Section(title, level, line, body, token_count)[source]
Bases:
objectA document section after splitting and micro-section merging.
- okflint.cohesion.analyze_cohesion(content, *, tau=0.15, min_tokens=20, title_levels=None)[source]
Run the full cohesion pipeline on one markdown file’s raw content.
- Parameters:
- Return type:
- Returns:
CohesionResult with merged sections and their connected components.
- okflint.cohesion.build_similarity_matrix(vectors)[source]
Build a symmetric cosine similarity matrix, quantized to 6 decimals.
- okflint.cohesion.compute_tfidf_vectors(bodies)[source]
Compute a TF-IDF vector per section body (stdlib only, no stopwords).
- okflint.cohesion.find_components(matrix, tau)[source]
Return connected components (as sorted index lists) linked by cos > tau.
- okflint.cohesion.merge_micro_sections(sections, min_tokens)[source]
Fuse sections under the token floor into a neighbour until none remain.
A section below the floor is attached to the previous section, or to the next one if it is the first section. Nothing is discarded.