[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Grouping and sorting using custom collation class

Subject: RE: Grouping and sorting using custom collation class with Saxon
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 23 Mar 2010 21:47:43 -0000
RE:  Grouping and sorting using custom collation class
Interesting one. So you essentially want to extract the first collation unit
in the string and use that as the grouping key. As far as I can see, there's
no direct way of doing that without an extension function.

The extension function isn'f difficult to write: given $collator as an
instance of your RuleBasedCollator, it's essentially

public List<Integer> collationUnits(String in) {
    List<Integer> units = new ArrayList<Integer>();
    CollationElementIterator iter =
collation.getCollationElementIterator(in);
    for (int c = iter.next(); c != CollationElementIterator.NULLORDER;) {
        units.add(c);
    }
}

and then in the XSLT you can do

<for-each-group select="..." group-by="ext:collationUnits(.)[1]">

Producing your heading which lists the character sequences corresponding to
the collation unit is the next challenge. You could change the extension
function so that instead of returning the integer values of the collation
units, it returns a sequence of substrings corresponding to the collation
units. You can still use the first of these as the grouping key provided you
compare under the collation, and you could then use the set containing the
first substring of each string in the current-group as the heading - which of
course would only include those actually present in the group, not those that
would be potentially present.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



> -----Original Message-----
> From: Larry Hayashi [mailto:lhtrees@xxxxxxxxx]
> Sent: 23 March 2010 21:10
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Grouping and sorting using custom collation
> class with Saxon
>
> I have a built a custom collation and there are a number of
> multigraphs in the language I am working in. Here is a
> sampling of the sort sequence (minus non-ASCII characters)
> from the java collation class.
>
> 	("='-';'=';'*' " + /** -,=,* are used to indicate
> various types of affixes and clitics. These should be ignored.*/
> 	"< a,A " +
>    	"< '''a,'''A " + /** 'a,'A*/
> 	"< aa,Aa " +
> 	"< b,B " +
> 	"< c,C " +
> 	"< d,D " +
> 	"< dz,Dz " +
> 	"< e,E " +
> 	"< '''e,'''E " + /** 'e,'E*/
> 	"< ee,Ee " +
> 	"< f,F " +
> 	"< g,G " +
> 	"< gw,Gw " +
> 	"< gy,Gy " +
> 	"< h,H " +
> 	"< i,I " +
> 	"< '''i,'''I " + /** 'i,'I*/
> 	"< ii,Ii " +
> 	"< k,K " +
> 	"< k'''K''' " + /** k',K'*/
> 	"< kw,Kw " +
> 	"< ky,Ky " +
> 	"< k'''w,K'''w " +  /** k'w,K'w */
> 	"< k'''y,K'''y " +  /** k'y,K'y */
> 	"< l,L " +
> 	etc.
> 	"< '''y,'''Y ")
>
> Desired output is something like this:
>
> a,A
> **********
> -ana
> atata
>
> 'a,'A
> **********
> 'ap
> 'atata
>
> etc.
>
> k,K
> **********
> kaba
> kopii
> ks=
> -ks
> ksa
>
> k',K'
> *********
> k'aba
> k'ol
>
> kw,kW
> *********
> kwduun
> kwtaxs
>
> k'w,K'w
> *********
> k'was
> k'wiss
> kwiloolag
>
>
> The source XML structure for each entry looks like this:
>
> <dictionary>
> <entry>
>     <lexical-unit>
>         <form lang="tsi"><text>kaba=</text></form>
>     </lexical-unit>
>     <trait name="morph-type" value="proclitic"/>
>     <sense>
>         <grammatical-info value="prenominal"/>
>         <gloss lang="en"><text>small</text></gloss>
>     </sense>
> </entry>
> <!--more entries ....->
> </dictionary>
>
> Any suggestions as to how to most efficiently group the data
> according to the parameters of the custom collation?
>
> Currently, I manually build a regular expression, putting the
> largest multigraphs first so that the greedy regex parser
> chooses the longest matching string. I use this with
> xsl:analyze-string to add @alphaGroupKey to each entry as shown below.
>
>  <xsl:attribute name="alphaGroupKey">
>    <xsl:analyze-string select="lexical-unit/form[@lang='tsi']/text"
>      regex="^[-=]*((aa|Aa)|(a|A)|(kw|Kw)|(ky|Ky)|(k|K)|(a85|a84))"
>
> default-collation="http://saxon.sf.net/collation?class=com.lht
> rees.xslt.LangXCollation;">
>       <xsl:matching-substring>
>         <xsl:analyze-string select="." regex="[^-=\*]+$">
>           <xsl:matching-substring>
>             <xsl:value-of select="."/>
>           </xsl:matching-substring>
>         </xsl:analyze-string>
>       </xsl:matching-substring>
>    </xsl:analyze-string>
>  </xsl:attribute>
>
> I can then do the grouping of entries using for-each-group
> with the attribute alphaGroupKey.
>
> But I am wondering if there is a pre-existing way to use the
> custom collation class to do the grouping so I don't need to
> build the regex string. It seems like all of the information
> that is needed is already in that class.
>
> Larry

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.