CIT 590 Assignment 8: Language Translation
Spring 2009, David Matuszek

Purposes of this assignment:

General idea of the assignment:

Write a program to translate from one language to another. The program will do word-for-word translation, then re-order the words according to the rules of the new language.

Note that this kind of translation gives very poor results, and is almost a parody of what a practical translator must do. It is, however, a beginning.

Translation details:

I have provided the main program, Translator.java, which implements a GUI (Graphical User Interface).

Your translate method will break each sentence up into individual words, use a dictionary to translate the words from the source (input) language to the target (output) language, rearrange the words to follow the rules of the target language, and return the result. (It should be obvious to you that all this work shouldn't be done in one big monolithic method!) You do not have to worry about punctuation.

English:

Verb rule: The verb comes after the first noun in the sentence.

Adjective rule: Adjectives precede nouns. If any adjective is found immediately following a noun, it should be moved to before the noun.

French:

Verb rule: The verb comes before the second noun in the sentence, or at the end of the sentence if there is only one noun.

Adjective rule: Adjectives follow nouns. If any adjective is found immediately before a noun, it should be moved to after the noun.

German:

Verb rule: The verb comes at the end of the sentence.

Adjective rule: Adjectives precede nouns. If any adjective is found immediately following a noun, it should be moved to before the noun.

Implementation details:

I have provided some classes for your use. They are:

The Translator GUI should be self-explanatory.

The Dictionary has a static method getWordList(String language), which takes one of the arguments "TYPE", "English", "German", or "French". Each call to this method will return an array of Strings. You can look up the translation of a word by finding its index in the appropriate word list, then using that same index into another word list. You can find the "part of speech" of a word by using its index into the "TYPE" word list. (For example, if the word "table" is at index location 3 in the English word list, then its translation into French is at location 3 in the French word list, and "NOUN" is at location 3 in the TYPE list.) Add words to this dictionary--at least a dozen--but don't delete or change any that have been provided.

There is an interface named RuleSet which declares the following methods:

void applyVerbRule(String[] words);
void applyAdjectiveRule(String[] words);

There are three classes, EnglishRules, GermanRules, and FrenchRules, each of which implements the RuleSet interface. Each class will contain the required two methods, and each method will take an array of words and rearrange the words according to the given language requirements. I've given you the skeleton for these classes; you need to fill in the working code.

The GUI will call the class LanguageTranslator approximately as follows:

LanguageTranslator translator =
      new LanguageTranslator(fromLanguage, toLanguage);
String translation = translator.translate(someText);

In this, the fromLanguage and the toLanguage should each be one of the Strings "English", "German", or "French". Throw an IllegalArgumentException if this is not the case.

Your LanguageTranslator class should have a constructor which takes as arguments a pair of language names and creates an appropriate translator object. The constructor will use the language names to get the appropriate word lists (along with a list of the word types). It will use the toLanguage name to get a RuleSet object which it can ask to rearrange the translated words.

The LanguageTranslator object will include a translate method that, given a String in the fromLanguage, translates it to a String in the toLanguage.

Your translate method (along with any methods it calls) will do the following:

The GUI will display the result.

Yes, you need to do unit testing on just about everything. Make it easy on yourself; write the tests first, then use short methods that each do only a single thing. It's a lot easier to test (and debug) a lot of small methods, than it is to test (and hopefully debug) longer methods that do several things.

Provided files:

You can get my files as a zip file, LanguageTranslator.zip.

Structure of the assignment:

The above are requirements. You may have additional classes and methods as needed, and they should be documented and unit tested as appropriate.

Grading:

We will pay careful attention to formatting and style.

Due date:

Thursday, March 26, before midnight.