Showing posts with label Text Processing. Show all posts
Showing posts with label Text Processing. Show all posts

Monday, January 30, 2012

Urdu to English Dictionary

Translators are not super humans or machines which take input in one language and provide output in another. They are like ordinary people, but a bit clever in using a dictionary. So it is the dictionary which makes a translator 'actual' translator. As there is always a women behind a successful man, there is a good dictionary behind a successful translator, in this case I must say a bunch of dictionaries. :-) As I work as a translator English <-> Urdu and Punjabi. En <> Ur combination is mostly demanded and for this purpose I am in a continuous need of dictionary. I had a dictionary for English to Urdu, as I mentioned here my adventure to integrate dictionary word list to OmegaT. 

This dictionary solved half of my problem i.e. En > Ur. But the revrse was still a headache. I always had to refer to UrduEnglishDictionary.org for searching English equivalents of Urdu words. But then, as I always sometimes do, I woke up and decided to do something on my own. So what I've done is changed the English > Urdu wordlist to work for Urdu > English purposes. It is a dirty solution, there are still lots of problem in the word list, and ideally there should have been a word list typed specifically for Urdu > English purposes. But this quick dirty solution works in most cases for me. And I am sharing it here online, so people struggling for Urdu > English equivalents may get some relief. There are lots of good dictionaries out there, but this is yet another dictionary in already available variety. And hopefully it will benefit other translators and users.
Urdu to English Dictionary in C#
There is nothing fancy, no help, no license and no xml type system to store word list. The word list is simply a text file with entries on new line and Urdu words are separated from English counterparts using a tab. The dictionary loads this file and then searches for appropriate word. The search pattern in very simple. By default it will search for exact match (which is dictionary look up method of c#) and additionally it will iterate through all dictionary key value pairs and add the entries which start with search query. The second radio button, if checked, will only give exact match, or if nothing found there won't be any result. This much is sufficient for me in most cases. I am hoping it would be for most people as well. It is compiled on Windows 7 64 bit. So I am not sure whether it would work on every system (including Windows 7 32 bit). But I am attaching source project as well as compiled dictionary. The project can be compiled using Sharp Develop 4. The dictionary assumes that you have installed Jameel Noori Nastaleeq. Please get it if you don't have.
Dictionary
Source Code (Sharp Develop Project) 

Update: Another dictionary was added afterwards, a 27000 words dictionary provided from Alqlm.org.
Dictionary
Source Code

Wednesday, May 12, 2010

Sorting a Dictionary in C# 2

During corpus processing tasks, I need to create and sort dictionaries for very simple tasks of frequency list generation. For this purpose I always have to seek on the web for solutions. C# is now at version 4 and it has lots of variations and innovations in its syntax. There are additional typing conventions, keywords, namespaces like powerful System.LINQ and extension methods. But being a linguistics student I am unable find time to upgrade my skills from C# 2005 a.k.a C# 2 to latest versions. It is not necessary perhaps also because I need C# for text processing tasks which is done very easily with C# 2 and its System.Collections.Generic namespace.
So here is a code sample which can be used to sort a dictionary with respect to its values. I have blended 2 or 3 methods into one so that it takes input as dictionary and gives output as dictionary. Code may be inefficient due to my inabilities in programming but still it works for me. Hopefully for you it would work also. :-)
public static Dictionary Sort (Dictionary dict)
{
List> list = new List>();
foreach(KeyValuePair kvp in dict)
{
list.Add(kvp);
}
list.Sort(
delegate(KeyValuePair firstPair,
KeyValuePair nextPair)
{
return nextPair.Value.CompareTo(firstPair.Value);
}
);
Dictionary d = new Dictionary();
foreach(KeyValuePair kvp in list)
{
d.Add(kvp.Key, kvp.Value);
}
return d;
}