| from __future__ import annotations
|
|
|
| import sys
|
| 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.meaning_safety import polarity_safe
|
| from app.pipeline.orchestrator import rewrite_text
|
|
|
|
|
| assert polarity_safe(
|
| "people live an unhealthy life",
|
| "people live a poor lifestyle",
|
| )
|
| assert not polarity_safe(
|
| "people live an unhealthy life",
|
| "people live a healthy life",
|
| )
|
| assert not polarity_safe(
|
| "people don't realize how much it affects health",
|
| "people realize how much it affects health",
|
| )
|
| assert not polarity_safe(
|
| "people don't realize how much it affects health",
|
| "causes people to realize how much it affects their health",
|
| )
|
| print("polarity OK")
|
|
|
|
|
| g = correct_text(
|
| "Nowadays many peoples are living unhealthy life because they don't have enough times. "
|
| "Eating fast foods are becoming very common and peoples don't realizes how much it affect their health."
|
| )
|
| gl = g.lower()
|
| assert "peoples" not in gl
|
| assert "enough times" not in gl
|
| assert "enough time" in gl
|
| assert "don't realize" in gl or "do not realize" in gl
|
| assert "it affects" in gl
|
| assert "fast foods is" in gl or "fast food" in gl
|
| assert "an unhealthy life" in gl
|
| print("grammar OK:")
|
| print(g)
|
|
|
|
|
| orig = (
|
| "Nowadays many peoples are living unhealthy life because they don't have enough times. "
|
| "Eating fast foods are becoming very common and peoples don't realizes how much it affect their health."
|
| )
|
| r = rewrite_text(orig, tone="Neutral", strength=1, preserve_length=True, ml_polish=False)
|
| out = r.text.lower()
|
| print("\nNeutral Normal:")
|
| print(r.text)
|
| assert "peoples" not in out
|
| assert "adequate moments" not in out
|
| assert "communities" not in out or "people" in out
|
| assert "rapid food" not in out
|
| assert "highly usual" not in out
|
| assert "don't realize" in out or "do not realize" in out
|
| assert "affects" in out
|
| assert "nowadays" in out
|
| assert "individuals" not in out
|
| assert "enough time" in out
|
| assert "an unhealthy life" in out
|
| assert "very common" in out or "widespread" in out
|
| print("\nALL ASSERTIONS PASSED")
|
|
|