Skip to content

AutoCorrect2 models

This module contains the concrete AutoCorrect2CandidateHotstring model.

models

Define AutoCorrect2-specific hotstring and result models.

AutoCorrect2CandidateHotstring dataclass

Bases: CandidateHotstring

Represent a candidate rendered using AutoCorrect2's f() helper.

The inherited constructor trigger input is semantic trigger text. The semantic replacement is converted to a safe AutoHotkey string literal and passed as the single argument to f().

Source code in hotstring\autocorrect2\models.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@dataclass(frozen=True, slots=True)
class AutoCorrect2CandidateHotstring(CandidateHotstring):
    """Represent a candidate rendered using AutoCorrect2's `f()` helper.

    The inherited constructor `trigger` input is semantic trigger text. The
    semantic replacement is converted to a safe AutoHotkey string literal and
    passed as the single argument to `f()`.
    """

    def compute_content(self, replacement: str) -> str:
        """Compute AutoCorrect2 executable content for a replacement.

        Args:
            replacement:
                Intended replacement text.

        Returns:
            AutoHotkey expression calling `f()` with the replacement.
        """
        return f"f({self.to_ahk_string_literal(replacement)})"

compute_content

compute_content(replacement: str) -> str

Compute AutoCorrect2 executable content for a replacement.

Parameters:

Name Type Description Default
replacement str

Intended replacement text.

required

Returns:

Type Description
str

AutoHotkey expression calling f() with the replacement.

Source code in hotstring\autocorrect2\models.py
20
21
22
23
24
25
26
27
28
29
30
def compute_content(self, replacement: str) -> str:
    """Compute AutoCorrect2 executable content for a replacement.

    Args:
        replacement:
            Intended replacement text.

    Returns:
        AutoHotkey expression calling `f()` with the replacement.
    """
    return f"f({self.to_ahk_string_literal(replacement)})"

AutoCorrect2CheckResult dataclass

Represent the result of checking candidates against AutoCorrect2.

Attributes:

Name Type Description
accepted tuple[AutoCorrect2CandidateHotstring, ...]

Candidates with no detected conflict.

rejected tuple[CandidateAssessment, ...]

Assessments for candidates with one or more conflicts.

Source code in hotstring\autocorrect2\models.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@dataclass(frozen=True, slots=True)
class AutoCorrect2CheckResult:
    """Represent the result of checking candidates against AutoCorrect2.

    Attributes:
        accepted:
            Candidates with no detected conflict.
        rejected:
            Assessments for candidates with one or more conflicts.
    """

    accepted: tuple[AutoCorrect2CandidateHotstring, ...]
    rejected: tuple[CandidateAssessment, ...]

    @property
    def candidate_count(self) -> int:
        """Return the total number of candidates checked.

        Returns:
            Number of accepted plus rejected candidates.
        """
        return len(self.accepted) + len(self.rejected)

candidate_count property

candidate_count: int

Return the total number of candidates checked.

Returns:

Type Description
int

Number of accepted plus rejected candidates.