in reply to Reading IPA characters in Perl (Unicode?)

Which is all well and good. For the most part, it works beautifully. The problem is that some phonemes in IPA are represented with two symbols (for example, ʣ), and perl is treating these as separate characters when calculating the edit distance.

I've just tested Text::Levenshtein::Damerau with the ʣ digraph, and it treats it as a single character:

use lib 'lib'; use strict; use warnings; use 5.010; use Text::Levenshtein::Damerau qw/edistance/; use charnames ":full"; use utf8; say edistance("e\N{LATIN SMALL LETTER DZ DIGRAPH}gar", 'edgar'); # output: 1

So the problem seems to be that you don't pass properly decoded strings to edistance

Is unicode the best way to do this? Are there any easier ideas that I am simply missing? Do I have to "use Encode"? I have seen some sample scripts that use it, and others that don't.

Unicode is the best way to do this, yes.

If your data comes in as a byte string, yes, you'll need use Encode and decode the data before passing it to edistance. And yes, some scripts use it, and others not, because not all example scripts do the same thing in the same way.

I hope this article answers some of your questions. In the end you'll just have to learn about character encodings and how perl handles them, and then fix your problem with that knowledge.

Replies are listed 'Best First'.
Re^2: Reading IPA characters in Perl (Unicode?)
by Anonymous Monk on Feb 01, 2012 at 16:45 UTC

    When you use:

    say edistance("e\N{LATIN SMALL LETTER DZ DIGRAPH}gar", 'edgar');

    What is the difference between writing out {LATIN SMALL LETTER DZ DIGRAPH} and using the actual Unicode number, in this case {0x02A3}? Are they functionally equivalent?

        Okay. Thanks a lot for that website, that is more helpful than the other guides I'd found online.