Skip to content

Patch: Implement export of "Score". #365

@aspell-helper

Description

@aspell-helper

Ethan Bradford <ethanrbradford@sf> created a patch on 2006-05-17 05:05:19 UTC
(Orig. from https://sourceforge.net/p/aspell/patches/134)

I added API calls to export the "score" for each
suggestion. The score is the "distance" of a
suggestion from the original word. This can be used to
resort suggestions for a calling program which knows
something more about the words.

Here's the diff from the manual:

--- reference/aspell/aspell_0_60/manual/aspell.texi
2006-05-05 09:36:09.074874000 -0700
+++ aspell.texi 2006-05-16 16:49:01.891079000 -0700
@@ -2197,7 +2197,7 @@

@var{word}, @var{size});
AspellStringEnumeration * elements =
aspell_word_list_elements(suggestions);
const char * word;
-while ( (word =
aspell_string_enumeration_next(aspell_elements)) != NULL )
+while ( (word =
aspell_string_enumeration_next(elements)) != NULL )
@{
// add to suggestion list
@}
@@ -2206,7 +2206,30 @@

Notice how @code{elements} is deleted but
@code{suggestions} is not.
The value returned by @code{suggestions} is only valid
to the next
-call to @code{suggest}. Once a replacement is made the
+call to @code{suggest}.
+
+If you want to sort the Aspell words by some
additional criterion before
+presenting them, you should also take into account the
``score'' that
+Aspell used to sort them. The score gives the
``distance'' of the
+suggestion from the original, with increasing scores
giving increasing
+distances. To cycle through a list of suggestions
with scores,
+instead of the above example, copy this code:
+@smallexample
+AspellSuggestionList * suggestions =
aspell_speller_scored_suggest(
+
spell_checker,
+
@var{word}, @var{size});

+AspellSuggestionEnumeration * elements =
+
aspell_suggestion_list_elements(suggestions);
+const AspellSuggestion * sugg;
+while ( (sugg =
aspell_suggestion_enumeration_next(elements)) != NULL )
+@{
+ // Add to suggestion list sugg->word, of length
sugg->word_len, and
+ // with score sugg->score.
+@}
+delete_aspell_suggestion_enumeration(elements);
+@EnD smallexample
+
+Once a replacement is made the
@code{store_repl} method should be used to communicate
the replacement
pair back to the spell checker (for the reason,
@pxref{Notes on
Storing Replacement Pairs}). Its usage is as follows:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions