xsl-list
[Top] [All Lists]

[xsl] Re: Efficient dictionary lookup

2012-03-22 19:49:59
On 12-03-22 02:44 PM, David Carlisle wrote:
On 22/03/2012 21:39, Martin Holmes wrote:
 > HI all,
 >
 > As part of a small pilot project, I'm implementing a set of spelling
 > normalization rules applied through XSLT 2.0 using Saxon 9. One
 > operation that happens extremely frequently is a dictionary lookup;
[SNIP]


sounds like you want to use a key then the processor will almost
certainly create an efficient lookup index.

If your dictionary is in a file say dict.xml
<words>
<word>one</word>
<word>hello</word>
</words>

then

<xsl:key name="w" match="word" use="."/>

declares the index and

key('w',$word,doc('dict.xml'))

will return the word if it is in the dictionary.

That is much faster, indeed. It's still not fast -- the spellcheck dictionary is big -- but it's interesting to see that processing it as an XML structure with <xsl:key> is so much faster than processing it as a string.

Cheers,
Martin


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>