I finally get the FixP code to work with!
Code:
def IsFixP(m):
"""
This function examines a hyphenated word to see whether the hyphen is required.
It is called by a regular expression function (re.sub) in FixCommonErrors()
It returns the original expression if the non-hyphenated word is not in the dictionary,
otherwise it returns the word without the hyphen
"""
FixP="Π"+m.group(2)
FixP2=m.group(1)+m.group(2)
if spell(FixP2):
return(m.group(0))
elif spell(FixP):
print("FixP removed from: ", FixP)
return ('Π'+m.group(2))
else:
return(m.group(0))
and
Code:
#Fixes Π in words that are misspelled
if dictExists == True:
CorrectText("Π fixes",r"(1\ Ι|ΓΙ|Γΐ|ΙΙ|II|Ι\ Ι|ΓΤ|ΙΊ|Ιί)[ ]?(\w+)(?![^<>]*>)(?!.*<body[^>]*>)", IsFixP)
It bypass the spelling correct words and changes the misspelled.
I think that i have some error in the CorrectText regex.
In the FixP sample that i had in a previously post... It doesn't correct the "
Ι Ιήρε" And i have it in the CorrectText as "
Ι\ Ι" .
Any thoughts???
EDIT: Found that it doesn't fix if the second part of the word (m.group(2)) is lowercase