| 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.orchestrator import rewrite_text | |
| samples = [ | |
| ( | |
| "Academic", | |
| 2, | |
| "Once upon a time, a tiny seed lay buried deep in the ground. " | |
| "Every day it heard the birds singing and wished it could see the bright blue sky.", | |
| ), | |
| ( | |
| "Casual", | |
| 1, | |
| "It is important to note that effective communication plays a crucial role " | |
| "in organizational success. Furthermore, this approach facilitates seamless " | |
| "collaboration across multifaceted teams.", | |
| ), | |
| ( | |
| "Formal", | |
| 1, | |
| "The team will start the project next week and try to finish early.", | |
| ), | |
| ( | |
| "Neutral", | |
| 2, | |
| "The team will start the project next week and try to finish early.", | |
| ), | |
| ] | |
| for tone, strength, sample in samples: | |
| r = rewrite_text(sample, tone=tone, strength=strength, preserve_length=True) | |
| sim = SequenceMatcher(None, sample.lower(), r.text.lower()).ratio() | |
| print(f"\n=== {tone} s={strength} sim={sim:.2f} changed={r.changed} ===") | |
| print(r.text) | |
| assert "lay bury" not in r.text.lower() | |
| assert " it hear " not in f" {r.text.lower()} " | |
| print("\nOK") | |