C# Class SIL.CoreImpl.SpellingHelper

This class manages a dictionary of (currently) Hunspell objects so that we can do spell checking.
Mostrar archivo Open project: sillsdev/FieldWorks Class Usage Examples

Public Methods

Method Description
AddAnySpellingExceptionsFromBackup ( string backupPath ) : void

Used in restoring backups, copy the specified file, typically an exc, to the hunspell directory

Will not overwrite any existing files. Exceptions for vernacular dictionaries are wiped out when the dictionary is initialized.

DictionaryExists ( int ws, ILgWritingSystemFactory wsf ) : bool

Return true iff GetSpellChecker will return a non-null value.

DictionaryExists ( string dictId ) : bool

Return true iff GetSpellChecker will return a non-null value.

DictionaryId ( int ws, ILgWritingSystemFactory wsf ) : string

Return the string which should be used to request a dictionary for the specified writing system, or null if none will work.

EnsureDictionary ( int ws, ILgWritingSystemFactory wsf ) : ISpellEngine

Make sure that a dictionary exists for the specified writing system. Currently this will NOT do so if its spelling ID is set to None (in angle brackets). Callers may want to include code like this: var wsObj = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; if (wsObj.SpellCheckingId == "None") // add angle brackets around None wsObj.SpellCheckingId = wsObj.Id.Replace('-', '_'); Enhance JohnT: maybe code like that should be part of this method? But it is meant to just make sure the dictionary exists, once the right SpellCheckingId has been established.

GetDictionaryIds ( ) : IEnumerable

Get all the IDs that will produce dictionaries (without any tricks like prefix matching).

GetExceptionFileName ( string dictFileName ) : string

The file name where we store exceptions is unfortunately the short-file-name version of the dictionary. We can't easily change this, so that is what we have to deal with any time we care about it.

GetSpellChecker ( int ws, ILgWritingSystemFactory wsf ) : ISpellEngine

Get a dictionary for the specified writing system, or null if we don't know of one. We ideally want a dictionary that exactly matches the specified writing system, that is, the file name for the .dic file == the SpellCheckDictionary of the writing system. If we can't find such a dictionary, for major languages (those we didn't create from wordform inventory), we will return a dictionary that shares a prefix, for example, 'en' when looking for 'en_US' or vice versa. This is not allowed for vernacular languages (where the dictionary is one we created ourselves); we return null if we can't find an exact match or an approximate match that is a 'major' language dictionary.

IsVernacular ( string dictId ) : bool

A dictionary is considered vernacular if it contains our special word. That is, we presume it is one we created and can rewrite if we choose; and it should not be used for any dictionary ID that is not an exact match.

PathsToBackup ( string dictId ) : IEnumerable

Return the files that should be backed up for the given dictionary. For now this is just the exc file, if it exists, and if the dictionary is not vernacular. (We assume any major language dictionary can be recovered from somewhere, and a vernacular one can be rebuilt from the WFI.)

ResetDictionary ( string id, IEnumerable words ) : void

Reset the whole dictionary for this ID. Henceforth it will contain exactly the words passed. Note that this will not affect any existing ISpellEngine; try not to have any left around.

SetSpellingStatus ( string word, int ws, ILgWritingSystemFactory wsf, bool fCorrect ) : void

Ensure that the spelling dictionary (if any) for the specified ws will give the specified answer regarding the specified word.

Private Methods

Method Description
AddAnySpellingExceptionsFromBackup ( string backupDictionaryPath, string destinationPath ) : void
ClearAllDictionaries ( ) : void

For testing (so far), clear all dictionaries so we can make a new one and verify persistence.

DictIdFromPath ( string path ) : string
DictionaryId ( string dictId ) : string
EnsureDictionary ( string dictId ) : void
GetDicPath ( string dirPath, string icuLocale ) : string

Get the path for the dictionary for a particular locale, if it is one of our private ones, given the path to the directory where we make them and the icuLocale.

GetShortName ( string input ) : string
GetShortPathName ( string lpszLongPath, char lpszShortPath, int cchBuffer ) : uint
GetSpellChecker ( string dictId ) : ISpellEngine
GetSpellingDirectoryPath ( ) : string

Locates the directory in which we look for and create hunspell dictionaries.

InitDictionary ( string dicPath, IEnumerable words ) : void
IsValidDictionary ( string path ) : bool
RawDictionaryId ( int ws, ILgWritingSystemFactory wsf ) : string
RawGetSpellChecker ( string dictId ) : SpellEngine
SpellingHelper ( ) : System

Method Details

AddAnySpellingExceptionsFromBackup() public static method

Used in restoring backups, copy the specified file, typically an exc, to the hunspell directory
Will not overwrite any existing files. Exceptions for vernacular dictionaries are wiped out when the dictionary is initialized.
public static AddAnySpellingExceptionsFromBackup ( string backupPath ) : void
backupPath string
return void

DictionaryExists() public static method

Return true iff GetSpellChecker will return a non-null value.
public static DictionaryExists ( int ws, ILgWritingSystemFactory wsf ) : bool
ws int
wsf ILgWritingSystemFactory
return bool

DictionaryExists() public static method

Return true iff GetSpellChecker will return a non-null value.
public static DictionaryExists ( string dictId ) : bool
dictId string
return bool

DictionaryId() public static method

Return the string which should be used to request a dictionary for the specified writing system, or null if none will work.
public static DictionaryId ( int ws, ILgWritingSystemFactory wsf ) : string
ws int
wsf ILgWritingSystemFactory
return string

EnsureDictionary() public static method

Make sure that a dictionary exists for the specified writing system. Currently this will NOT do so if its spelling ID is set to None (in angle brackets). Callers may want to include code like this: var wsObj = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; if (wsObj.SpellCheckingId == "None") // add angle brackets around None wsObj.SpellCheckingId = wsObj.Id.Replace('-', '_'); Enhance JohnT: maybe code like that should be part of this method? But it is meant to just make sure the dictionary exists, once the right SpellCheckingId has been established.
public static EnsureDictionary ( int ws, ILgWritingSystemFactory wsf ) : ISpellEngine
ws int
wsf ILgWritingSystemFactory
return ISpellEngine

GetDictionaryIds() public static method

Get all the IDs that will produce dictionaries (without any tricks like prefix matching).
public static GetDictionaryIds ( ) : IEnumerable
return IEnumerable

GetExceptionFileName() public static method

The file name where we store exceptions is unfortunately the short-file-name version of the dictionary. We can't easily change this, so that is what we have to deal with any time we care about it.
public static GetExceptionFileName ( string dictFileName ) : string
dictFileName string
return string

GetSpellChecker() public static method

Get a dictionary for the specified writing system, or null if we don't know of one. We ideally want a dictionary that exactly matches the specified writing system, that is, the file name for the .dic file == the SpellCheckDictionary of the writing system. If we can't find such a dictionary, for major languages (those we didn't create from wordform inventory), we will return a dictionary that shares a prefix, for example, 'en' when looking for 'en_US' or vice versa. This is not allowed for vernacular languages (where the dictionary is one we created ourselves); we return null if we can't find an exact match or an approximate match that is a 'major' language dictionary.
public static GetSpellChecker ( int ws, ILgWritingSystemFactory wsf ) : ISpellEngine
ws int
wsf ILgWritingSystemFactory
return ISpellEngine

IsVernacular() public static method

A dictionary is considered vernacular if it contains our special word. That is, we presume it is one we created and can rewrite if we choose; and it should not be used for any dictionary ID that is not an exact match.
public static IsVernacular ( string dictId ) : bool
dictId string
return bool

PathsToBackup() public static method

Return the files that should be backed up for the given dictionary. For now this is just the exc file, if it exists, and if the dictionary is not vernacular. (We assume any major language dictionary can be recovered from somewhere, and a vernacular one can be rebuilt from the WFI.)
public static PathsToBackup ( string dictId ) : IEnumerable
dictId string
return IEnumerable

ResetDictionary() public static method

Reset the whole dictionary for this ID. Henceforth it will contain exactly the words passed. Note that this will not affect any existing ISpellEngine; try not to have any left around.
public static ResetDictionary ( string id, IEnumerable words ) : void
id string
words IEnumerable
return void

SetSpellingStatus() public static method

Ensure that the spelling dictionary (if any) for the specified ws will give the specified answer regarding the specified word.
public static SetSpellingStatus ( string word, int ws, ILgWritingSystemFactory wsf, bool fCorrect ) : void
word string
ws int
wsf ILgWritingSystemFactory
fCorrect bool
return void