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")