Skip to content

Commit f394f57

Browse files
authored
Merge pull request jxmorris12#111 from bugsyb/Matches-fix
correct() updated to only return positive match, otherwise None is returned.
2 parents bb634d2 + 8a8edda commit f394f57

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

language_tool_python/utils.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import subprocess
1010
import urllib.parse
11-
import urllib.request
11+
from enum import Enum
1212
import psutil
1313

1414
from .config_file import LanguageToolConfig
@@ -99,6 +99,32 @@ def parse_url(url_str: str) -> str:
9999
return urllib.parse.urlparse(url_str).geturl()
100100

101101

102+
class TextStatus(Enum):
103+
CORRECT = "correct"
104+
FAULTY = "faulty"
105+
GARBAGE = "garbage"
106+
107+
108+
def classify_matches(matches: List[Match]) -> TextStatus:
109+
"""
110+
Classify the matches (result of a check on a text) into one of three categories:
111+
CORRECT, FAULTY, or GARBAGE.
112+
This function checks the status of the matches and returns a corresponding
113+
`TextStatus` value.
114+
115+
:param matches: A list of Match objects to be classified.
116+
:type matches: List[Match]
117+
:return: The classification of the matches as a `TextStatus` value.
118+
:rtype: TextStatus
119+
"""
120+
if not len(matches):
121+
return TextStatus.CORRECT
122+
matches = [match for match in matches if match.replacements]
123+
if not len(matches):
124+
return TextStatus.GARBAGE
125+
return TextStatus.FAULTY
126+
127+
102128
def correct(text: str, matches: List[Match]) -> str:
103129
"""
104130
Corrects the given text based on the provided matches.

0 commit comments

Comments
 (0)