Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Sorting Vietnamese text

by Anonymous Monk
on Dec 23, 2013 at 07:31 UTC ( #1068152=note: print w/replies, xml ) Need Help??

in reply to Re: Sorting Vietnamese text
in thread Sorting Vietnamese text

And here's what I came up
sub make_sort_order {
	my $str = shift;
	$str =~

	return $str;

my @words = ('ầm', 'm', 'ấm ch', 'm số');

print $_->[1], "[n" for
	sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] }
	map  { [ make_sort_order($_), $_ ] } @words;

It's still missing a correct 'secondary sort' (for the edge case when the diacritic-stripped words are identical); it should not be difficult to add once someone figures out a suitable transliteration that sorts asciibetically.

Replies are listed 'Best First'.
Re^3: Sorting Vietnamese text
by pdenisowski (Acolyte) on Dec 23, 2013 at 15:10 UTC

    It's still missing a correct 'secondary sort' (for the edge case when the diacritic-stripped words are identical);

    (laughs) That's hardly an "edge case" in Vietnamese - there are thousands of minimal pairs where the only difference between the words is the diacritical marks. While it's possible to read and understand Vietnamese typed in (7-bit) ASCII without too much ambiguity (i.e. you can figure out what word is meant from the context), this obviously wouldn't work for a dictionary.

    The other issue is that the words in the dictionary need to be sorted in the "correct" order for me to detect duplicates, etc.

    I'll try out your suggestion later today - thanks again!

      I'm probably completely off base here -- why does m số come before m when sorts at the same point as ? And the same question with ỳ ạch and ỷ and the other lines...

      I think there's something wrong with my alphabet -- some characters being eaten perhaps -- since the tr/// has duplicates? If they're wrong, please re-input the correct alphabetical order into the tr/// lines yourself.

      I'm still not sure how spaces play part in all this; I'd sort all the single-character y variants together, and before the two-syllable ones, but the order you've given does not match that and somehow my code handles it handled it even though it shouldn't have.

      You should split the string into two before sorting, though. One part for the actual word, the other for the translation.

      Anyway, here's a try for a correct secondary sort -- of course, I do not have any words to test it on. It sorts how I expect it to do based on what I said in 1068139, but it does not sort how you expect it to.

      Also, why the hell is my tr///d not deleting characters?

      Okay -- the alphabet is only 93 characters per the link in 1068127; you had seven characters extra.

      You should clarify what the relation between monosyllables and polysyllables is, and what is the desired collation behaviour between them.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1068152]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2017-10-22 10:32 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (273 votes). Check out past polls.