File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import os
99import subprocess
1010import urllib .parse
11- import urllib . request
11+ from enum import Enum
1212import psutil
1313
1414from .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+
102128def correct (text : str , matches : List [Match ]) -> str :
103129 """
104130 Corrects the given text based on the provided matches.
You can’t perform that action at this time.
0 commit comments