See how to use the Whoosh spell checker.
This module contains functions/classes using a Whoosh index as a backend for a spell-checking engine.
Implements a spell-checking engine using a search index for the backend storage and lookup. This class is based on the Lucene contributed spell- checker code.
To use this object:
st = store.FileStorage("spelldict")
sp = SpellChecker(st)
sp.add_words([u"aardvark", u"manticore", u"zebra", ...])
# or
ix = index.open_dir("index")
sp.add_field(ix, "content")
suggestions = sp.suggest(u"ardvark", number = 2)
Parameters: |
|
---|
Adds the terms in a field from another index to the backend dictionary. This method calls add_scored_words() and uses each term’s frequency as the score. As a result, more common words will be suggested before rare words. If you want to calculate the scores differently, use add_scored_words() directly.
Parameters: |
|
---|
Adds a list of (“word”, score) tuples to the backend dictionary. Associating words with a score lets you use the ‘usescores’ keyword argument of the suggest() method to order the suggestions using the scores.
Parameters: |
|
---|
Adds a list of words to the backend dictionary.
Parameters: |
|
---|
Returns the backend index of this object (instantiating it if it didn’t already exist).
Returns a list of suggested alternative spellings of ‘text’. You must add words to the dictionary (using add_field, add_words, and/or add_scored_words) before you can use this.
Parameters: |
|
---|---|
Return type: | list |
Returns a list of possible alternative spellings of ‘text’, as (‘word’, score, weight) triples, where ‘word’ is the suggested word, ‘score’ is the score that was assigned to the word using SpellChecker.add_field() or SpellChecker.add_scored_words(), and ‘weight’ is the score the word received in the search for the original word’s ngrams.
You must add words to the dictionary (using add_field, add_words, and/or add_scored_words) before you can use this.
This is a lower-level method, in case an expert user needs access to the raw scores, for example to implement a custom suggestion ranking algorithm. Most people will want to call suggest() instead, which simply returns the top N valued words.
Parameters: |
|
---|---|
Return type: | list |