Loading TOC...

MarkLogic 9 Product Documentation
spell:suggest-detailed

spell:suggest-detailed(
   $dictionary_uris as xs:string*,
   $word as xs:string,
   [$options as (element()|map:map)?]
) as element(spell:suggestion)*

Summary

Suggests a list of spellings for a word. Returns a sequence of elements 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 Options with which to customize this operation. You can specify options as either an options XML element in the http://marklogic.com/xdmp/spell namespace, or as a map:map. The options names below are XML element localnames. When using a map, replace the hyphens with camel casing. For example, "an-option" becomes "anOption" when used as a map:map key. This function supports the following options:
maximum
Specifies the maximum number of suggestions to be returned. The default is 10.
distance-threshold
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

This function is built-in, so you do not need to import a library module to use it.

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

The key-distance and word-distance 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.

If there are no suggestions, this function returns an empty sequence.

Example

xquery version "1.0-ml";
spell:suggest-detailed("/my/dictionary.xml", "occasionally") 

(: Returns a sequence of spell:suggestion elements from the
 : dictionary with the URI "/my/dictionary.xml", similar to the following:

<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="0" key-distance="0" word-distance="0" 
      levenshtein-distance="0">occasionally</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="26" key-distance="0" word-distance="90" 
      levenshtein-distance="2">occasional</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="180" 
      levenshtein-distance="4">occasion</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="185" 
      levenshtein-distance="4">occasions</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="190" 
      levenshtein-distance="4">occasion's</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="190" 
      levenshtein-distance="4">occasioned</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="190" 
      levenshtein-distance="4">optionally</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="80" key-distance="1" word-distance="200" 
      levenshtein-distance="4">irrationally</spell:word>
</spell:suggestion>
:)

Example

(: Using an options element :)
xquery version "1.0-ml";
spell:suggest-detailed(
  "/my/dictionary.xml", "occasionally", 
  <options xmlns="http://marklogic.com/xdmp/spell">
    <distance-threshold>200</distance-threshold>
    <maximum>4</maximum>
  </options>
)

(: Returns a sequence of spell:suggestion elements similar to 
 : the following, based on the entries in the dictionary with the 
 : URI "/my/dictionary.xml":

<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="0" key-distance="0" word-distance="0" 
      levenshtein-distance="0">occasionally</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
      xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="26" key-distance="0" word-distance="90" 
      levenshtein-distance="2">occasional</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
      xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="180" 
      levenshtein-distance="4">occasion</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
      xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="185" 
      levenshtein-distance="4">occasions</spell:word>
</spell:suggestion>
:)

Example

(: Using an options map :)
xquery version "1.0-ml";
spell:suggest-detailed(
  "/my/dictionary.xml", "occasionally", 
  map:map() => map:with("distanceThreshold", 200)
            => map:with("maximum", 4)
)

(: Returns a sequence of spell:suggestion elements similar to 
 : the following, based on the entries in the dictionary with the 
 : URI "/my/dictionary.xml":

<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
    xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="0" key-distance="0" word-distance="0" 
      levenshtein-distance="0">occasionally</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
      xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="26" key-distance="0" word-distance="90" 
      levenshtein-distance="2">occasional</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
      xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="180" 
      levenshtein-distance="4">occasion</spell:word>
</spell:suggestion>
<spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" 
      xmlns:spell="http://marklogic.com/xdmp/spell">
  <spell:word distance="76" key-distance="1" word-distance="185" 
      levenshtein-distance="4">occasions</spell:word>
</spell:suggestion>
:)

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.