package grammar.model.verbs;
//import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import grammar.model.Form;
import grammar.model.Multiplicity;
import grammar.model.PersonalPronoun;
import grammar.model.ReflexiveClitic;
import grammar.model.SubjectGender;
import grammar.model.factory.CliticOrderFactory;
import grammar.model.verbs.ModelVerb.ConjugatedVerb;
/**
* An inflection of a verb, with respect to factors such as tense, subject pronoun,
* mood, etc.
*
* @author Duncan Roberts
*/
public class Conjugation {
private final Mood mood;
private final Tense tense;
private final Form form;
private final ConjugatedVerb conjugatedVerb;
private final ModelVerb modelVerb;
private final boolean question;
private final Map<Segment, String> primarySegments = new HashMap<Segment, String>();
private final Map<Segment, String> auxiliarySegments = new HashMap<Segment, String>();
private final boolean auxiliary;
public Conjugation(Tense tense, Form pronoun, ConjugatedVerb conjugatedVerb, boolean question) {
//System.err.println("new Conjugation():"+new Date());
this.mood = tense.getMood();
this.tense = tense;
this.form = pronoun;
this.conjugatedVerb = conjugatedVerb;
this.modelVerb = conjugatedVerb.getModelVerb();
this.question = question;
// Retrieve individual inflected segment Strings
boolean aux = false;
for (Segment segment : Segment.values()) {
primarySegments.put(segment, modelVerb.getText(tense, conjugatedVerb, pronoun.getCategory(), segment, false));
String str = conjugatedVerb.getAuxiliary().getText(tense, conjugatedVerb.getAuxiliary().getConjugatedVerb(), pronoun.getCategory(), segment, true);
if (str != null) {
auxiliarySegments.put(segment, str);
aux = true;
}
}
auxiliary = aux;
}
public boolean isNegative() {
return false; // FIXME
}
/**
* Renders the model
*
* @return
*/
public String inflect() {
//System.err.println("Conjugation.inflect():"+new Date());
return CliticOrderFactory.getInstance(modelVerb.getLanguage()).getClosestMatch(this).inflect(this);
}
public String toString() {
return inflect();
}
public Mood getMood() {
return mood;
}
public Tense getTense() {
return tense;
}
public Form getPronoun() {
return form;
}
public ConjugatedVerb getConjugatedVerb() {
return conjugatedVerb;
}
public ModelVerb getModelVerb() {
return modelVerb;
}
public boolean isQuestion() {
return question;
}
public String getPrefix() {
return primarySegments.get(Segment.PREFIX);
}
public boolean hasPrefix() {
return getPrefix() != null;
}
public String getStem() {
return primarySegments.get(Segment.STEM);
}
public boolean hasStem() {
return getStem() != null;
}
public String getInfix() {
return primarySegments.get(Segment.INFIX);
}
public boolean hasInfix() {
return getInfix() != null;
}
public String getSuffix() {
return primarySegments.get(Segment.SUFFIX);
}
public boolean hasSuffix() {
return getSuffix() != null;
}
// Auxiliary
public String getAuxiliaryPrefix() {
return auxiliarySegments.get(Segment.PREFIX);
}
public boolean hasAuxiliaryPrefix() {
return getAuxiliaryPrefix() != null;
}
public String getAuxiliaryStem() {
return auxiliarySegments.get(Segment.STEM);
}
public boolean hasAuxiliaryStem() {
return getAuxiliaryStem() != null;
}
public String getAuxiliaryInfix() {
return auxiliarySegments.get(Segment.INFIX);
}
public boolean hasAuxiliaryInfix() {
return getAuxiliaryInfix() != null;
}
public String getAuxiliarySuffix() {
return auxiliarySegments.get(Segment.SUFFIX);
}
public boolean hasAuxiliarySuffix() {
return getAuxiliarySuffix() != null;
}
public boolean hasAuxiliary() {
return auxiliary;
}
public boolean isPersonal() {
return mood.isPersonal();
}
public boolean isReflexive() {
return conjugatedVerb.isReflexive();
}
public SubjectGender getSubjectGender() {
if (!(form instanceof PersonalPronoun))
return null;
PersonalPronoun pp = (PersonalPronoun) form;
return pp.getGender();
}
public Multiplicity getPronounMultiplicity() {
if (!(form instanceof PersonalPronoun))
return null;
PersonalPronoun pp = (PersonalPronoun) form;
return pp.getMultiplicity();
}
public boolean auxiliaryPronounAgreement() {
return conjugatedVerb.getAuxiliary().pronounAgreement();
}
public ReflexiveClitic getReflexiveClitic() {
return ReflexiveClitic.getInstance(modelVerb.getLanguage());
}
}