Skip to content

Commit

Permalink
Add remove_special method to Proofreader class
Browse files Browse the repository at this point in the history
  • Loading branch information
LyubomirT committed Dec 7, 2023
1 parent 6ac46a1 commit 2ca3172
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions lesp/autocorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" }
Expand Down

0 comments on commit 2ca3172

Please sign in to comment.