Find similarities
The LESP library provides a method called get_similar() that can be used to find similar words to a specified word. The method takes three parameters:
- word: The word to find similar words for.
- similarity_rate: The minimum similarity score that a word must have to be considered similar. The similarity rate is a float between 0 and 1, where 0 means no similarity and 1 means perfect similarity.
- upto: The maximum number of similar words to return.
- use_cache: The switch for using cache before running the scan algorithm.
- set_cache: The switch for adding the correction to cache after finding similarities.
The method returns a list of similar words, or None if no similar words were found.
Example Usage
from lesp import Proofreader
proofreader = Proofreader()
# Find words that are 0.8 or more similar to "hello"
similar_words = proofreader.get_similar("hello", 0.8)
print(similar_words)This code will print the following output:
['hallo', 'hello']Using the Cache
The LESP library can also use a cache to improve performance. The cache is a file that stores the results of previous calls to the get_similar() method. This can save time, especially if you are calling the method frequently.
To use the cache, you need to set the use_cache parameter to True when calling the get_similar() method. You can also set the set_cache parameter to True to save the results of the current call to the cache.
Example Usage
from lesp import Proofreader
proofreader = Proofreader()
# Find words that are 0.8 or more similar to "hello"
similar_words = proofreader.get_similar("hello", 0.8, use_cache=True, set_cache=True)
print(similar_words)This code will print the following output:
['hallo', 'hello']Clearing the Cache
The cache can be cleared using the clear_cache() method. This can be useful if you want to ensure that the results of the get_similar() method are up-to-date.
Last updated
