File size: 2,314 Bytes
67f284e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Forced rule-based coverage fallback tests."""

from __future__ import annotations

from app.engine.force import force_cleft_rewrite
from app.engine.orchestrator import rewrite_document


SAMPLE = (
    "Time management is an essential skill that helps individuals achieve "
    "their personal and professional goals. Planning daily tasks and setting "
    "priorities allow people to complete their work more efficiently.\n\n"
    "Using calendars, to-do lists, and reminders can help organize "
    "responsibilities and reduce stress. Avoiding procrastination and "
    "focusing on one task at a time also improves productivity.\n\n"
    "By managing time effectively, individuals can maintain a better "
    "work-life balance and accomplish more with less pressure."
)


def test_force_cleft_rewrites_subject_predicate():
    result = force_cleft_rewrite(
        "Planning daily tasks allow people to complete their work more efficiently."
    )
    assert result
    assert result.lower().startswith("it is planning")
    assert "that" in result.lower()
    assert result != (
        "Planning daily tasks allow people to complete their work more efficiently."
    )


def test_force_rewrite_changes_every_rewriteable_sentence():
    result = rewrite_document(SAMPLE, force_rewrite=True, use_lexical_refinement=False)
    rewriteable = [
        record
        for record in result.sentences
        if record.original.strip()
        and record.sentence_type
        in {"simple_declarative", "compound", "complex", "because_clause"}
    ]
    assert rewriteable
    unchanged = [
        record
        for record in rewriteable
        if record.rewritten.strip().lower().rstrip(".!?")
        == record.original.strip().lower().rstrip(".!?")
    ]
    assert not unchanged, [
        (record.original, record.status, record.reasons) for record in unchanged
    ]
    assert "Daily, planning tasks" not in result.text
    assert result.stats.forced_rewrites >= 1


def test_force_rewrite_can_be_disabled():
    result = rewrite_document(
        "Using calendars can help organize responsibilities and reduce stress.",
        force_rewrite=False,
        use_lexical_refinement=False,
    )
    assert result.stats.forced_rewrites == 0