File size: 2,361 Bytes
2f3072b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 | 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
# --- polarity ---
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")
# --- grammar ---
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)
# --- classical rewrite ---
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 # communities banned as people swap
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 # don't churn to today
assert "individuals" not in out # keep people
assert "enough time" in out
assert "an unhealthy life" in out
assert "very common" in out or "widespread" in out
print("\nALL ASSERTIONS PASSED")
|