[xquery-talk] contains(), matches(), highlight-matches()

Christian Grün christian.gruen at gmail.com
Sat Jul 6 04:04:39 PDT 2013

Hi Joe,

this is a nice idea for using higher-order functions! A minor remark:
In the last example in the blog article, it may be advantageous to
remove the predicate (otherwise, the highlighted texts will be lost as
soon as the predicate has been processed).

A little excursion: It may come to no surprise that one of the most
requested features for XQuery Full Text 3.0 is the possibility to
highlight matches [1], and I believe it would be a good idea to
introduce higher-order functions to make highlighting more flexible.
Qizx also provides such a highlighting function with an optional
function argument (look for "word-function" [2]). The syntax differ a
little it was developed before HOF were finalized. BaseX also has a
function for highlighting results, but it allows uses no function as
argument [3]. Obviously, both extensions are based on XQuery Full
Text, and are implementation-defined (and I guess there are various
others). One advantage it provides is the support for linguistic
features, such as tokenization, the normalization of diacritics, etc.

> I'm curious: Was a function like this impossible to write in pure
> XQuery before 3.0's support for fn:analyze-string() and higher order
> functions?

I can’t think of any straightforward solution without analyze-string()
(we could write custom string match functions in XQuery, using
recursive functions and all kinds of XQuery string functions, but the
resulting solution may get too slow for large text corpora).
Higher-order functions are probably not mandatory, but they clearly
help to make the solution more elegant.


[1] http://www.w3.org/TR/xpath-full-text-30-requirements-use-cases/#d3e329
[2] http://www.axyana.com/qizxopen/_distrib/docs/manual/fulltext_extensions.html#d0e2303
[3] http://docs.basex.org/wiki/Full-Text_Module#ft:mark

> Today I posted some code [1] with a function for highlighting regex
> matches in an XML node.  I'd appreciate any comments or improvements
> to the code (via response here, pull requests, or whatever method is
> best for you).
> I also wrote an accompanying post [2] for relative beginners to
> XQuery.  While seasoned programmers probably come up this function on
> the first day they learn XQuery, I think it's beyond most
> XQuery-first-programmers like I was when I began.  Yet I think the
> function is so basic that in my post I ventured to call it XQuery's
> "missing third function" - the first two being contains() and
> matches().
> I'm curious: Was a function like this impossible to write in pure
> XQuery before 3.0's support for fn:analyze-string() and higher order
> functions?  Surely, if it had been possible, it would've been in the
> functx library.
> Thanks in advance for your insights,
> Joe (@joewiz on twitter)
> [1] https://gist.github.com/joewiz/5937897
> [2] http://joewiz.tumblr.com/post/54729725793/xquerys-missing-third-function
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk

More information about the talk mailing list