That project started as a task from WideBot company, that was the email that I received:
For our second task, we're looking at spelling correction - a vital feature for any text-based service. Your mission is to build a super-efficient spelling correction API. It should take a word as input and return a list of probable corrections, sorted by likelihood, or the word itself if it's already correct. Wrap this functionality up nicely in an API, and you're golden!
Constraints:
* The response time for each word should be between 50-200 ms.
* Feel free to use any technique or approach - whether it's a ready-made solution or something you build from scratch. We're looking for efficiency and precision.
I chose to go with Flask given the fact that I had an experience using it in that cute project I actually can't remember anything regarding Flask from it but at least I can use the codebase from it.
Due to some calculation issue, I had 1 day to finish that project, I found a very fast starting solution by using that library called ar_corrector and even given the time constraints it was still a valid solution!
So the only thing left to do here is to remember how to actually build API! I found those 2 tutorials on LinkedIn learning that are really good and love to share them here in order to go back to them in case I need any refreshers on Flask in the future -that's very useful given the fact that I have such a short memory-:
1- Flask essential training
2- Building RESTful APIs with Flask
Although initially, I used the Python time
module to measure how much time ar_corrector takes to return the correct words, I made sure again of the API response time using Postman and it was confirmed that the response time about 10 ms.
import time
from ar_corrector.corrector import Corrector
corr = Corrector()
start = time.time()
corr.spell_correct('بختب')
end = time.time()
print(end - start)