Collating sequence

From Wikipedia, the free encyclopedia

The term collating sequence refers to the order in which character strings should be placed when sorting them.

A common example is the familiar "alphabetic order", in which "Alfred" occurs before "Zeus" because "A" occurs before "Z" in the English alphabet. But there are other issues that a collating sequence must consider, say in a computer system.

  • Uppercase and lowercase: an upper-case "A" and a lower-case "a" are usually considered to be the same letter, so Ab comes between aa and ac. But it may be that you want to sort the records otherwise.
  • National characters, accents, tildes: Various languages use these marks over and around letters, but once again the speakers of the language might consider the characters to be "the same."

In a computer system, each letter is necessarily assigned a unique numeric code (as in the ASCII or Unicode character set), but the proper and customary ordering of strings is not performed by a simple numeric comparison of those codes. Rather, the ordering is determined by reference to the collating sequence.

[edit] Collating sequences in various languages

Some languages include modified letters, ligatures, or digraphs in the alphabet, for orthographic and collation purposes. This varies from language to language, and sometimes from symbol to symbol, within the same language. Listed below are the collation orders in various languages.

  • In Azerbaijani, there are 7 additional letters. 4 of them are vowels: ı, ö, ü, ə and 3 are consonants: ç, ş, ğ. The alphabet is the same as the Turkish alphabet, with the same sounds written with the same letters, except for three additional letters: q, x and ə for sounds that do not exist in Turkish. Although all the "Turkish letters" are collated in their "normal" alphabetical order like in Turkish, the three extra letters are collated arbitrarily after letters whose sounds approach theirs. So, q is collated just after k, x (pronounced like a German ch) is collated just after h and ə (pronounced roughly like an English short a) is collated just after e.
  • In Breton, there is no "c" but there are the ligatures "ch" and "c'h", which are collated between "b" and "d". For example: « buzhugenn, chug, c'hoar, daeraouenn » (earthworm, juice, sister, teardrop).
  • In Bosnian, Croatian and Serbian and other related South Slavic languages, the five accented characters and three conjoined characters are sorted after the originals: ..., C, Č, Ć, D, DŽ, Đ, E, ..., L, LJ, M, N, NJ, O, ..., S, Š, T, ..., Z, Ž.
  • In Czech and Slovak, accented vowels have secondary collating weight - compared to other letters, they are treated as their unaccented forms (A-Á, E-É-Ě, I-Í, O-Ó-Ô, U-Ú-Ů, Y-Ý), but then they are sorted after the unaccented letters (for example, the correct lexicographic order is baa, baá, báa, bab, báb, bac, bác, bač, báč). Accented consonants (the ones with caron) have primary collating weight and are collocated immediately after their unaccented counterparts, with exception of Ď, Ň and Ť, which have again secondary weight. CH is considered to be a separate letter and goes between H and I. In Slovak, DZ and are also considered separate letters and are positioned between Ď and E (A-Á-Ä-B-C-Č-D-Ď-DZ-DŽ-E-É…).
  • In the Danish and Norwegian alphabets, the same extra vowels as in Swedish (see below) are also present but in a different order and with different glyphs (..., X, Y, Z, Æ, Ø, Å). Also, "Aa" collates as an equivalent to "Å". The Danish alphabet has traditionally seen "W" as a variant of "V", but nowadays "W" is considered a separate letter.
  • In Dutch the combination IJ (representing IJ) was formerly to be collated as Y (or sometimes, as a separate letter Y < IJ < Z), but is currently mostly collated as 2 letters (II < IJ < IK). Exceptions are phone directories; IJ is always collated as Y here because in many Dutch family names Y is used where modern spelling would require IJ. Note that a word starting with ij that is written with a capital I is also written with a capital J, for example, the town IJmuiden and the river IJssel.
  • In Esperanto, consonants with circumflex accents (ĉ, ĝ, ĥ, ĵ, ŝ), as well as ŭ (u with breve), are counted as separate letters and collated separately (c, ĉ, d, e, f, g, ĝ, h, ĥ, i, j, ĵ ... s, ŝ, t, u, ŭ, v, z).
  • In Estonian õ, ä, ö and ü are considered separate letters and collate after w. Letters š, z and ž appear in loanwords and foreign proper names only and follow the letter s in the Estonian alphabet, which otherwise does not differ from the basic Latin alphabet.
  • The Faroese alphabet also has some of the Danish, Norwegian, and Swedish extra letters, namely Æ and Ø. Furthermore, the Faroese alphabet uses the Icelandic eth, which follows the D. Five of the six vowels A, I, O, U and Y can get accents and are after that considered separate letters. The consonants C, Q, X, W and Z are not found. Therefore the first five letters are A, Á, B, D and Ð, and the last five are V, Y, Ý, Æ, Ø
  • In Filipino and other Philippine languages, the letter Ng is treated as a separate letter. It is pronounced as in sing, ping-pong, etc. By itself, it is pronounced nang, but in general Filipino orthography, it is spelled as if it were two separate letters (n and g). Also, letter derivatives (such as Ñ) immediately follow the base letter. Filipino also is written with accents and other marks, but the marks are not in very wide use (except the tilde). (Philippine orthography also includes spelling.)
  • The Finnish alphabet and collating rules are the same as in Swedish, except for the addition of the letters Š and Ž, which are considered variants of S and Z.
  • In German letters with umlaut (Ä, Ö, Ü) are treated generally just like their non-umlauted versions; ß is always sorted as ss. This makes the alphabetic order Arg, Ärgerlich, Arm, Assistant, Aßlar, Assoziation. For phone directories and similar lists of names, the umlauts are to be collated like the letter combinations "ae", "oe", "ue". This makes the alphabetic order Udet, Übelacker, Uell, Ülle, Ueve, Üxküll, Uffenbach.
  • The Hungarian vowels have accents, umlauts, and double accents, while consonants are written with single, double (digraphs) or triple (trigraph) characters. In collating, accented vowels are equivalent with their non-accented counterparts and double and triple characters follow their single originals. Hungarian alphabetic order is: A, Á, B, C, CS, D, DZ, DZS, E, É, F, G, GY, H, I, Í, J, K, L, LY, M, N, NY, O, Ó, Ö, Ő, P, Q, R, S, SZ, T, TY, U, Ú, Ü, Ű, V, W, X, Y, Z, ZS. (For example, the correct lexicographic order is baa, baá, bab, báb, bac, bác, bacs, bács, bad, bád, ...).
  • In Icelandic, Þ is added, and D is followed by Ð. Each vowel (A, E, I, O, U, Y) is followed by its correspondent with acute: Á, É, Í, Ó, Ú, Ý. There is no Z, and after Ý, it goes like this: ... Þ, Æ, Ö.
    • Both letters were also used by Anglo-Saxon scribes who also used the Runic letter Wynn to represent /w/.
    • Þ (called thorn; lowercase þ) is also a Runic letter.
    • Ð (called eth; lowercase ð) is the letter D with an added stroke.
  • In Lithuanian, specifically Lithuanian letters go after their Latin originals. Another change is that Y comes just before J: ... G, H, I, Į, Y, J, K...
  • In Polish, specifically Polish letters derived from the Latin alphabet are collated after their originals: A, Ą, B, C, Ć, D, E, Ę, ..., L, Ł, M, N, Ń, O, Ó, P, ..., S, Ś, T, ..., Z, Ź, Ż. The digraphs for collation purposes are treated as if they were two separate letters.
  • In Portuguese, the collating order is just like in English, including the three letters not native to Portuguese: A, B, C, D, E, F, G, H, I, J, (K), L, M, N, O, P, Q, R, S, T, U, V, (W), X, (Y), Z. Digraphs and letters with diacritics are not included in the alphabet.
  • In Romanian, special characters derived from the Latin alphabet are collated after their originals: A, Ă, Â, ..., I, Î, ..., S, Ş, T, Ţ, ..., Z.
  • In the Swedish alphabet, there are three extra vowels placed at its end (..., X, Y, Z, Å, Ä, Ö), similar to the Danish and Norwegian alphabet, but with different glyphs and a different collating order. The letter "W" has been treated as a variant of "V", but in the 13th edition of Svenska Akademiens ordlista (2006) "W" was considered a separate letter.
  • Spanish treated (until 1997) "CH" and "LL" as single letters, giving an ordering of cinco, credo, chispa and lomo, luz, llama. This is not true anymore since in 1997 RAE adopted the more conventional usage, and now LL is collated between LK and LM, and CH between CG and CI. The six accented or umlauted characters Á, É, Í, Ó, Ú, Ü are treated as the original letters A, E, I, O, U, for example: radio, ráfaga, rana, rápido, rastrillo. The only Spanish specific collating question is Ñ (eñe) as a different letter collated after N.
  • In Tatar and Turkish, there are 9 additional letters. 5 of them are vowels, paired with main alphabet vowels as hard-smooth: a-ä, o-ö, u-ü, í-i, ı-e. The four remaining are consonants: ş is sh, ç is ch, ñ is ng and ğ is gh.
  • In many Turkic languages (such as Azeri or the Jaŋalif orthography for Tatar), there used to be the letter Gha (Ƣƣ), which came between G and H. It is now come in disuse.
  • Welsh also has complex rules: the combinations CH, DD, FF, NG, LL, PH, RH and TH are all considered single letters, and each is listed after the letter which is the first character in the combination, with the exception of NG which is listed after G. However, the situation is further complicated by these combinations not always being single letters. An example ordering is LAWR, LWCUS, LLONG, LLOM, LLONGYFARCH: the last of these words is a juxtaposition of LLON and GYFARCH, and, unlike LLONG, does not contain the letter NG.

The Unicode Collation Algorithm can be used to get any of the collation sequences described above, by tailoring its default collation table. Several such tailorings are collected in Common Locale Data Repository.

[edit] See also