Skip to content

Commit

Permalink
Update README.md with project details and usage instructions.
Browse files Browse the repository at this point in the history
Add examples for development, and add a banner and a logo.
  • Loading branch information
LyubomirT committed Nov 26, 2023
1 parent c751687 commit 42646f1
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 2 deletions.
184 changes: 183 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,183 @@
# lesp-oneword
<div align="center">
<h1>LESP - Lightweight Efficient Spelling Proofreader</h1>
<img src="branding/BANNER.png">
</div>

---

<div align="center">
<img src="https://img.shields.io/badge/Version-0.3.0-gold.svg" alt="version">
<img src="https://img.shields.io/badge/License-BSD%203--Clause-blue.svg" alt="license">
<img src="https://img.shields.io/badge/Python-3.2+-green.svg" alt="python">
<img src="https://img.shields.io/badge/Platform-Linux%20%7C%20Windows%20%7C%20macOS-lightgrey.svg" alt="platform">
<!-- No dependencies -->
<img src="https://img.shields.io/badge/Dependencies-none-red.svg" alt="dependencies">
</div>

## Welcome to the LESP repository! 👋

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.

## Features ✨

- Lightweight and efficient
- Easy to use
- Fast
- Cross-platform
- No dependencies
- (Kind of) Customizable

## Installation 📥

Simply clone the repository and run the `demo.py` file to check it out. You don't need to install any additional libraries, so this is like plug-and-play. Just note that anything below Python 3.2 won't run this since old versions don't support `concurrent.futures`, which is used to speed up the process.

### Detailed installation instructions

1. Clone the repository

```bash
git clone https://github.com/LyubomirT/lesp.git
```

2. Open the folder

```bash
cd lesp
```

3. Run the demo

```bash
python demo.py
```

## Usage 📖

LESP is pretty easy to setup, and basic configuration are already pre-built. You can find them in `config` and `demo_config` (these are files, not folders!) and you can edit them to your liking. Note that these files are **required** for the program to run, so don't delete, move, or rename them.

### Basic usage

To use LESP, you need to import `is_correct` and `get_similar` from the `lesp` module. Then, you can use them like this:

```python
from lesp import is_correct, get_similar

clearlynotcorrect = is_correct("apgle") # False

if not clearlynotcorrect:
print("Did you mean: " + get_similar("apgle")) # Did you mean: apple
```

Simple as that!

### Advanced usage

You can use a different wordlist by specifying it in the `config` file. Just note that the wordlist must be a `.txt` file, and it must be in the same folder as the file you want to run.

A wordlist must be structured with each word on a new line, like this:

```
apple
banana
orange
```

After you've done with putting a good wordlist in the directory, specify it in the `config` file like this:

```
wordlist="my_wordlist.txt"
```

You can customize the process of getting similar words as well. Configuration will be provided as arguments to the `get_similar` function. Here's an example:

```python
from lesp import get_similar

similar_words = get_similar("apgle", similarity_rate=0.5, chunks=4, upto=3)

print(similar_words)
```

In the code above, we're getting similar words to `apgle` with a similarity rate of 0.5, splitting the wordlist into 4 chunks, and returning up to 3 similar words.

A similarity rate of `0.5` means that the words returned will be at least 50% similar to the word we're checking. The higher the similarity rate, the more precise the results will be, but generally there will be less words. Myself I would recommend to keep the similarity rate at `0.5`, but you can experiment with it and see what works best for you.

The `chunks` argument specifies how many chunks the wordlist will be split into. This is useful if you have a large wordlist and you want to speed up the process. The higher the number, the faster the process will be, but the more memory/CPU it will consume. For example, when trying to scan `wordlist.txt` with 500 chunks, the process takes about 0.5 seconds on my machine, but it consumes about 1.5 GB of RAM and 44% of one of the CPU cores. If you have a large wordlist.

The `upto` argument specifies how many similar words will be returned. If you set it to `3`, then the function will return up to 3 similar words. If you set it to `1`, then it will return up to 1 similar word. But, whatever amount you select, the output will still be a list. If you set it to `0`, then the function will raise a `ValueError`.

### Get similarity score

Even if this function isn't really supposed to be a feature, you can still use it if you want to. It's pretty simple to use, just import `get_similarity_score` from the `lesp` module and use it like this:

```python
from lesp import get_similarity_score

score = get_similarity_score("apple", "apgle") # 0.8

print(score)
```

The function will return a float between 0 and 1, where 0 means that the words are completely different, and 1 means that the words are exactly the same.

## 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.

## Contributing 🤝

Contributions, issues and feature requests are welcome! Feel free to check out the [issues page](https://github.com/LyubomirT/lesp/issues).

### How to contribute?

Thank you for your interest in contributing to LESP! Here's a quick guide on how to contribute:

1. Fork the repository

```bash
git clone https://github.com/LyubomirT/lesp.git
```

2. Make your changes

3. Test your changes to make sure everything works as expected

4. Commit your changes

```bash
git commit -m "Your changes"
```

5. Push your changes

```bash
git push
```

6. Open a pull request

7. Wait for your pull request to be reviewed

Once again, thank you for your support!

## Reach out to the developer 👨‍💻

You can contact me on Discord either in my [Discord Server](https://discord.gg/XkjPDcSfNz) or in my DMs (@lyubomirt). Creating a discussion might also work, but I'm a bit faster to respond on Discord.

## Future plans 📅

- [ ] Optimize even further
- [ ] Add more examples
- [ ] Improve documentation
- [ ] Add support for compounds

## License 📜

This project is licensed under the BSD 3-Clause License. For more information, please refer to the `LICENSE` file.

## Acknowledgements 🙏

Many thanks to the following Open-Source projects:

- [Google 10000 English](https://github.com/first20hours/google-10000-english) - `small_wordlist.txt`
- [English Word List](https://github.com/dwyl/english-words) - `wordlist.txt`
Binary file added branding/BANNER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added branding/LESP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ac.autocorrect import is_correct, get_similar
from lesp.autocorrect import is_correct, get_similar

def load_config():
with open("demo_config", "r") as f:
Expand Down
19 changes: 19 additions & 0 deletions examples/A Simple Spell Checker/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from lesp import is_correct, get_similar

# Read a text file and check for spelling errors
with open("text.txt", "r") as f:
text = f.read()

# Split the text into words
words = text.split()

# Loop through the words and check if they are correct
for word in words:
# Remove punctuation and make lowercase
word = word.strip(".,").lower()
# Check if the word is correct
if not is_correct(word):
# Get a suggestion for the word
suggestion = get_similar(word, similarity_rate=0.5, upto=1)
# Print the word and the suggestion
print(f"{word} -> {suggestion}")
31 changes: 31 additions & 0 deletions examples/A Word Game/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from lesp import get_similar
import random

# A list of words to choose from
words = ["apple", "banana", "orange", "grape", "melon", "cherry", "lemon", "lime", "pear", "peach"]

# Pick a random word
word = random.choice(words)

# Get three similar words with a similarity rate of 0.4
similar_words = get_similar(word, similarity_rate=0.4, upto=3)

# Add the original word to the list
similar_words.append(word)

# Shuffle the list
random.shuffle(similar_words)

# Print the list
print("Which of these words is not like the others?")
for i, w in enumerate(similar_words):
print(f"{i + 1}. {w}")

# Get the user's answer
answer = int(input("Enter your answer: "))

# Check if the answer is correct
if similar_words[answer - 1] == word:
print("Correct!")
else:
print(f"Wrong! The correct answer is {word}.")
49 changes: 49 additions & 0 deletions examples/Similarity Score Calculator/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Import the get_similarity_score function from the lesp module
from lesp import get_similarity_score

# Import tkinter for creating a graphical user interface
import tkinter as tk

# Create a window
window = tk.Tk()
window.title("Word Similarity App")

# Create a label for the first word
label1 = tk.Label(window, text="Enter the first word:")
label1.pack()

# Create an entry for the first word
entry1 = tk.Entry(window)
entry1.pack()

# Create a label for the second word
label2 = tk.Label(window, text="Enter the second word:")
label2.pack()

# Create an entry for the second word
entry2 = tk.Entry(window)
entry2.pack()

# Create a button for calculating the similarity score
button = tk.Button(window, text="Calculate")

# Define a function for calculating the similarity score
def calculate():
# Get the words from the entries
word1 = entry1.get()
word2 = entry2.get()
# Calculate the similarity score
score = get_similarity_score(word1, word2)
# Display the similarity score
result.config(text=f"The similarity score is {score:.2f}")

# Bind the function to the button
button.config(command=calculate)
button.pack()

# Create a label for displaying the similarity score
result = tk.Label(window, text="")
result.pack()

# Start the main loop of the window
window.mainloop()
File renamed without changes.
5 changes: 5 additions & 0 deletions ac/autocorrect.py → lesp/autocorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def get_similar_worker(args):
def get_similar(word, similarity_rate, chunks=4, upto=3):
if upto < 1:
raise ValueError("Can only return 1 or more similar words.")
if chunks < 1:
raise ValueError("Can only split into 1 or more chunks.")
if similarity_rate < 0 or similarity_rate > 1:
raise ValueError("Similarity rate must be between 0 and 1.")

word = word.lower()
similar_words = []
chunk_size = len(wordlist) // chunks
Expand Down

0 comments on commit 42646f1

Please sign in to comment.