C# Class SpellChecker.Net.Search.Spell.SpellChecker

Spell Checker class (Main class)
(initially inspired by the David Spencer code).

Example Usage:

 SpellChecker spellchecker = new SpellChecker(spellIndexDirectory); // To index a field of a user index: spellchecker.indexDictionary(new LuceneDictionary(my_lucene_reader, a_field)); // To index a file containing words: spellchecker.indexDictionary(new PlainTextDictionary(new File("myfile.txt"))); String[] suggestions = spellchecker.suggestSimilar("misspelt", 5); 
Afficher le fichier Open project: synhershko/lucene.net Class Usage Examples

Méthodes publiques

Méthode Description
ClearIndex ( ) : void

Removes all terms from the spell check index.

Close ( ) : void
CreateSearcher ( Lucene.Net.Store.Directory dir ) : IndexSearcher

Creates a new read-only IndexSearcher (for testing purposes)

Dispose ( ) : void
Exist ( System word ) : bool

Check whether the word exists in the index.

GetStringDistance ( ) : StringDistance

Returns the StringDistance instance used by this SpellChecker instance.

IndexDictionary ( IDictionary dict ) : void

Indexes the data from the given IDictionary.

IndexDictionary ( IDictionary dict, int mergeFactor, int ramMB ) : void

Index a Dictionary

SetAccuracy ( float minScore ) : void

Set the accuracy 0 < min < 1; default 0.5

SetSpellIndex ( Lucene.Net.Store.Directory spellIndexDir ) : void

Use a different index as the spell checker index or re-open the existing index if spellIndex is the same value as given in the constructor.

SpellChecker ( Lucene.Net.Store.Directory spellIndex ) : System

Use the given directory as a spell checker index with a LevenshteinDistance as the default StringDistance. The directory is created if it doesn't exist yet.

SpellChecker ( Lucene.Net.Store.Directory spellIndex, StringDistance sd ) : System

Use the given directory as a spell checker index. The directory is created if it doesn't exist yet.

SuggestSimilar ( System word, int num_sug ) : System.String[]

Suggest similar words

SuggestSimilar ( System word, int numSug, Lucene.Net.Index.IndexReader ir, System field, bool morePopular ) : System.String[]

Suggest similar words (restricted or not to a field of a user index)

setStringDistance ( StringDistance sd ) : void

Sets the StringDistance implementation for this SpellChecker instance.

Méthodes protégées

Méthode Description
Dispose ( bool disposeOfManagedResources ) : void

Private Methods

Méthode Description
Add ( Lucene.Net.Search.BooleanQuery q, System k, System v ) : void

Add a clause to a boolean query.

Add ( Lucene.Net.Search.BooleanQuery q, System k, System v, float boost ) : void

Add a clause to a boolean query.

AddGram ( System text, Lucene.Net.Documents.Document doc, int ng1, int ng2 ) : void
CreateDocument ( System text, int ng1, int ng2 ) : Lucene.Net.Documents.Document
EnsureOpen ( ) : void
FormGrams ( System text, int ng ) : System.String[]

Form all ngrams for a given word.

GetMax ( int l ) : int
GetMin ( int l ) : int
IsClosed ( ) : bool

Returns true if and only if the SpellChecker is closed, otherwise false.

ObtainSearcher ( ) : IndexSearcher
ReleaseSearcher ( IndexSearcher aSearcher ) : void
SwapSearcher ( Lucene.Net.Store.Directory dir ) : void

Method Details

ClearIndex() public méthode

Removes all terms from the spell check index.
public ClearIndex ( ) : void
Résultat void

Close() public méthode

public Close ( ) : void
Résultat void

CreateSearcher() public méthode

Creates a new read-only IndexSearcher (for testing purposes)
public CreateSearcher ( Lucene.Net.Store.Directory dir ) : IndexSearcher
dir Lucene.Net.Store.Directory dir the directory used to open the searcher
Résultat Lucene.Net.Search.IndexSearcher

Dispose() public méthode

public Dispose ( ) : void
Résultat void

Dispose() protected méthode

protected Dispose ( bool disposeOfManagedResources ) : void
disposeOfManagedResources bool
Résultat void

Exist() public méthode

Check whether the word exists in the index.
public Exist ( System word ) : bool
word System String ///
Résultat bool

GetStringDistance() public méthode

Returns the StringDistance instance used by this SpellChecker instance.
public GetStringDistance ( ) : StringDistance
Résultat StringDistance

IndexDictionary() public méthode

Indexes the data from the given IDictionary.
public IndexDictionary ( IDictionary dict ) : void
dict IDictionary dict the dictionary to index
Résultat void

IndexDictionary() public méthode

Index a Dictionary
public IndexDictionary ( IDictionary dict, int mergeFactor, int ramMB ) : void
dict IDictionary the dictionary to index
mergeFactor int mergeFactor to use when indexing
ramMB int the max amount or memory in MB to use
Résultat void

SetAccuracy() public méthode

Set the accuracy 0 < min < 1; default 0.5
public SetAccuracy ( float minScore ) : void
minScore float
Résultat void

SetSpellIndex() public méthode

Use a different index as the spell checker index or re-open the existing index if spellIndex is the same value as given in the constructor.
public SetSpellIndex ( Lucene.Net.Store.Directory spellIndexDir ) : void
spellIndexDir Lucene.Net.Store.Directory spellIndexDir the spell directory to use
Résultat void

SpellChecker() public méthode

Use the given directory as a spell checker index with a LevenshteinDistance as the default StringDistance. The directory is created if it doesn't exist yet.
public SpellChecker ( Lucene.Net.Store.Directory spellIndex ) : System
spellIndex Lucene.Net.Store.Directory the spell index directory
Résultat System

SpellChecker() public méthode

Use the given directory as a spell checker index. The directory is created if it doesn't exist yet.
public SpellChecker ( Lucene.Net.Store.Directory spellIndex, StringDistance sd ) : System
spellIndex Lucene.Net.Store.Directory the spell index directory
sd StringDistance the measurement to use
Résultat System

SuggestSimilar() public méthode

Suggest similar words
public SuggestSimilar ( System word, int num_sug ) : System.String[]
word System String the word you want a spell check done on ///
num_sug int int the number of suggest words ///
Résultat System.String[]

SuggestSimilar() public méthode

Suggest similar words (restricted or not to a field of a user index)
public SuggestSimilar ( System word, int numSug, Lucene.Net.Index.IndexReader ir, System field, bool morePopular ) : System.String[]
word System String the word you want a spell check done on ///
numSug int int the number of suggest words ///
ir Lucene.Net.Index.IndexReader the indexReader of the user index (can be null see field param) ///
field System String the field of the user index: if field is not null, the suggested /// words are restricted to the words present in this field. ///
morePopular bool boolean return only the suggest words that are more frequent than the searched word /// (only if restricted mode = (indexReader!=null and field!=null) ///
Résultat System.String[]

setStringDistance() public méthode

Sets the StringDistance implementation for this SpellChecker instance.
public setStringDistance ( StringDistance sd ) : void
sd StringDistance the implementation for this /// instance.
Résultat void