Croatica et Tyrolensia: XQuery scripts

Adding a function to parse wordforms externally

What we need:

  1. a working BaseX installation; see The easiest way to deploy BaseX
  2. permissions and ways to edit a .xqm XQuery module file (such as the restxq.xqm supplied with BaseX)
  3. address of a parsing service (e. g. – check this out to see the kinds of results that will be provided)

First we edit the form part, where users submit sentences (or words) to be parsed:

<h3>Parse words from Latin sentence</h3>
 <p>Enter a Latin sentence which you want to parse. 
    The result will be an XML file with lots of grammatical
    information for each word.</p>
      <form method="post" action="homon">
        <p>Sententia:<br />
        <input name="message" size="50"></input>
        <input type="submit" /></p>

Then we prepare the function (e. g. by adding this to the end of the restxq.xqm module file). Caveat: the service address here is not real, it is a placeholder!

 : A comment, to help us know what we're doing:
 : this function retrieves lexical information 
 : from an external service 
 : for words in a form request.
 : @param  $message  message to be included in the response
 : @return response element 
  %rest:form-param("query","{$query}", "(no query)")
  function page:homon-postman(
    $message as xs:string)
let $url := (";lang=latamp;engine=morpheuslat")
(: convert string into sequence :)
let $rijeci := tokenize($query, "\W+")
(: for each item in sequence :)
return element w { 
for $r in $rijeci
let $parsed := (doc(replace($url,'SOMEWORD',$r)))
return element ana { $parsed } 
z/croat-tyrol-xquery.txt · Last modified: 11. 01. 2014. 16:33 by njovanov
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki