49
49
word = line.strip()
50
50
ignore_list[word.lower()] = word # Store lowercase -> correct-case
51
51
52
- # Common phrases to prioritize in spellcheck corrections
53
- common_phrases = {
54
- "identity provider": ["identiy provider", "identify provider"],
55
- "access token": ["access toekn", "acess token"],
56
- "user authentication": ["user authentification", "user authenthication"],
57
- "API gateway": ["API getway", "API gatway"]
58
- }
59
-
60
52
# Function to check if a word is inside a code block, backticks, URL, or file reference
61
53
def is_code_or_url_or_file(line):
62
54
return bool(re.search(r'`.*?`|https?://\S+|www\.\S+|/[\w./-]+', line))
@@ -68,28 +60,12 @@ jobs:
68
60
# Function to determine if an ignore list word should be used
69
61
def should_use_ignore_list(original, suggestion, line):
70
62
best_match, score = process.extractOne(original, ignore_list.keys())
71
-
72
- # Must be at least 90% similar to be considered a match
73
63
if score < 90:
74
- return False
75
-
76
- # Reject if original contains best_match as a substring (e.g., "certifcate" vs "CE")
64
+ return False # Reject weak matches
77
65
if best_match in original and len(original) > len(best_match):
78
- return False
79
-
66
+ return False # Prevent incorrect substring matches
80
67
return True
81
68
82
- # Function to apply strict context-based correction rules
83
- def apply_strict_context_correction(sentence, original, suggestion):
84
- # Prioritize known common phrases first
85
- for correct_phrase, wrong_variants in common_phrases.items():
86
- for wrong_phrase in wrong_variants:
87
- if wrong_phrase in sentence:
88
- return sentence.replace(wrong_phrase, correct_phrase)
89
-
90
- # Replace the misspelled word with the correct word **only once**
91
- return re.sub(r'\b' + re.escape(original) + r'\b', suggestion, sentence, count=1)
92
-
93
69
# Process spellcheck output and apply fixes
94
70
with open("spellcheck_report_raw.txt", "r", encoding="utf-8") as infile, open("spellcheck_report.txt", "w", encoding="utf-8") as outfile:
95
71
for line in infile:
@@ -103,31 +79,31 @@ jobs:
103
79
content_lines = file.readlines()
104
80
context_line = content_lines[int(line_number) - 1].strip()
105
81
106
- # ✅ Use sentence-splitter to analyze full sentence context
82
+ # Use sentence-splitter to analyze full sentence context
107
83
splitter = SentenceSplitter(language="en")
108
84
sentences = splitter.split(context_line)
109
85
relevant_sentence = next((s for s in sentences if original in s), context_line)
110
86
111
- # **Fix #1: Enforce strict case-sensitive ignore list rules**
87
+ # Enforce strict case-sensitive ignore list rules
112
88
if original.lower() in ignore_list:
113
89
if is_code_or_url_or_file(relevant_sentence) or is_markdown_link(relevant_sentence, original):
114
90
corrected_word = original.lower() # Keep lowercase in URLs, links, or file paths
115
91
else:
116
92
corrected_word = ignore_list[original.lower()] # Use exact case from ignore list
117
93
118
- # **Fix #2: Reject weak matches to ignore words**
94
+ # Reject weak matches to ignore words
119
95
elif should_use_ignore_list(original, suggestion, relevant_sentence):
120
96
best_match, _ = process.extractOne(original, ignore_list.keys())
121
97
corrected_word = ignore_list[best_match]
122
98
123
- # **Fix #3: Strictly prevent weak ignore word matches**
99
+ # Prevent weak ignore word matches
124
100
elif len(original) < 3 or len(original) < len(ignore_list.get(suggestion.lower(), "")) / 2:
125
101
corrected_word = suggestion # Use the English dictionary instead
126
102
127
- # **Fix #4: Apply strict context-based correction**
128
- relevant_sentence = apply_strict_context_correction(relevant_sentence, original, corrected_word)
103
+ # Apply strict context-based correction
104
+ relevant_sentence = re.sub(r'\b' + re.escape( original) + r'\b' , corrected_word, relevant_sentence, count=1 )
129
105
130
- # **Fix #5: Strictly prevent punctuation modifications**
106
+ # Prevent punctuation modifications
131
107
relevant_sentence = relevant_sentence.replace("..", ".").replace(",.", ".").replace(" ,", ",")
132
108
133
109
# Write final output
0 commit comments