any2human / tests /test_classical_strict.py
idnameraj's picture
Enable aggressive classical multi-pass wording when MiniLM is off.
312c142
Raw
History Blame Contribute Delete
5.4 kB
"""Classical-strict gates (no MiniLM): block second-pass synonym drift."""
from __future__ import annotations
from app.engine.lexical import refine_sentence
from app.engine.phrase import rewrite_phrases
SECOND_PASS = (
"For the success of any business, supplying excellent customer service is "
"vital. Customers appreciate organizations that answer promptly to their "
"questions, decide issues efficiently, and treat them with respect.\n\n"
"Employees who communicate clearly and keep a positive attitude help create "
"a satisfying customer experience. Areas for improvement can be identified "
"by businesses that actively listen to customer feedback and consolidate "
"customer loyalty.\n\n"
"By consistently delivering high-quality service, organizations can "
"establish a strong reputation, gain customer retention, and spur positive "
"word-of-mouth recommendations."
)
def test_phrase_blocks_found_and_present_reputation_service():
source = (
"By consistently delivering high-quality service, organizations can "
"establish a strong reputation."
)
result = rewrite_phrases(
source,
polish=True,
use_t5=False,
max_changes=2,
classical_strict=True,
)
low = result.text.lower()
assert "found a strong reputation" not in low
assert "presenting high-quality service" not in low
assert "launch" not in low
assert "prove a strong reputation" not in low
def test_lexical_blocks_prove_reputation_and_win_retention():
source = (
"Organizations can establish a strong reputation and gain customer "
"retention."
)
result = refine_sentence(
source,
min_wsd=0.10,
polish=True,
classical_strict=True,
)
low = result.text.lower()
assert "prove a strong reputation" not in low
assert "win customer retention" not in low
def test_lexical_blocks_resolve_to_decide_and_respond_to_answer():
source = (
"Customers appreciate organizations that respond promptly to their "
"questions, resolve issues efficiently, and treat them with respect."
)
result = refine_sentence(
source,
min_wsd=0.10,
polish=True,
classical_strict=True,
)
low = result.text.lower()
assert "decide issues" not in low
assert "resolve issues" in low
# "answer promptly to" is ungrammatical; keep respond.
assert "answer promptly to" not in low
def test_lexical_still_allows_maintain_to_keep_headword():
source = "Employees who maintain a positive attitude help customers."
result = refine_sentence(
source,
min_wsd=0.10,
polish=True,
classical_strict=True,
)
# Headword upgrade may apply; must not invent bad VO pairs.
low = result.text.lower()
assert "decide" not in low
assert "attitude" in low
if result.changes:
assert any(
c.original.lower() == "maintain" and c.replacement.lower() == "keep"
for c in result.changes
)
def test_phrase_blocks_decide_determine_define_issues():
source = (
"Customers appreciate organizations that decide issues efficiently."
)
result = rewrite_phrases(
source,
polish=True,
use_t5=False,
max_changes=2,
classical_strict=True,
)
low = result.text.lower()
assert "determine issues" not in low
assert "define issues" not in low
def test_phrase_blocks_keep_to_maintain_cycle():
source = "Employees who keep a positive attitude help customers."
result = rewrite_phrases(
source,
polish=False,
use_t5=False,
max_changes=2,
classical_strict=True,
)
low = result.text.lower()
assert "maintain a positive attitude" not in low
def test_lexical_blocks_delivering_to_functioning():
source = "By consistently delivering high-quality service, firms succeed."
result = refine_sentence(
source,
min_wsd=0.10,
polish=True,
classical_strict=True,
)
low = result.text.lower()
assert "functioning" not in low
assert "serving high-quality service" not in low
def test_second_pass_sample_stays_stable_under_classical_strict():
phrase = rewrite_phrases(
SECOND_PASS,
polish=True,
use_t5=False,
max_changes=2,
classical_strict=True,
)
lexical = refine_sentence(
SECOND_PASS,
min_wsd=0.14,
polish=True,
classical_strict=True,
)
combined = (phrase.text + "\n" + lexical.text).lower()
for bad in (
"launch a strong reputation",
"found a strong reputation",
"prove a strong reputation",
"presenting high-quality",
"functioning high-quality",
"serving high-quality service",
"define issues",
"determine issues",
"maintain a positive attitude",
"win customer retention",
):
assert bad not in combined
def test_classical_strict_skips_aggressive_ensure_path():
from app.engine.lexical import ensure_wording_change
source = "The report assists students with useful information."
result = ensure_wording_change(source, classical_strict=True)
assert result.text == source
assert result.reason == "classical_strict_no_ensure"