Provides a non-visual spellchecking engine that runs in the background behind PHP SpellCheck. Knowledge of this class is useful for building custom spellchecking apps, and setting up PHPSpellCheck settings files.
Class PHPSpellCheck
PHP Spell Check > Documentation > PHP Object Reference > Class PHPSpellCheck
- 2 Properties
- 3 Key Methods
- 3.1 didYouMean( $text )
- 3.2 SpellCheckWord ($word)
- 3.3 Suggestions( $word )
- 3.4 ErrorTypeWord( $word )
- 3.5 LoadDictionary( $dictionaryName )
- 3.6 ListDictionaries()
- 3.7 ListLiveDictionaries()
- 3.8 SetContext($tokens)
- 3.9 LoadCommonTypos( $filePath )
- 3.10 BuildCommonTypos($arrayOfCommonTypos)
- 3.11 LoadEnforcedCorrections( $filePath )
- 3.12 LoadCustomBannedWords( $filePath )
- 3.13 AddBannedWords($arrayOfBannedWords)
- 3.14 LoadCustomDictionary( $filePath )
- 3.15 AddCustomDictionaryFromArray($arrayOfWords)
- 3.16 LoadCustomDictionaryFromURL($url)
- 4 Helper Methods
Properties
DictionaryPath
- The Path relative to your PHPSpellCheck directory where dictionary files are stored.
- (string) [Default: "dictionaries/"]
IgnoreAllCaps
- Instructs the spell-checker to ignore FULLY CAPITALIZED WORDS, which are often abbreviations.
- (bool) [Default: true]
IgnoreNumeric
- Instructs the spell-checker to ignore words containing numbers such as "#BTS787" or "8Ball".
- The spellchecker is aware of XML and HTML markup URLS and EMail addresses - and will remain so even if IgnoreNumeric is set false
- (bool) [Default: true]
CaseSensitive
- Instructs the spell-checker to consider the CaSe of a word when spell checking.
- (bool) [Default: true]
SuggestionTollerance
- Sets the bar of acceptability of suggestions.
- A higher SuggestionTollerance will provide more phonetic spell checking results.
- (int) [Default: 1]
LicenceKey
- Your LicenseKey if applicable.
- (string) [Default: "TRIAL"]
Key Methods
didYouMean( $text )
- Suggests the most likely correctly spelled string to the string $input.
- arguments: (string) $text
- returns (string)
SpellCheckWord ($word)
- Returns true if $word is found in any of the loaded Dictionaries or in a Custom Dictionary
- arguments: (string) $word
- returns (boolean)
Suggestions( $word )
- Returns spelling suggestions for (string) $word.
- Suggestions are listed in probability order - most probable coming first.
- arguments: (string) $word
- returns (array) of strings
ErrorTypeWord( $word )
- Returns a (char) that explains why $word is not a valid word.
- "E" - Enforced Correction
- "B" - Word is on your banned words list
- "C" - A CaSe Mistake
- "X" - (infrequent) Unlicensed software
- "S" - Spelling mistake. Not found in any dictionary and none of the above cases apply.
- "" -$word is valid
- arguments: (string) $word
- returns (char)
LoadDictionary( $dictionaryName )
- Loads a Dictionary into the spellchecker.
- The (string) $dictionaryName rerers to a file with a .dic file extension in your DictionaryPath directory.
- E.G. LoadDictionary("English (international)") will load file: /phpspellcheck/dictionaries/English (international).dic
- arguments: (string) $dictionaryName
- returns null
ListDictionaries()
- Return an array of strings that relate to dictionaries that have been loaded.
- Also see LoadDictionary
- arguments: none
- returns (array) of strings
ListLiveDictionaries()
- Return an array of strings that relate to dictionaryNames of all installed DictionaryPath.
- Also see LoadDictionary
- returns (array) of dictionary names as strings.
SetContext($tokens)
- Allows the spell checker to see $tokens - the whole document context it is spellchecking in.
- This allows the spell-checker to use statistics on word usage to increase spelling suggestion accuracy.
- arguments: (array) $tokens is as a tokenized array of strings - which can be generated by must be set by the tokenizeString method.
- returns: null
LoadCommonTypos( $filePath )
- Loads a list of common typographic mistakes from a file relative to your DictionaryPath directory.
- Aids spell-checker suggestion accuracy.
- Example of such a file can be found at /phpspellcheck/dictionaries/langauge-rule/common-mistakes.txt
- arguments: (string) $filePath
- returns: null
herat-->heart
hewas-->he was
hismelf-->himself
...
BuildCommonTypos($arrayOfCommonTypos)
- Adds to a list of common typographic mistakes from an array which can be programmed or drawn from a database
- Aids spell-checker suggestion accuracy.
- arguments: (array) $arrayOfCommonTypos
- returns: null
heart","hewas-->he was","hismelf-->himself"))
?>
LoadEnforcedCorrections( $filePath )
- Loads a list of Enforced Corrections from a file.
- The (string) $filePath refers to a file within your DictionaryPath directory
- Example of such a file can be found at /phpspellcheck/dictionaries/langauge-rule/enforced-corrections.txt
- arguments: (string) $filePath
- returns: null
USA--> United States Of America || United States Army
LoadCustomBannedWords( $filePath )
- Loads a list of Banned Words from a text file, 1 word per line.
- A banned word can never spellcheck true.
- The (string) $filePath refers to a file within your DictionaryPath directory.
- Example of such a file can be found at /phpspellcheck/dictionaries/langauge-rule/banned-words.txt
- arguments: (string) $filePath
- returns: null
AddBannedWords($arrayOfBannedWords)
- Adds a list of Banned Words from an array of strings.
- $arrayOfBannedWords array can easily be populated from an SQL query.
- A banned word can never spellcheck true.
- arguments: (array) $arrayOfBannedWords
- returns: null
LoadCustomDictionary( $filePath )
- Loads additional vocabulary into the spell-checker from a file in the Dictionary Path directory.
- This document must return a document with 1 word on each line.
- Performance will be increased if the words are structured in ascending ascii sort order.
- An example of such a file can be found at /phpspellcheck/dictionaries/custom.txt
- arguments: (string) $filePath
- returns: null
AddCustomDictionaryFromArray($arrayOfWords)
- Loads additional vocabulary into the spell-checker from an array of words.
- arguments: (array) $arrayOfWords
- returns: null
LoadCustomDictionaryFromURL($url)
- Loads vocabulary into the spell-checker from a URL. The url may be remote or local.
- $url should be fully formed - starting with http://
- This URL must render a document with 1 word on each line.
- Performance will be increased if the words are structured in ascending ascii sort order.
- arguments: (string) $url
- returns: null
Helper Methods
tokenizeString( $text )
Accurately tokenizes (string) $text into an array of tokens.
- Each token is either:
- a word
- punctuation
- a number
- a url
- an email address
- arguments (string) $text
- returns (array) or strings.
CorrectCase($word, $startsASentence)
- returns the string $word in its correct CaSe as seen in the dictionary.
- arguments: (boolean) $StartsASentence , string $word
- returns (string)
BuildDictionary($ArrayOfWords)
- Builds and returns a complete .dic format dictionary.
- arguments (array) $ArrayOfWords is an array of each word that will appear in the dictionary.
- returns (string) of the entire dictionary, which can then be written to a file.