CIT 591 Assignment 6: Language Translation
Fall 2005, 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.

Translation details:

Your program will read in sentences from the user (one sentence at a time), 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 display the result. 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.) Feel free to add words to this dictionary.

Create an interface named RuleSet which declares the following methods:

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

Also create 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.

Write a class LanguageTranslator which the GUI will call (approximately) as follows:

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

In this, the fromLanguage and the toLanguage are each one of the Strings "English", "German", or "French".

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 "to" language 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 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; use short methods that each do only a single thing.

Provided files:

You can get my files as a zip file, Translator.zip, or individually, as Translator.java, Dictionary.java, and DictionaryTest.java.

Grading:

We will pay careful attention to formatting and style.

Due date:

October 24 or later, via Blackboard only.