Loading TOC...

spell.suggestDetailed

spell.suggestDetailed(
   $dictionary_uris as String[],
   $word as String,
   [$options as Object?]
) as Array

Summary

Suggests a list of spellings for a word. Returns an array of objects describing each suggestion, including the suggested word, the distance, the key distance, the word distance, and the levenshtein distance. You can use this extra information to make your own decisions about which suggestions to use. If you do not want to use this information, use the spell.suggest function instead.

Parameters
$dictionary_uris The URIs of the dictionaries to use.
$word The word for which you get spelling suggestions.
$options The options node for this suggest operation. The default is null.

The spell.suggestDetailed options include:

maximum
Specifies the maximum number of suggestions to be returned. The default is 10.
distanceThreshold
Specifies a cut off threshold for suggestions having a distance less than the given number. The distance is a weighted number indicating the "distance" between two words, where lower numbers indicate a closer match. The default is 100, which means that distances less than or equal to 100 are considered as suggestions.

Usage Notes

The spell.suggestDetailed function is built-in and does not require importing any separate module.

The spell.suggestDetailed function only provides suggestions to words that are less than 64 characters in length; words 64 characters or longer return no suggestions. Also, it removes any dictionary entries that are 64 characters or more, so it will never return a suggestion with greater than 64 characters.

The keyDistance and wordDistance values in the output are used by the double metaphone algorithm to calculate the distance, which is a weighted number indicating how close a word is to the one in the dictionary.

Example

spell.suggestDetailed("myDictionary.xml","occasionally");

=> ()

Example

two-words.xml:

   <dictionary xmlns="http://marklogic.com/xdmp/spell">
   <word>albatross</word>
   <word>albatrosses</word>
   </dictionary>

// preparatory

declareUpdate();
xdmp.documentLoad("/space/two-words.xml");

// then run spell.suggestDetailed

spell.suggestDetailed("/space/two-words.xml",
                      "albetros",
                      { 
		        "maximum": 5,
                        "distanceThreshold":500
                      });
==>
[
{
"original": "albatros",
"word": "albatross",
"dictionary": "/space/two-words.xml",
"distance": 9,
"keyDistance": 0,
"wordDistance": 45,
"levenshteinDistance": 1
},
{
"original": "albatros",
"word": "albatrosses",
"dictionary": "/space/two-words.xml",
"distance": 48,
"keyDistance": 1,
"wordDistance": 135,
"levenshteinDistance": 3
}
]

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy