Possibly misspelt word python что это
Перейти к содержимому

Possibly misspelt word python что это

  • автор:

Python — Spelling Check

Checking of spelling is a basic requirement in any text processing or analysis. The python package pyspellchecker provides us this feature to find the words that may have been mis-spelled and also suggest the possible corrections.

First, we need to install the required package using the following command in our python environment.

Now we see below how the package is used to point out the wrongly spelled words as well as make some suggestions about possible correct words.

When we run the above program we get the following output −

Case Sensitive

If we use Let in place of let then this becomes a case sensitive comparison of the word with the closest matched words in dictionary and the result looks different now.

Spell Checker in Python

In this tutorial, we will learn about how to check the spelling and suggest corrections for words that are miss-spelled using Python. We will learn about autocorrect, textblob, and pyspellchecker packages for it using different examples.
The spell checker is a crucial part of text-processing.

Using autocorrect in Python

First, we will install it using the command

After installation, we will import the Speller class from autocorrect and create an object that uses the English language (lang = ‘en’) which we will use to do spelling corrections.

The misspelled words present in the sentence passed to check object will be identified and auto-corrected as shown below:

Its corresponding output is as follows:

As you can see that the misspelled words in the input were “leerning”, “misspeled “, and “wods” which has been corrected as “learning “, “misspelled “, and “words”, respectively.

Using TextBlob: Check spellings

First, we will install it using the command

Now, we will import textblob package as follows:

We will take our input string

We have split input strings using space as a delimiter and store into a list. Now, we will iterate through each element of the list and find its correct word.

Its corresponding output is as follows:

Using pyspellchecker to check spelling in Python

First, we will install and import it using the command

The correction() function returns the most likely option for the input and candidates() functions return the all possible likely options for it.

Take input and split as we have done before.

The unknown() function will return a Python set of the potentially misspelled words.

Now, we will iterate through each element and find its correction() and candidates().

pyspellchecker

The pyspellchecker package allows you to perform spelling corrections, as well as see candidate spellings for a misspelled word. To install the package, you can use pip:

Once installed, the pyspellchecker is really straightforward to use. Note that even though we use “pyspellchecker” when installing via pip, we just type “spellchecker” in the package import statement. The first piece is to create a SpellChecker object, which we’ll just call “spell”.

from spellchecker import SpellChecker spell = SpellChecker()

Now, we’re ready to test this out with a few misspellings. We’ll use a few words from this list of commonly misspelled words.

To attempt a correction, you can use the correction method:

pyspellchecker also has a method to split the words in a sentence.

spell.split_words("this sentnce has misspelled werds")

Once we have a list of the words in the sentence, we can just loop over each word using our SpellChecker object.

words = spell.split_words("this sentnce has misspelled werds") [spell.correction(word) for word in words]

If you just want to flag what words in a sentence are misspelled you can use the unknown method. This method will return a Python set of the potentially misspelled words.

We can also see the candidate spellings for a misspelled word.

TextBlob

The powerful TextBlob can also do spelling corrections. To install TextBlob we can use pip (note all lowercase):

pip install textblob

To use TextBlob’s spellchecking functionality, we just need to import the Word class. Then we can input a word and check its spelling using the spellcheck method, like below.

from textblob import Word

word = Word('percieve') word.spellcheck()

As can be seen above, TextBlob returns two pieces – a recommended correction for this word, and a confidence score associated with the correction. In this case, we just get one word back with a confidence of 1.0, or 100%.

Let’s try another word that returns multiple possibilities. If we input the string “personell”, we get a list of possible corrections with confidence scores because this string is fairly similar in spelling to a few different words.

#[('personal', 0.65), #('personally', 0.2642857142857143), # ('peroneal', 0.06428571428571428), # ('personnel', 0.014285714285714285), # ('personen', 0.007142857142857143)]

According to its documentation, TextBlob’s spelling correction feature is about 70% accurate.

autocorrect

The last package we’ll examine is called autocorrect. Again, we can install this package with pip:

Once installed, we’ll import the Speller class from autocorrect. Then we’ll create an object that uses the English language (lang = ‘en’). We’ll use this object to do spelling corrections.

autocorrect import Speller

check =Speller(lang=’en’)

Next, we can input a sentence to our object, and it will attempt to correct any misspellings.

check("does this sentece have misspelled wordz?")

Spell Checker for Python

I’m fairly new to Python and NLTK. I am busy with an application that can perform spell checks (replaces an incorrectly spelled word with the correct one). I’m currently using the Enchant library on Python 2.7, PyEnchant and the NLTK library. The code below is a class that handles the correction/replacement.

I have written a function that takes in a list of words and executes replace() on each word and then returns a list of those words, but spelled correctly.

Now, I don’t really like this because it isn’t very accurate and I’m looking for a way to achieve spelling checks and replacements on words. I also need something that can pick up spelling mistakes like «caaaar»? Are there better ways to perform spelling checks out there? If so, what are they? How does Google do it? Because their spelling suggester is very good.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *