package grammar.output;
import java.io.IOException;
import java.util.Arrays;
//import java.util.Date;
import java.util.List;
import java.util.TreeSet;
import grammar.model.Form;
import grammar.model.Language;
import grammar.model.PersonalPronounCategory;
import grammar.model.PersonalPronounRole;
import grammar.model.Form.FormCategory;
import grammar.model.factory.ModelVerbFactory;
import grammar.model.verbs.ModelVerb;
import grammar.model.verbs.Tense;
import grammar.model.verbs.ModelVerb.ConjugatedVerb;
import grammar.util.Utilities;
public class Conjugator {
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.err.println("java grammar.output.Conjugator <infinitive> <language>");
System.exit(-1);
}
String infinitive = args[0].toLowerCase();
//����������
Language l = Language.valueOf(Utilities.asConstantName(args[1]));
new Conjugator().conjugate(infinitive, l, false);
}
public void conjugate(String infinitive, Language language, boolean allForms) throws IOException {
//System.err.println("Conjugator.conjugate(S,L,b):"+new Date());
// System.out.println("Conjugator.conjugate(): "+infinitive);
conjugate(infinitive, language, allForms, Arrays.asList(Tense.values(language)));
}
public void conjugate(String infinitive, Language language, boolean allForms, List<Tense> tenses) throws IOException {
StringBuilder sb = new StringBuilder();
//System.err.println("Conjugator.conjugate(S,L,b,Lt):"+new Date());
ModelVerbFactory mvf = ModelVerbFactory.getInstance(language);
sb.append("Infinitive: "+infinitive+"\n");
ModelVerb mv = mvf.getModelVerb(infinitive, language);
sb.append("Selected model verb: " + mv.toString()+"\n");
ConjugatedVerb cv = mv.getConjugatedVerb(infinitive);
sb.append("Auxiliary verb: "+cv.getAuxiliary().toString()+"\n");
for (Tense t : tenses) {
int i = 0; i++;
for (FormCategory p : mv.getForms(t)) {
Form[] l;
l = p instanceof PersonalPronounCategory ?
((PersonalPronounCategory) p).getForms(language, PersonalPronounRole.SUBJECT) :
p.getAllForms(language);
if (!allForms) {
l = new Form[] {new TreeSet<Form>(Arrays.asList(l)).iterator().next()};
}
for (Form f : l) {
sb.append(
"Mood: "+t.getMood().toString().replace('_', ' ').toLowerCase()+
"; tense: "+t.toString().replace('_', ' ').toLowerCase()+
"; form: "+p.toString().replace('_', ' ').toLowerCase()+
"; conjugation: "+cv.getForm(t, f)+"\n");
}
}
}
System.out.print(sb.toString());
}
}