"""Report how closely rewrite output matches the input paste.""" from __future__ import annotations import sys from difflib import SequenceMatcher from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) from app.pipeline.grammar_fix import correct_text from app.pipeline.orchestrator import rewrite_text SAMPLES = { "LIBRARIES": ( "Public libraries offer free books and quiet spaces for study. " "If cities don't fund them properly, many young people lose access " "to learning resources." ), "ELECTRIC": ( "Electric cars produce less air pollution than petrol cars. " "However, charging stations are still rare in rural areas, so long " "trips remain difficult for drivers." ), "HOMEMADE": ( "Homemade meals are usually healthier than fast food. Families who " "cooks together also spend more quality time and talk about daily problems." ), "GROUP": ( "Group projects helps students learn teamwork, but some members don't " "contribute equally. Teachers should check progress regularly instead " "of grading only the final report." ), } def _sim(a: str, b: str) -> float: return SequenceMatcher(None, a.lower(), b.lower()).ratio() def main() -> None: print("LOCAL similarity report") print("sim_input = vs original paste | sim_grammar = vs grammar-corrected source") print("-" * 72) for name, text in SAMPLES.items(): r = rewrite_text(text, tone="Neutral", strength=1, ml_polish=False) g = correct_text(text) sim_i = _sim(text, r.text) sim_g = _sim(g, r.text) preview = r.text.replace("\n", " / ")[:140] print( f"{name}: sim_input={sim_i:.3f} sim_grammar={sim_g:.3f} " f"api_similarity={r.similarity:.3f} changed={r.changed} " f"words={r.input_words}->{r.output_words}" ) print(f" OUT: {preview}") print() if __name__ == "__main__": main()