View Single Post
Old 10-13-2015, 04:18 AM   #102
gipsy
Connoisseur
gipsy began at the beginning.
 
Posts: 81
Karma: 10
Join Date: Nov 2013
Device: Kobo Aura HD
Two more CalibUser
Code:
############ FIXES ώ ###########		
def IsFixO(m):
	"""
	This function examines a word to see whether is required to fix the (ιό|οί|ιο|οι) characterw that is misspelled.
	It is called by a regular expression function (re.sub) in FixCommonErrors()
	It returns the original expression if the checked word is not in the dictionary,
	otherwise it returns the word without the ώ fixed
	"""
	FixO=m.group(1)+"ώ"+m.group(3)
	FixO2=m.group(1)+m.group(2)+m.group(3)
	if spell(FixO2):
		return(m.group(1)+m.group(2)+m.group(3))
	elif spell(FixO):
		print("FixΏ: ",FixO2, " changed to ", FixO)
		return(m.group(1)+"ώ"+m.group(3))
	else:
		return(m.group(1)+m.group(2)+m.group(3))
		
############ FIXES ω ###########		
def IsFixW(m):
	"""
	This function examines a word to see whether is required to fix the (ιό|οί|ιο|οι) characterς that is misspelled.
	It is called by a regular expression function (re.sub) in FixCommonErrors()
	It returns the original expression if the checked word is not in the dictionary,
	otherwise it returns the word without the ω fixed
	"""
	FixW=m.group(1)+"ω"+m.group(3)
	FixW2=m.group(1)+m.group(2)+m.group(3)
	if spell(FixW2):
		return(m.group(1)+m.group(2)+m.group(3))
	elif spell(FixW):
		print("FixΩ: ",FixW2, " changed to ", FixW)
		return(m.group(1)+"ω"+m.group(3))
	else:
		return(m.group(1)+m.group(2)+m.group(3))
		

--------------------------------------------------------------------

		#Fixes ώ in words that are misspelled
		if dictExists == True:
			CorrectText("ώ fixes",r"(\w+)(ιίι|(ό|ο)|ίό|ο&gt;|ο'ι|ιό|οί|ιο|οι|&lt;ο|οϊ)(\w+)(?![^<>]*>)(?!.*<body[^>]*>)", IsFixO)

		#Fixes ω in words that are misspelled
		if dictExists == True:
			CorrectText("ω fixes",r"(\w+)(ιίι|(ό|ο)|ίό|ο&gt;|ο'ι|ιό|οί|ιο|οι|&lt;ο|οϊ)(\w+)(?![^<>]*>)(?!.*<body[^>]*>)", IsFixW)

EDIT: How can I modify the regex to match and the last and first characters in a word? I noticed that they work only inside the word.

Thanks!

Last edited by gipsy; 10-14-2015 at 02:39 AM.
gipsy is offline   Reply With Quote