From 2ca3172fe6b0907cb1ab294bda9775dffc6e01bd Mon Sep 17 00:00:00 2001 From: LyubomirT Date: Thu, 7 Dec 2023 13:16:02 +0200 Subject: [PATCH] Add remove_special method to Proofreader class --- README.md | 16 ++++++++++++++++ lesp/autocorrect.py | 22 ++++++++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f9fcd9f..5af3ac4 100644 --- a/README.md +++ b/README.md @@ -304,6 +304,22 @@ similar_words2 = proofreader.get_similar("apgle", similarity_rate=0.5, chunks=4, Here, `use_cache` is responsible for using the loaded cache file (if it exists) and `set_cache` helps you to add a new mistake to cache. If you set `set_cache` to `True`, then the function will add the mistake to cache, so the next time you check the same word, it will be much faster with `use_cache` enabled. +### Removing Special Characters + +Sometimes, a string may contain special characters, such as `!`, `?`, `@`, etc. These characters can be removed using the `remove_special` method. It covers most of the special characters out there, but not all of them. So if you find a special character that is not covered, please open an issue and I'll add it. Here's an example: + +```python +from lesp.autocorrect import Proofreader + +proofreader = Proofreader(wordlist="my_wordlist.txt") + +word = "apgle!" +word = proofreader.remove_special(word) # apgle + +if not proofreader.is_correct(word): # Not correct, of course + print("Did you mean: " + proofreader.get_similar(word)) # Did you mean: apple +``` + ## Examples 📝 If you're still not sure where to use LESP, you can check out the `examples` folder. It contains some examples of how you can use LESP in your projects. These examples are pretty simple, but they should give you an idea of how you can use LESP in your projects. diff --git a/lesp/autocorrect.py b/lesp/autocorrect.py index bfe2097..adb384d 100644 --- a/lesp/autocorrect.py +++ b/lesp/autocorrect.py @@ -579,4 +579,26 @@ def clear_cache(self, cache_file: str = "lesp_cache/lesp.cache") -> None: else: raise ValueError("Cache file not specified!") + def remove_special(self, word: str) -> str: + """ + Removes special characters from a word. + + Args: + word (str): Word to remove special characters from. + + Returns: + str: Word without special characters. + + Raises: + None + + Requires: + The word must be a string. + """ + special_chars: str = "!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~" + for char in special_chars: + word = word.replace(char, "") + + return word + diff --git a/pyproject.toml b/pyproject.toml index 56bba37..f29f2f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "lesp" description = "LESP is a lightweight, efficient spelling proofreader written in Python. It's designed to be easy to use and lightweight, while still providing a decent result when checking for spelling errors. Resource consumption is kept to a minimum, and the program is designed to be as fast as possible." -version = "1.0.4" +version = "1.1.0" readme = "PYPI.md" authors = [ { name = "Lyubomir Ternavskiy", email = "ternavski103@gmail.com" }