This page was generated
September  12,  2012
6:00  AM
XQuery & XSLT Built-In & Modules Function Reference

Built-In: Spell

The spelling correction built-in functions are used with dictionary documents to compare words with words in the dictionary. These functions use the double metaphone algorithm, which uses the way words sound to try and suggest spelling alternatives for incorrectly-spelled words.

There is also a Spelling Dictionary Management XQuery module, which is used to load and manage dictionary documents, and is complimentary to the spelling built-in functions.

Function Summary
spell:double-metaphone Given a word returns the two metaphone keys.
spell:is-correct Returns true() if the specified word is spelled correctly, otherwise returns false().
spell:levenshtein-distance Given two strings, returns the Levenshtein distance between those strings.
spell:suggest Suggests a list of spellings for a word.
spell:suggest-detailed Suggests a list of spellings for a word.
Function Detail
spell:double-metaphone(
$word as xs:string
)  as   xs:string*
Summary:

Given a word returns the two metaphone keys. The primary and secondary metaphone keys which represent the phonetic encoding of two words are returned as a sequence of two strings. Double metaphone is an algorithm based on phonetic sounds useful in providing data to spelling correction suggestions.

Parameters:
$word : The word for phonetic matching.

Usage Notes:

The spell:double-metaphone function is a built-in function and does not require the import module statement in the XQuery prolog.

Example:
  spell:double-metaphone("smith")
  
=> smo xmt
Example:
  spell:double-metaphone("jones")
  
=> jns ans

spell:is-correct(
$uri as xs:string*,
$word as xs:string
)  as   xs:boolean
Summary:

Returns true() if the specified word is spelled correctly, otherwise returns false(). A word is considered to be spelled correctly if it is in the specified dictionary.

Parameters:
$uri : The URIs of the dictionarys to use.
$word : The word to check.

Usage Notes:

The spell:is-correct function is a built-in function and does not require the import module statement in the XQuery prolog.

Example:
  spell:is-correct("en-utf8.xml","occasionally")
  
  => true()

spell:levenshtein-distance(
$str1 as xs:string,
$str2 as xs:string
)  as   xs:integer?
Summary:

Given two strings, returns the Levenshtein distance between those strings. The Levenshtein distance is a measure of how many operations it takes to transform a string into another string, and it is useful in determining if a word is spelled correctly, or in simply comparing how "different" two words are.

Parameters:
$str1 : The first input string.
$str2 : The second input string.

Usage Notes:

The spell:levenshtein-distance function is a built-in function and does not require the import module statement in the XQuery prolog.

The spell:levenshtein-distance function throws an exception if one of the strings is 64 or more characters in length and the other is at least 1 character in length.


Example:
  spell:levenshtein-distance("albatros","albetros")
  
=> 1
Example:
  spell:levenshtein-distance("cat", "cats")
  
=> 1

spell:suggest(
$uri as xs:string*,
$word as xs:string,
[$options as node()?]
)  as   xs:string*
Summary:

Suggests a list of spellings for a word. Returns a sequence of the most likely spellings for the specified word.

Parameters:
$uri : The URIs of the dictionarys to use.
$word : The word for which you get spelling suggestions.
$options (optional): The options node for this suggest operation. The default is (). The node for the spell:suggest options must be in the http://marklogic.com/xdmp/spell namespace.

The spell:suggest options include:

<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 gven number. The default is 100.

Usage Notes:

The spell:suggest function is a built-in function and does not require the import module statement in the XQuery prolog.

The spell:suggest 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.


Example:
  spell:suggest("myDictionary.xml","occasionally")
  
=> occasionally occasional occasion occasions occasion's occasioned optionally educationally irrationally
Example:
  spell:suggest("spell.xml", "albetros")
  
=> albatross abettors alders alters Albert's Elbert's allegros alder's Walters abettor's

spell:suggest-detailed(
$uri as xs:string*,
$word as xs:string,
[$options as node()?]
)  as   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.

Parameters:
$uri : The URIs of the dictionarys to use.
$word : The word for which you get spelling suggestions.
$options (optional): The options node for this suggest operation. The default is (). The node for the spell:suggest-detailed options must be in the http://marklogic.com/xdmp/spell namespace.

The spell:suggest-detailed options include:

<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 gven number. The default is 100.

Usage Notes:

The spell:suggest-detailed function is a built-in function and does not require the import module statement in the XQuery prolog.

The spell:suggest-detailed 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.


Example:
  spell:suggest-detailed("myDictionary.xml","occasionally")
  
=> ()
Example:
  spell:suggest("spell.xml", "albetros")
  
  => 
<spell:suggestion original="albetros" dictionary="spell.xml">
  <spell:word 
         distance="26" 
         key-distance="0" 
         word-distance="95" 
         levenshtein-distance="2">
    albatross
  </spell:word>
</spell:suggestion>