This page was generated
March  13,  2012
4:48  AM
XQuery & XSLT Built-In & Modules Function Reference

Module: Spelling Dictionary Management

The spelling functions are designed to help you manage dictionary documents in MarkLogic Server. 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 namespace spell = "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.

There are also Spell Built-In functions, which you use to check if words are spelled correctly according to the dictionaries and to suggest alternate spellings.

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:load Add the words from the file specified in $path to the dictionary at $uri.
spell:make-dictionary Creates a dictionary node from a sequence of words.
spell:remove-word Remove the word $word from the dictionary at $uri.
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 "1.0-ml";
  import module namespace spell = "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 "1.0-ml";
  import module namespace spell = "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: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. Note that words that are 64 characters or greater will never be returned as suggestions from spell:suggest or spell:suggest-detailed.

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 "1.0-ml";
  import module namespace spell = "http://marklogic.com/xdmp/spell" 
		  at "/MarkLogic/spell.xqy";

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

spell:make-dictionary(
$words as xs:string*
)  as   element(spell:dictionary)
Summary:

Creates a dictionary node from a sequence of words. Use spell:load to load the dictionary node into the database as a dictionary.

Parameters:
$words : The words from which to construct a dictionary.

Example:
  xquery version "1.0-ml";
  import module namespace spell = "http://marklogic.com/xdmp/spell" 
		  at "/MarkLogic/spell.xqy";

  let $words := ("words", "to", "go", "in", "the", "dictionary")
  return 
  spell:make-dictionary($words)

  => 
  <dictionary xmlns="http://marklogic.com/xdmp/spell">
    <word>words</word>
    <word>to</word>
    <word>go</word>
    <word>in</word>
    <word>the</word>
    <word>dictionary</word>
  </dictionary>

  
Example:
  xquery version "1.0-ml";
  import module namespace spell = "http://marklogic.com/xdmp/spell" 
		  at "/MarkLogic/spell.xqy";

  spell:make-dictionary(cts:words())

  => A spell:dictionary element containing all the words in the database.  
     Use spell:load to load this into the database as a dictionary.  
     This example requires a word lexicon on the database.  You can 
     construct the sequence of words any way you like.
  

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 "1.0-ml";
  import module namespace spell = "http://marklogic.com/xdmp/spell" 
		  at "/MarkLogic/spell.xqy";

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

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