| XQUERY/XSLT API DOCUMENTATION 4.2 |
All XQuery & XSLT Functions MarkLogic Built-In Functions Admin (xdmp:) AppServer (xdmp:) Classifier (cts:) Debug (dbg:) Document Conversion (xdmp:) Extension (xdmp:) Documents, Directories, Properties, and Locks Functions Extension Functions Function Values Functions HTTP Functions JSON Functions MarkLogic Server Functions Search Functions XML Functions XQuery Context Functions XSLT Functions map (map:) Math (math:) Profile (prof:) Search (cts:) cts:query Constructors Functions Geospatial Functions Geospatial Lexicon Functions Lexicon Functions Search Functions Search Clustering Functions Security (xdmp:) Server Monitoring (xdmp:) Spell (spell:) Update (xdmp:) XQuery Library Modules Admin Library (admin:) Actions Functions Appserver Functions Database Functions Forest Functions Group Functions Host Functions Mimetypes Functions Scheduler Functions Alerting (alert:) Elastic Compute Cloud (ec2:) Entity Enrichment (entity:) Flexible Replication (flexrep:) Geospatial Supporting Functions GEO Functions GeoRSS Functions GML Functions KML Functions MCGM Functions Information Studio (info:) Information Studio Developer (infodev:) Library Services (dls:) cts:query Constructor Functions Document Management Functions Document Update Functions Retention Policy Functions XInclude Functions Modular Documents XInclude Functions XPointer Functions PKI (pki:) Plugin (plugin:) Search (search:) Security-sec (sec:) Spelling Dictionary Management (spell:) Thesaurus (thsr:) Triggers (trgr:) Triggers Library (trgr:) WordProcessingML (ooxml:) ZIP Package (ooxml:) CPF Functions Content Processing Framework (cpf:) CSS Conversion (css:) DocBook Conversion (dbk:) Domains (dom:) Excel Conversion (excel:) Generic Conversion (cvt:) Links (lnk:) MSWord Conversion (msword:) PDF Conversion (pdf:) Pipelines (p:) Powerpoint Conversion (ppt:) XHTML Conversion (xhtml:) W3C-Standard Functions Accessor (fn:) AnyURI (fn:) Boolean (fn:) Context (fn:) DurationDateTime (fn:) Error and Trace (fn:) Node (fn:) Numeric (fn:) QName (fn:) Sequence (fn:) String (fn:) XSLT (fn:) W3C XQuery/XSLT Reference W3C XQuery Functions W3C XQuery Language W3C XSLT Language
This page was generated September 12, 2012 6:00 AM | XQuery & XSLT Built-In & Modules Function Reference
Module: Thesaurus
The thesaurus functions are designed to help you manage thesaurus documents and then use those thesaurus documents to lookup synonyms for words used in queries. The thesaurus function module is installed as the following file: `install_dir/Modules/MarkLogic/thesaurus.xqy` where `install_dir` is the directory in which MarkLogic Server is installed. To use the `thesaurus.xqy` module in your own XQuery modules, include the following line in your XQuery prolog: `import module namespace thsr="http://marklogic.com/xdmp/thesaurus" at "/MarkLogic/thesaurus.xqy";`
Function Summary
thsr:add-synonym | Adds a synonym to the specified thesaurus entry.
thsr:expand | Returns a query that searches for all the query strings specified in $query and their synonyms as found in $entries.
thsr:insert | Load the entries in $thsr into the thesaurus at $uri.
thsr:load | Load the file specified in $path to the thesaurus at $uri.
thsr:lookup | Returns all entries for term $term in the thesaurus document(s) at $uri.
thsr:query-lookup | Returns a sequence of all entries that are found by looking up terms in the query and/or subqueries of $query in the thesaurus document(s) at $uri.
thsr:remove-entry | Removes all entries that exactly match $entry from the thesaurus documents(s) at $uri.
thsr:remove-synonym | Removes synonym $synonym from thesaurus entry $entry.
thsr:remove-term | Removes all entries with term $term from the thesaurus document(s) at $uri.
thsr:set-entry | Adds the entry $entry to the thesaurus at $uri.
Function Detail
thsr:add-synonym(
| $entry as element(thsr:entry),
| $synonym as element(thsr:synonym)
) as empty-sequence()
Summary: Adds a synonym to the specified thesaurus entry.
Parameters:
$entry : A thesaurus entry.
$synonym : A synonym to add to a thesaurus entry.
Usage Notes: The synonym and the entry specified must conform to the thesaurus schema and must be namespace-qualified with the "http://marklogic.com/xdmp/thesaurus" namespace.
Example:
      xquery version "1.0-ml";
      import module namespace
    	thsr="http://marklogic.com/xdmp/thesaurus"
                                 at "/MarkLogic/thesaurus.xqy";
      thsr:add-synonym(thsr:lookup("/myThsrDocs/roget.xml",
                                   "car")[1],
                     <thsr:synonym>
                        <thsr:term>Alfa Romeo</thsr:term>
                     </thsr:synonym>)
thsr:expand(
| $query as cts:query,
| $entries as element(thsr:entry)*,
| $new-weight as xs:double?,
| $min-weight as xs:double?,
| $filter as node()*
) as cts:query
Summary: Returns a query that searches for all the query strings specified in $query and their synonyms as found in $entries.
Parameters:
$query : A cts:query item from any of the `cts:*-query` functions (`cts:word-query`, `cts:and-query`, and so on). Thesaurus expansion only occurs on an "unwildcarded" `cts:query`; it cannot expand "wildcarded" queries.
$entries : A sequence of thesaurus entries.
$new-weight : A new weight for the relevance ranking. If $new-weight is the empty sequence, then the relevance ranking is inherited from the parent query.
$min-weight : A minimum weight for the relevance ranking. If $min-weight is not the empty sequence then only queries with weight less than or equal to $min-weight will be expanded. Otherwise, all queiries are expanded.
$filter : A sequence of node restrictions. These restrictions must be nodes that can be found in a thesaurus entry (for example, `<thsr:qualifier>birds</thsr:qualifier>`).
Example:
      xquery version "1.0-ml";
      import module namespace
    	   thsr="http://marklogic.com/xdmp/thesaurus"
                               at "/MarkLogic/thesaurus.xqy";

      cts:search(
       doc("/Docs/hamlet.xml")//LINE,
       thsr:expand(
         cts:word-query("weary"),
         thsr:lookup("/myThsrDocs/thesaurus.xml",
         "weary"),
         (),
         (),
         () )
       )

       (: This query returns all of the lines in Shakespeare's
          Hamlet that have the word "weary" or any of the
          synonyms of the word "weary"  :)
thsr:insert(
| $uri as xs:string,
| $thsr as element(thsr:thesaurus)
) as empty-sequence()
Summary: Load the entries in $thsr into the thesaurus 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 a thesaurus document.
$thsr : A thesaurus document.
Usage Notes: If $uri contains XML that does not conform to the thesaurus schema (located in `install_dir/Config/thesaurus.xsd`), an error is raised. If $thsr contains XML that does not conform to the thesaurus schema, an error is raised.
Example:
      xquery version "1.0-ml";
      import module namespace
    	thsr="http://marklogic.com/xdmp/thesaurus"
                                 at "/MarkLogic/thesaurus.xqy";

      thsr:insert("/myThsrDocs/roget.xml",
                   xdmp:get("c:\thesaurus\roget.xml") )
thsr:load(
| $path as xs:string,
| $uri as xs:string
) as empty-sequence()
Summary: Load the file specified in $path to the thesaurus at $uri. Exisiting documents at $uri are overwritten.
Parameters:
$path : The path to a file containing thesaurus entries.
$uri : The URI of a thesaurus document.
Usage Notes: If $path contains XML that does not conform to the thesaurus schema, an error is raised. If $uri contains XML that does not conform to the thesaurus schema (located in `install_dir/Config/thesaurus.xsd`), an error is raised.
Example:
      xquery version "1.0-ml";
      import module namespace
    	thsr="http://marklogic.com/xdmp/thesaurus"
                                 at "/MarkLogic/thesaurus.xqy";

      thsr:load("c:\thesaurus\roget.xml", "/myThsrDocs/roget.xml")
thsr:lookup(
| $uri as xs:string*,
| $term as xs:string
) as element(thsr:entry)*
Summary: Returns all entries for term $term in the thesaurus document(s) at $uri.
Parameters:
$uri : The URI of the thesaurus document(s).
$term : A term to lookup in the thesaurus.
Example:
       thsr:lookup("/myThsrDocs/thesaurus.xml", "weary")
       => returns the thesaurus entry for the term "weary"
thsr:query-lookup(
| $uri as xs:string*,
| $query as cts:query
) as element(thsr:entry)*
Summary: Returns a sequence of all entries that are found by looking up terms in the query and/or subqueries of $query in the thesaurus document(s) at $uri.
Parameters:
$uri : The URI of the thesaurus document(s).
$query : A cts:query item from any of the `cts:*-query` functions (`cts:word-query`, `cts:and-query`, etc.).
Example:
      xquery version "1.0-ml";
      import module namespace
    	   thsr="http://marklogic.com/xdmp/thesaurus"
                               at "/MarkLogic/thesaurus.xqy";

      let $query := cts:word-query("weary")
      return
          thsr:query-lookup("/myThsrDocs/thesaurus.xml",
                            $query)

       => All entries for the term "weary" in the specified
          thsesaurus document
thsr:remove-entry(
| $uri as xs:string*,
| $entry as element(thsr:entry)
) as empty-sequence()
Summary: Removes all entries that exactly match $entry from the thesaurus documents(s) at $uri.
Parameters:
$uri : The URI of the thesaurus document(s).
$entry : A thesaurus entry.
Example:
      xquery version "1.0-ml";
      import module namespace
    	thsr="http://marklogic.com/xdmp/thesaurus"
                                 at "/MarkLogic/thesaurus.xqy";

       (: removes the second "Car" entry from the
          thesaurus document :)
      thsr:remove-entry("/myThsrDocs/roget.xml",
                thsr:lookup("/myThsrDocs/roget.xml","Car")[2])
thsr:remove-synonym(
| $entry as element(thsr:entry),
| $synonym as element(thsr:synonym)
) as empty-sequence()
Summary: Removes synonym $synonym from thesaurus entry $entry.
Parameters:
$entry : A thesaurus entry.
$synonym : A synonym to add to a thesaurus entry.
Example:
      xquery version "1.0-ml";
      import module namespace
    	   thsr="http://marklogic.com/xdmp/thesaurus"
                                 at "/MarkLogic/thesaurus.xqy";

      thsr:remove-synonym(thsr:lookup("/myThsrDocs/roget.xml",
                                       "car")[1],
                               <thsr:synonym>
                                    <thsr:term>Fiat</thsr:term>
                               </thsr:synonym>)
thsr:remove-term(
| $uri as xs:string*,
| $term as xs:string
) as empty-sequence()
Summary: Removes all entries with term $term from the thesaurus document(s) at $uri.
Parameters:
$uri : The URI of the thesaurus document(s).
$term : A term to remove from the thesaurus.
Example:
      xquery version "1.0-ml";
      import module namespace
    	thsr="http://marklogic.com/xdmp/thesaurus"
                                 at "/MarkLogic/thesaurus.xqy";

      thsr:remove-term("/myThsrDocs/roget.xml", "Car")

       => removes all entries for "Car" from the thesaurus with the
          specified URI
thsr:set-entry(
| $uri as xs:string,
| $entry as element(thsr:entry)
) as empty-sequence()
Summary: Adds the entry $entry to the thesaurus at $uri.
Parameters:
$uri : The URI of a thesaurus document.
$entry : An entry to add to the thesaurus.
Usage Notes: set the entry $entry in the thesaurus at $uri. If $entry does not contain a valid entry node, an error will be raised. If an entry matching $entry does not exist in the thesaurus, $entry is added to the thesaurus. If $entry contains XML that does not conform to the thesaurus schema (located in `install_dir/Config/thesaurus.xsd`), an error is raised.
Example:
      xquery version "1.0-ml";
      import module namespace
    	thsr="http://marklogic.com/xdmp/thesaurus"
                                 at "/MarkLogic/thesaurus.xqy";

      thsr:set-entry("/myThsrDocs/roget.xml",
       <entry xmlns="http://marklogic.com/xdmp/thesaurus">
          <term>Car</term>
          <synonym>
            <term>Ford</term>
            <part-of-speech>noun</part-of-speech>
          </synonym>
          <synonym>
            <term>automobile</term>
            <part-of-speech>noun</part-of-speech>
          </synonym>
          <synonym>
            <term>Fiat</term>
            <part-of-speech>noun</part-of-speech>
          </synonym>
       </entry>)

© Copyright 2002-2012 MarkLogic Corporation. All rights reserved.