 Hey, how's it going everybody? Welcome back to another Python programming tutorial We're still looking at pi enchant or when we import the module just enchant And that's really nice because we can create these dictionary objects that pretty much I don't know act as a real dictionary, right? We're able to test if words actually exist like hello does that word exist and yeah It does or we can actually get something like a wrong word and say it that doesn't exist from there We can actually determine certain suggestions for that mistyped word or misspelled word and see what else we could We'd be looking at there We were looking at personal word lists and stuff like that So the real use with the enchant module comes with checking if we have an English word or Actually getting other suggestions, but this is kind of doing this one at a time, right? It's only checking individual words I Want a little bit more functionality to actually get us an Entire paragraph or sentences or pages of text that we might want to spell check So the documentation talks about this there is a method of checking entire blocks of chat of text Sorry, so here we go while the enchant dictionary objects are useful for spell checking individual words They cannot be used directly to check for example a whole paragraph So the module enchant dot checker provides a class spell checker which is designed to do just this handle that task So they're handled and created kind of the same way as our dictionary objects You pass in a language tag, and then you're ready to roll now It uses an interesting method and function called set text and there is of course get text to see what you've passed in and This is the text that's going to be looked at it's going to be examined and checked over by the object Now it's kind of used as an iterator that looks through all of the spelling mistakes in the text that you give it So here's a simple example that they show us and let's try and build this all on our own as well. Let's from enchant Dot checker let's import that class spell checker So now let's create s equals a spell checker right or doesn't really matter What variable name we give it, but it does take the language we want En underscore us so we've got that dictionary English dictionary for us And then we'll give it text with this set text function. So real simple set text Hi My name is John Cool now if you use a dot space of course to See what else? I'm sorry dot and then control space to kind of autocomplete and see what more you can do here with this Object there is the get text function and that will return what it's been given and then you can play a little bit more here next But that's kind of working as like our iterator, right? Replace replace always and actually word is what we're seeing that we would have an error there and We haven't started to loop through it So it's not going to show us those yet and word position would get the position there as well So in the example that they give they do loop through this spell checker object for every error in there It's going to get an error word so you can see what is spelled wrong So let's do this. Let's say for error in s print misspelled word and then s or error sorry error dot word and There is apparently nothing misspelled. So okay high HY must be actually be a word. Let's take a look here check We can work with Hi, oh Is capital H Y okay? Apparently that is a thing. Oh, I'm really curious now Not cursor or funkel. What's high? Oh Oh, it's a wonderful dialect of lisp. That's part of Python. That's pretty nifty Well, maybe I'll have to look at that later. Okay All right, let's use a different text, right? Let's do s dot set text This has some typos I Should have said has but I actually wrote have all right so Now we can run our loop for error in s and hey, there's a misspelled word fidgios Truly truly. I said you fidgios So and now of course, I want to say if s dot word it will tell us. Oh, yeah There's the gyos and s dot word position Would give us the position of that misspelled word now if we had multiple in here. Let's say So typos, I hope that's not a word Okay, yeah misspelled word the gyos and so so now we've got s dot word Which is so which was the last one that we saw and s dot word position so 12 12 Places into the string. We have SOE or so Now where does our s dot next come into play it looks like we're all done with our iteration so s dot next is gonna Kind of throw an error at us. Will it bring us back to where we need to go? No, it won't okay? Is there any way we can get back to where we were set offset? Maybe let's take a look. I wanted you to see that Description here set the offset of the tokenization routine So if I set offset zero now if I use s dot next no, it's not gonna get us anywhere We might have to just restart the text and Yeah, probably reset the text. I don't even know what I just tried to write there. We can run it manually with our iterator I'm kind of curious what this object is. So let's kind of explore here Okay, so I missed over it the first one that I ran that I didn't create an object on must have been Helo and then Aya this next one is where we're at Now if I do p dot word again After I've created move to the next Error We're gonna get or and that's not a word and it found that one But of course we can just run through our actual loop, which is a much better way of testing for these things Okay That's enough of me talking about those. Let's go back to our documentation. See what else we can do. There is of course a Functionality or a method there that changes the way we Filter through certain words. Can we can we ignore some words? And there are lists of filters that we can pass in as keyword arguments And we can actually import them from the enchant tokenize module like an email filter or URL filter So let's try and build this From enchant dot tokenize Let's import email filter and URL filter and Now let's actually make that checker object again spell checker with the language and us and For tokenizers, I think that's an option there or filters. It's a keyword. Okay filters equals none filters Which is apply an array of email filter and URL filter Now we can set the text. I need to get an email from Me at metro cast net and his website is HTTP dot now for error in s print misspelled word Error dot word and the only thing that we see wrong Because of our email filter and our URL filter me and metro cast net along with the HTTP URL Aren't treated as errors since we set up those filters, but good obviously what should have been get Since that miss that is misspelled our spell checker found that and saw that that was the error there. So cool We're good. I think that's all I really wanted to show you in this tutorial Checking through a whole string with multiple words And of course you could have this load entire paragraph or a whole friggin text file if you wanted it to and You can loop through the errors Find the word and the word position as to where those things are and if you want to set up some filters You can do that. There are totally other filters. I'm kind of curious. What other filters there are. Let's actually import Enchant dot token eyes as Filters now filters dot Wiki word filter URL filter Was there email filter up there email filter? Okay, so those are the only three that I see so far But and of course you can read more about that in the documentation if you're curious But you've got that option and I hope I was able to walk you through this segment of the spell checker and a few of the filter Functionality, so thanks for watching guys. Hope you enjoyed this. I'll see you in the next tutorial