Spell Checker Primitives

Summary
Spell Checker Primitives
Macros
spell_bufferSpell the specified buffer.
spell_controlSpell control.
spell_dictionarySpell dictionary modifications.
spell_distanceEdit distance.
spell_stringSpell the specified word or line.
spell_suggestSuggest spelling of the the specified word.

Macros

spell_buffer

list spell_buffer(int start_line,
 [int end_line],
  [int tokenize = 1],
 [int suggest])

Spell the specified buffer.

Description

The spell_buffer() primitive spell checks the specified lines within the current buffer.

The string passed in should only be split on white space characters.

Furthermore, between calls to reset each string should be passed in exactly once and in the order they appeared in the document.  Passing in stings out of order, skipping strings or passing them in more than once may lead to undefined results.

Parameters

start_lineInteger line number, being the first line at which spell
end_lineOptional integer line number, denoting the line at which spell check shall complete.  If omitted checks are performed until the end-of-buffer.
tokenizeOptional integer flag, if specified as zero the buffer content shall not be split into tokens during parsing.
suggestOptional integer flag, if specified as non-zero spelling suggestions shall be returned against each misspelt word.

Returns

The spell_buffer() primitive returns a list of possible spelling errors in the form.

[<word>, <suggest-list|NULL>, <offset>, <column>, <line> [, <count>]]

Portability

A GriefEdit extension.

See Also

spell_string, spell_suggest, spell_control, spell_distance

spell_control

declare spell_control(int action,
 ...)

Spell control.

Description

The spell_control() primitive manipulates the spell engine attribute associated with the specified action.  Additional arguments are specific to the action or attribute being modified.

Parameters

actionInteger identifier of the engine attribute to be manipulated.
...Action specific value.
Modes
Action
Description
SPELL_DESCRIPTION
Spell implementation description, returns a string containing the name of the current speller.
SPELL_DICTIONARIES
List of available dictionaries, retrieves a list of string each the name of a available dictionary.
SPELL_LOAD
Load a personal dictionary.
SPELL_SAVE
Save to a personal dictionary.
SPELL_ADD
Add to the personal dictionary.
SPELL_IGNORE
Add to the spell ignore list.
SPELL_REPLACE
Add to the spell replacement list.
SPELL_LANG_ADD
n/a
SPELL_LANG_PRIMARY
n/a
SPELL_LANG_REMOVE
n/a

Returns

The spell_control() primitive usually, on success returns zero, otherwise -1 on error.

A few spell_control requests return non-integer values, either a string or list, based on the attribute that was manipulated by the specified action, see table above.

Portability

A GriefEdit extension.

See Also

spell_buffer, spell_string, spell_suggest, spell_distance

spell_dictionary

int spell_dictionary(int,
string|list)

Spell dictionary modifications.

Description

The spell_dictionary() primitive is reserved.

Parameters

n/a

Returns

The spell_dictionary() primitive returns -0 on success, otherwise -1 on error.

Portability

A GriefEdit extension.

See Also

spell_buffer, spell_string, spell_suggest, spell_control, spell_distance

spell_distance

int spell_distance(string a,
string b)

Edit distance.

Description

The spell_distance() primitive computes the “distance” between two words by counting the number of insert, replace, and delete operations required to permute one word into another.

In general the fewer operations required, the closer the match.  Some implementations assign varying scores to the insert, replace, and delete operations.  Another common variation varies which operations are considered when computing the distance; for example, the replace operation may not be considered, thereby defining the edit distance solely in terms of insert and delete options.

This algorithm uses one of the more popular algorithms in the edit distance known as the “Levenshtein distance”.

The costs assigned to each move are equal, that is of the following operations have a cost of 1.

  • Delete a character
  • Insert a character
  • Character substitution.

Parameters

s1String one.
s2Second string.

Returns

The spell_distance() primitive returns the edit distance between the two words.

Portability

A GriefEdit extension.

See Also

spell_buffer, spell_string, spell_suggest, spell_control,

spell_string

int spell_string(string word,
 [int length],
  [int tokenize = 0],
 [int suggest = FALSE])

Spell the specified word or line.

Description

The spell_string() primitive spell checks the specified string word

The string passed in should only be split on white space characters.

Furthermore, between calls to reset each string should be passed in exactly once and in the order they appeared in the document.  Passing in stings out of order, skipping strings or passing them in more than once may lead to undefined results.

Parameters

wordString containing the text to be checked.
lengthOptional integer, stating the number of characters within the string to be parsed.
tokenizeOptional integer flag, if specified as non-zero the string content shall be split into tokens during parsing.
suggestOptional integer flag, if specified as non-zero spelling suggestions shall be returned against each misspelt word.

Returns

The spell_string() primitive returns a value dependent on the input mode.

For word checks, 0 on success, other non-zero.

For string or line checks, list of possible incorrect words offset/line + length pairs with optional suggestion list, with offsets starting from 1.

[<word>, <suggest-list|NULL>, <offset>, <column>]

Portability

A GriefEdit extension.

See Also

spell_buffer, spell_suggest, spell_control, spell_distance

spell_suggest

list spell_suggest(string word,
 [int length])

Suggest spelling of the the specified word.

Description

The spell_distance() primitive spell checks the specified word building a list of possible suggestions.

Parameters

wordxxx
lengthxxx

Returns

The spell_suggest() primitive returns a list of possible suggestions, otherwise null.

Portability

A GriefEdit extension.

See Also

spell_buffer, spell_string, spell_control, spell_distance

$Id: $

To send feedback on this topic email: grie.nosp@m.fedit@gmai.nosp@m.l.com

Copyright © Adam Young All Rights Reserved.

list spell_buffer(int start_line,
 [int end_line],
  [int tokenize = 1],
 [int suggest])
Spell the specified buffer.
declare spell_control(int action,
 ...)
Spell control.
int spell_dictionary(int,
string|list)
Spell dictionary modifications.
int spell_distance(string a,
string b)
Edit distance.
int spell_string(string word,
 [int length],
  [int tokenize = 0],
 [int suggest = FALSE])
Spell the specified word or line.
list spell_suggest(string word,
 [int length])
Suggest spelling of the the specified word.