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.
install_dir
To use the spell.xqy module in your own XQuery modules, include the following line in your XQuery prolog:
spell.xqy
import module namespace spell = "http://marklogic.com/xdmp/spell" at "/MarkLogic/spell.xqy";
The library uses the spell: namespace, predefined in the server.
spell:
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.
spell:is-correct
spell:suggest
import module
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.
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
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:suggest-detailed
spell:load
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")
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>
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.
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