This page was generated
July 7, 2010
4:03 PM
XQuery Built-In and Modules Function Reference

Built-In: Spell

The spelling functions are designed to help you manage dictionary documents in MarkLogic Server, to use those dictionaries to check if words are spelled correctly, and to suggest possible spellings for words that are not spelled correctly. The spelling function module is installed as the following file:

  • install_dir/Modules/MarkLogic/spell.xqy

where install_dir is the directory in which MarkLogic Server is installed.

To use the spell.xqy module in your own XQuery modules, include the following line in your XQuery prolog:

import module "http://marklogic.com/xdmp/spell" at "/MarkLogic/spell.xqy"

The library uses the spell: namespace, predefined in the server.

The spelling correction functions (spell:is-correct and spell:suggest) are built-in functions and do not require the import module statement in the XQuery prolog.

Function Summary
spell:add-word Add the word $word to the dictionary at $uri.
spell:insert Load the words in $dict into the dictionary at $uri.
spell:is-correct Returns true() if the specified word is spelled correctly, otherwise returns false().
spell:load Add the words from the file specified in $path to the dictionary at $uri.
spell:remove-word Remove the word $word from the dictionary at $uri.
spell:suggest Suggests a list of spellings for a word.
Function Detail
spell:add-word(
$uri as xs:string,
$word as xs:string
)  as   empty-sequence()
Summary:

Add the word $word to the dictionary at $uri. If the word is already in the dictionary (case-sensitive), then this function throws an exception.

Parameters:
$uri : The URI of the dictionary.
$word : The word to add.

Example:
  xquery version "0.9-ml"
  import module "http://marklogic.com/xdmp/spell" 
		  at "/MarkLogic/spell.xqy"

  spell:add-word("/mySpell/spell.xml", "WebDAV")

  => adds the word "WebDAV" to the specifed dictionary
  

spell:insert(
$uri as xs:string,
$dict as element(spell:dictionary)
)  as   empty-sequence()
Summary:

Load the words in $dict into the dictionary at $uri. If there is no document at $uri a new one will be created. If there is a document at $uri it will be overwritten.

Parameters:
$uri : The URI of the dictionary.
$dict : A dictionary document.

Example:
  xquery version "0.9-ml"
  import module "http://marklogic.com/xdmp/spell" 
		  at "/MarkLogic/spell.xqy"

  spell:insert("/mySpell/special.xml", 
     <dictionary xmlns="http://marklogic.com/xdmp/spell">
          <word>WebDAV</word>
     </dictionary> )

  => Creates a dictionary with only the word "WebDAV" 
     at the specifed URI
  

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 URI of the dictionary 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:load(
$path as xs:string,
$uri as xs:string
)  as   empty-sequence()
Summary:

Add the words from the file specified in $path to the dictionary at $uri. If a document exists with the specified URI, it is replaced with this one.

Parameters:
$path : The path to a file containing the dictionary.
$uri : The URI of the dictionary.

Usage Notes:

Dictionaries loaded with the spell:load function are automatically added to the following collections:
  • http://marklogic.com/xdmp/documents
  • http://marklogic.com/xdmp/spell

Example:
  xquery version "0.9-ml"
  import module "http://marklogic.com/xdmp/spell" 
		  at "/MarkLogic/spell.xqy"

  spell:load("c:\dictionaries\spell.xml", "/mySpell/spell.xml")
  

spell:remove-word(
$uri as xs:string,
$word as xs:string
)  as   empty-sequence()
Summary:

Remove the word $word from the dictionary at $uri.

Parameters:
$uri : The URI of the dictionary.
$word : The word to remove.

Example:
  xquery version "0.9-ml"
  import module "http://marklogic.com/xdmp/spell" 
		  at "/MarkLogic/spell.xqy"

  spell:remove-word("/mySpell/spell.xml", "Fiat")

  => removes the word "Fiat" from the specified dictionary
  

spell:suggest(
$uri as xs:string,
$word as xs:string
)  as  xs:string*
Summary:

Suggests a list of spellings for a word. Returns a sequence of the ten most likely spellings for the specified word. Returns the empty sequence if the specified word is in the dictionary.

Parameters:
$uri : The dictionary from which to suggest spellings.
$word : The word for which you get spelling suggestions.

Usage Notes:

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

Example:
  spell:suggest("myDictionary.xml","occasionally")
  
=> ()
Example:
  spell:suggest("spell.xml", "albetros")
  
=> albatross abettors alders alters Albert's Elbert's allegros alder's Walters abettor's