Croatica et Tyrolensia: XQuery scripts

upload.wikimedia.org-wikipedia-commons-thumb-b-b3-costumes_de_differents_pays-2c_-27femme_morlaque_du_canton_de_segna-27_lacma_m.83.190.48.jpg-256px-costumes_de_differents_pays-2c_-27femme_morlaque_du_canton_de_segna-27_lacma_m.83.190.48.jpg

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. http://services.perseids.org/bsp/morphologyservice/analysis/word?word=homines&lang=lat&engine=morpheuslat – 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>
      </form>

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 
 :)
declare
  %rest:path("/homon")
  %rest:POST
  %rest:form-param("query","{$query}", "(no query)")
  function page:homon-postman(
    $message as xs:string)
    { 
let $url := ("http://some.parsing.service.org/somemorphologyservice/someword?word=SOMEWORD&amp;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