C# Класс 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); 
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
Dispose ( bool disposeOfManagedResources ) : void

Приватные методы

Метод Описание
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

Описание методов

ClearIndex() публичный Метод

Removes all terms from the spell check index.
public ClearIndex ( ) : void
Результат void

Close() публичный Метод

public Close ( ) : void
Результат void

CreateSearcher() публичный Метод

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
Результат Lucene.Net.Search.IndexSearcher

Dispose() публичный Метод

public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

protected Dispose ( bool disposeOfManagedResources ) : void
disposeOfManagedResources bool
Результат void

Exist() публичный Метод

Check whether the word exists in the index.
public Exist ( System word ) : bool
word System String ///
Результат bool

GetStringDistance() публичный Метод

Returns the StringDistance instance used by this SpellChecker instance.
public GetStringDistance ( ) : StringDistance
Результат StringDistance

IndexDictionary() публичный Метод

Indexes the data from the given IDictionary.
public IndexDictionary ( IDictionary dict ) : void
dict IDictionary dict the dictionary to index
Результат void

IndexDictionary() публичный Метод

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
Результат void

SetAccuracy() публичный Метод

Set the accuracy 0 < min < 1; default 0.5
public SetAccuracy ( float minScore ) : void
minScore float
Результат void

SetSpellIndex() публичный Метод

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
Результат void

SpellChecker() публичный Метод

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
Результат System

SpellChecker() публичный Метод

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
Результат System

SuggestSimilar() публичный Метод

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 ///
Результат System.String[]

SuggestSimilar() публичный Метод

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) ///
Результат System.String[]

setStringDistance() публичный Метод

Sets the StringDistance implementation for this SpellChecker instance.
public setStringDistance ( StringDistance sd ) : void
sd StringDistance the implementation for this /// instance.
Результат void