What we need:
.xqm
XQuery module file (such as the restxq.xqm
supplied with BaseX)
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&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 } } };