Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

unicode translation

by ed111 (Initiate)
on May 28, 2009 at 05:05 UTC ( #766584=perlquestion: print w/ replies, xml ) Need Help??
ed111 has asked for the wisdom of the Perl Monks concerning the following question:

Hi-I have a list of "words"-actually a list of unicode numbers that represent Arabic words. I would like to translate these "words" into English if possible but I don't know how to do this given that the unicode represents Arabic words. Nor do I know how to translate unicode that represents English words for that matter. In any case, there are over 1,000 words on the list so I need to do this via a Perl script if this is possible. Any ideas?

Replies are listed 'Best First'.
Re: unicode translation
by graff (Chancellor) on May 28, 2009 at 06:05 UTC
    There is a tool written in perl (with associated dictionary tables) available for free on request (you have to ask for it -- you can't just download it). Send email to ldc (at) saying that you want the Buckwalter Arabic Morphological Analyzer (BAMA) Version 1 (LDC catalog-ID "LDC2002L49"). The name comes from the person who invented the tool and maintained it for many years, Tim Buckwalter.

    Once you have that tool in place on your machine, you need to convert your Arabic text from unicode to cp1256 (that version of the tool only accepts that encoding) and pipe the text as input to the "" script. The output will be a list of possible "interpretations" for each word, including part-of-speech tags, segmentation into stems and affixes, and English glosses.

    Bear in mind that most Arabic words (as written in Arabic characters) are incredibly ambiguous, due in part to the fact that the words are normally written without the marks that indicate vowels and lengthened consonants, so getting an English translation for a given word is fairly speculative for those who don't know both Arabic and English.

    If the "unicode" you are talking about is utf8, then "unicode English" is no different from "ascii English", because the ascii character set is a subset of utf8-encoded unicode. If you have utf-16, that's very different, because each ascii byte needs to have a null "high byte" to pad it out to 16 bits.

    As for doing encoding conversions, perl makes that pretty easy. If you are starting with utf8 Arabic, and want to feed the "" tool described above, this would suffice:

    perl -e 'binmode STDIN,":utf8";binmode STDOUT,":encoding(cp1256)";prin +t while(<>)' < arabic.utf8 | > output
    If you're data is in some other form of unicode (not utf8), just change the 'binmode STDIN' part as needed.

    You'll want to consult the BAMA docs for more information about the tool and its output. (Update: since the previous reply mentioned dialects, I should point out that BAMA works only on Modern Standard Arabic, not any colloquial dialect, but that's generally not a problem, since the vast majority of writing in Arabic involves MSA.)

      Fantastic Post!

      I think the poster will definitely need a helper (doesn't have to a programmer), just somebody who speaks both languages or this could be a real problem. I don't know much at all about Arabic but I do hear this this "missing vowel sort of stuff" can be very difficult.

      I used to help a friend go from German to English. She was certified in the German courts to go from English to German, but the other direction was more problematic! What she came up with was understandable to be sure! But not the way a native English language speaker would formulate or say it. This translation stuff has many pitfalls.

      At little at the edges of the topic, but once I was trying to read an instruction manual. This was a German product that got licensed to a Japanese company who evidently translated the manual into Japanese, and then into English. I could easily understand the German, but the English was just gibberish to me! I'm just saying that translation is a tricky business.

      I have been on a trip and just got back. Thanks for the reponses-good stuff.
        Two further questions: I sent e-mail to the e-mail address you listed and requested BAMA but never heard back. Any other ideas on how I could get a copy of BAMA? Second question: I have a new task and that is to translate URL endoed strings to Arabic and then to English? Any suggestions?
Re: unicode translation
by Marshall (Monsignor) on May 28, 2009 at 05:30 UTC
    As a starter, try this unicode page:

    Also of interest could be, which shows Arabic encodings: Anyway you are going to maybe need to know what kind of dialect of Arabic you are using.

    If you want a decent translation, you are going to need to display this Arabic stuff and have somebody who speaks arabic translate it for you. This is very difficult as usually there are multiple meanings per word. So you have a huge problem to solve there! I don't know of any Perl module that can do this. Although there may be some kind of say Google web gizmo that does translations and then we are into a a CGI type of application which can be done in Perl.

    If you can get the problem down to "hey, this set of bits that mean a word in Arabic, need to get transformed into this set of bits that are english characters", then that job can be done.

    Read above link about unicode . I don't how to be of more help right now.

      As a starter, try this unicode page:

      That's not a good place to start. As the document itself now indicates, if you just want to use Unicode in Perl you shouldn't have to read a reference document, and can instead start at the Unicode tutorial.

Re: unicode translation
by Anonymous Monk on Dec 18, 2009 at 14:43 UTC
    you can find it here

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://766584]
Approved by graff
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2016-06-25 18:21 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (326 votes). Check out past polls.