Python is an extremely simple language and a good option to start with small projects when you are still a noob at programming.
The editor file is the starting point.
The code should work except that the path needs to be changed for dictionary.txt and for all the gif files that can be downloaded from github.
- The path for dictionary.txt appears in find_misspelled_word.py
- the path for *.gif files appears in Interface_2.py
Just download the code and type: "python editor.py" in the terminal.
Screenshot -
Pointers:
- Spell-check : The misspelled word was found by comparing it with a dictionary stored as a hash table. To make the list of suggested words for the misspelled word, an attribute score associated with each word would increment based on its similarity with misspelled word. Similarity includes the length of the common substring, the number of common letters, words that start with the same letter as the misspelled word. For instance: For misspelled word “utail”,"tail" will be higher in rankings because the length of common substring 4(very high considering total length of "utail" is only 5). The top ten words with the highest score are displayed in the list of suggested words.
- Undo-Redo : This was the most interesting part. After doing it wrong many times, the final solution had an undo and redo stack. The attributes associated with an event(keypress) were event_type, start, end, value, operation. Start and end define the index, value stores the string, event_type defines the behaviour - delete/insert the string or shift the cursor. On pressing undo button, the event at the top of the stack is executed, popped and pushed into the redo stack. The same happens for the redo stack.
- Find and Replace : It supports features such as match case, match entire word only, search backwards and wrap around. Boyer-Moore would become inefficient when all permutations of a pattern are considered, so a modified rabin-karp was used instead. Matched patterns were appropriately highlighted. Replace contained additional buttons for replace one or replace all.
- Functions for open file, save, quit, new were simple as they were already provided by the library.
Overall, it turned out to be 2330 lines of code divided into 24 files.
No comments:
Post a Comment