Skip to content

Commit d5e6fae

Browse files
authored
Update spellcheck.yml
1 parent 64886b7 commit d5e6fae

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

.github/workflows/spellcheck.yml

+9-33
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ jobs:
4949
word = line.strip()
5050
ignore_list[word.lower()] = word # Store lowercase -> correct-case
5151
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-
6052
# Function to check if a word is inside a code block, backticks, URL, or file reference
6153
def is_code_or_url_or_file(line):
6254
return bool(re.search(r'`.*?`|https?://\S+|www\.\S+|/[\w./-]+', line))
@@ -68,28 +60,12 @@ jobs:
6860
# Function to determine if an ignore list word should be used
6961
def should_use_ignore_list(original, suggestion, line):
7062
best_match, score = process.extractOne(original, ignore_list.keys())
71-
72-
# Must be at least 90% similar to be considered a match
7363
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
7765
if best_match in original and len(original) > len(best_match):
78-
return False
79-
66+
return False # Prevent incorrect substring matches
8067
return True
8168
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-
9369
# Process spellcheck output and apply fixes
9470
with open("spellcheck_report_raw.txt", "r", encoding="utf-8") as infile, open("spellcheck_report.txt", "w", encoding="utf-8") as outfile:
9571
for line in infile:
@@ -103,31 +79,31 @@ jobs:
10379
content_lines = file.readlines()
10480
context_line = content_lines[int(line_number) - 1].strip()
10581
106-
# Use sentence-splitter to analyze full sentence context
82+
# Use sentence-splitter to analyze full sentence context
10783
splitter = SentenceSplitter(language="en")
10884
sentences = splitter.split(context_line)
10985
relevant_sentence = next((s for s in sentences if original in s), context_line)
11086
111-
# **Fix #1: Enforce strict case-sensitive ignore list rules**
87+
# Enforce strict case-sensitive ignore list rules
11288
if original.lower() in ignore_list:
11389
if is_code_or_url_or_file(relevant_sentence) or is_markdown_link(relevant_sentence, original):
11490
corrected_word = original.lower() # Keep lowercase in URLs, links, or file paths
11591
else:
11692
corrected_word = ignore_list[original.lower()] # Use exact case from ignore list
11793
118-
# **Fix #2: Reject weak matches to ignore words**
94+
# Reject weak matches to ignore words
11995
elif should_use_ignore_list(original, suggestion, relevant_sentence):
12096
best_match, _ = process.extractOne(original, ignore_list.keys())
12197
corrected_word = ignore_list[best_match]
12298
123-
# **Fix #3: Strictly prevent weak ignore word matches**
99+
# Prevent weak ignore word matches
124100
elif len(original) < 3 or len(original) < len(ignore_list.get(suggestion.lower(), "")) / 2:
125101
corrected_word = suggestion # Use the English dictionary instead
126102
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)
129105
130-
# **Fix #5: Strictly prevent punctuation modifications**
106+
# Prevent punctuation modifications
131107
relevant_sentence = relevant_sentence.replace("..", ".").replace(",.", ".").replace(" ,", ",")
132108
133109
# Write final output

0 commit comments

Comments
 (0)