Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion language_tool_python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import subprocess
import urllib.parse
import urllib.request
from enum import Enum
import psutil

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


class TextStatus(Enum):
CORRECT = "correct"
FAULTY = "faulty"
GARBAGE = "garbage"


def classify_matches(matches: List[Match]) -> TextStatus:
"""
Classify the matches (result of a check on a text) into one of three categories:
CORRECT, FAULTY, or GARBAGE.
This function checks the status of the matches and returns a corresponding
`TextStatus` value.

:param matches: A list of Match objects to be classified.
:type matches: List[Match]
:return: The classification of the matches as a `TextStatus` value.
:rtype: TextStatus
"""
if not len(matches):
return TextStatus.CORRECT
matches = [match for match in matches if match.replacements]
if not len(matches):
return TextStatus.GARBAGE
return TextStatus.FAULTY


def correct(text: str, matches: List[Match]) -> str:
"""
Corrects the given text based on the provided matches.
Expand Down