Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
here i am writing a program that is checking for spelling and grammatical mistake. is there a way to
get extra spacing error error .If there is more then one space between the word user should be notified that you have one extra spacing error. can we check 5 level of mistake with this.
i.e

level-1 ==> tedious
level-2 ==> typing mistake
level-3 ==> week grammar
level-4 ==> margin of improvement
level-5 ==> novelty
here is my code am using which give only grammar and spell mistake

Python
#wind32com.client is module for connecting with windows
#os is module for getting information about os directory
#zipfile is used to make zipfile of docx to read images because python-docx
#does not provide a way to get images from docx.

import win32com.client, os
import zipfile
wdDoNotSaveChanges = 0  #use for exist zero
path = os.path.abspath('mistake_image.docx')  #getting docx file directory we did not need to open it in program
                                        #because we are using word application for checking
z = zipfile.ZipFile("mistake_image.docx")      #making zibfile of doc for reading image and data
                                         #in this case we just need images
#print all files in zip archive
all_files = z.namelist()            #getting all file from doc file
#images will exist in side word/media/ directory that is default for maintaining images directory inside word side
images = filter(lambda x: x.startswith('word/media/'), all_files)   #reading only images
print 'images in doc',images      #printing images list on screen
app = win32com.client.gencache.EnsureDispatch('Word.Application')   #requesting for office grammar and spell checker
                                                            #extra spaces may or may no be handle depand on spell checker
                                                            #setting. if spell and grammar is not set to default . program
                                                            #will show no grammar and spelling error.
doc = app.Documents.Open(path)          #saving path of doc file in doc object
print "Grammar: %d" % (doc.GrammaticalErrors.Count,)        #pring grammar error count
print "Spelling: %d" % (doc.SpellingErrors.Count,)          #prinng spelling errors count

app.Quit(wdDoNotSaveChanges)        #exist app using exit 0
Posted

1 solution

You could always look into Regular Expressions.
See for example http://www.regular-expressions.info/[^]

This simple expression will find all positions in the text where there are 2 or more spaces in sequence.
[ ]{2,}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900