|
Subject: Re: [xsl] comparing sequences that contain more than one of the same item From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx> Date: Fri, 22 Feb 2008 14:08:55 +0000 |
The goal is to give you all possible words that can be made out of a given word.
So for "farmer" you get:
framer
armer
farer
frame
rearm
fame
fare
...
So I'm looking for a comparison that checks if a word can be made out
of the letters of another word.
The recursive function that I wrote 10 mins ago looks like this, where
$searchWord would be the codepoints for "farmer", and $wordListWord
would be any word from my list of words:
<xsl:function name="f:checkWord" as="xs:boolean">
<xsl:param name="searchWord" as="xs:integer*"/>
<xsl:param name="wordListWord" as="xs:integer*"/>
<xsl:variable name="firstChar" select="$wordListWord[1]" as="xs:integer?"/>
<xsl:choose>
<xsl:when test="empty($wordListWord)">
<xsl:sequence select="true()"/>
</xsl:when>
<xsl:when test="empty($searchWord)">
<xsl:sequence select="false()"/>
</xsl:when>
<xsl:when test="$firstChar = $searchWord">
<xsl:sequence select="f:checkWord(remove($searchWord,
index-of($searchWord, $firstChar)[1]), remove($wordListWord, 1))"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="false()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
On 22/02/2008, Robert Koberg <rob@xxxxxxxxxx> wrote:
>
> contains(str1, str2)
>
> ?
>
>
> On Fri, 2008-02-22 at 13:57 +0000, Andrew Welch wrote:
> > A bit of a Friday challenge...
> >
> > Is it possible to compare to sequences such that items in the sequence
> > are consumed after the comparison?
> >
> > For example, I want to compare two words to see if one is a subset of the other.
> >
> > "farmer" and "frame"
> >
> > If you do:
> >
> > string-to-codepoints('farmer')[not(. = string-to-codepoints('frame'))]
> >
> > the result is empty because the two r's in farmer are both being
> > compared to the single r in frame.
> >
> > Currently I've a got a recursive function that removes each letter
> > after a match, but I'm wondering if there's a one-liner or some other
> > set based approach?
> >
> >
> > thanks
>
>
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] comparing sequences that , Robert Koberg | Thread | Re: [xsl] comparing sequences that , Robert Koberg |
| Re: [xsl] comparing sequences that , Robert Koberg | Date | Re: [xsl] XPath Best Practice: Gett, Florent Georges |
| Month |