/** * This method performs the morphology for adjectives. * * @param element * the <code>InflectedWordElement</code>. * @param baseWord * the <code>WordElement</code> as created from the lexicon * entry. * @return a <code>StringElement</code> representing the word after * inflection. */ public static NLGElement doAdjectiveMorphology(InflectedWordElement element, WordElement baseWord) { string realised = null; object patternValue = element.getFeature(LexicalFeature.DEFAULT_INFL); // base form from baseWord if it exists, otherwise from element string baseForm = getBaseForm(element, baseWord); if (element.getFeatureAsBoolean(Feature.IS_COMPARATIVE)) { realised = element.getFeatureAsString(LexicalFeature.COMPARATIVE); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.COMPARATIVE); } if (ReferenceEquals(realised, null)) { if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoubleCompAdjective(baseForm); } else { realised = buildRegularComparative(baseForm); } } } else if (element.getFeatureAsBoolean(Feature.IS_SUPERLATIVE)) { realised = element.getFeatureAsString(LexicalFeature.SUPERLATIVE); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.SUPERLATIVE); } if (ReferenceEquals(realised, null)) { if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoubleSuperAdjective(baseForm); } else { realised = buildRegularSuperlative(baseForm); } } } else { realised = baseForm; } StringElement realisedElement = new StringElement(realised); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); return(realisedElement); }
/** * This is the main method for performing the morphology. It effectively * examines the lexical category of the element and calls the relevant set * of rules from <code>MorphologyRules</em>. * * @param element * the <code>InflectedWordElement</code> * @return an <code>NLGElement</code> reflecting the correct inflection for * the word. */ private NLGElement doMorphology(InflectedWordElement element) { NLGElement realisedElement = null; if (element.getFeatureAsBoolean(InternalFeature.NON_MORPH)) { realisedElement = new StringElement(element.BaseForm); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); } else { NLGElement baseWord = element.getFeatureAsElement(InternalFeature.BASE_WORD); if (baseWord == null && lexicon != null) { baseWord = lexicon.lookupWord(element.BaseForm); } ElementCategory category = element.Category; if (category is LexicalCategory) { switch (((LexicalCategory)category).GetLexicalCategory()) { case LexicalCategory.LexicalCategoryEnum.PRONOUN: realisedElement = MorphologyRules.doPronounMorphology(element); break; case LexicalCategory.LexicalCategoryEnum.NOUN: realisedElement = MorphologyRules.doNounMorphology(element, (WordElement)baseWord); break; case LexicalCategory.LexicalCategoryEnum.VERB: realisedElement = MorphologyRules.doVerbMorphology(element, (WordElement)baseWord); break; case LexicalCategory.LexicalCategoryEnum.ADJECTIVE: realisedElement = MorphologyRules.doAdjectiveMorphology(element, (WordElement)baseWord); break; case LexicalCategory.LexicalCategoryEnum.ADVERB: realisedElement = MorphologyRules.doAdverbMorphology(element, (WordElement)baseWord); break; default: realisedElement = new StringElement(element.BaseForm); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); break; } } } return(realisedElement); }
/** * This method performs the morphology for pronouns. * * @param element * the <code>InflectedWordElement</code>. * @return a <code>StringElement</code> representing the word after * inflection. */ public static NLGElement doPronounMorphology(InflectedWordElement element) { string realised = null; if (!element.getFeatureAsBoolean(InternalFeature.NON_MORPH) && !isWHPronoun(element)) { object genderValue = element.getFeature(LexicalFeature.GENDER); object personValue = element.getFeature(Feature.PERSON); object discourseValue = element.getFeature(InternalFeature.DISCOURSE_FUNCTION); int numberIndex = element.Plural ? 1 : 0; int genderIndex = (genderValue is Gender) ? (int)((Gender)genderValue) : 2; int personIndex = (personValue is Person) ? (int)((Person)personValue) : 2; if (personIndex == 2) { personIndex += genderIndex; } int positionIndex = 0; if (element.getFeatureAsBoolean(LexicalFeature.REFLEXIVE)) { positionIndex = 2; } else if (element.getFeatureAsBoolean(Feature.POSSESSIVE)) { positionIndex = 3; if (DiscourseFunction.SPECIFIER.Equals(discourseValue)) { positionIndex++; } } else { positionIndex = (DiscourseFunction.SUBJECT.Equals(discourseValue) && !element.getFeatureAsBoolean(Feature.PASSIVE)) || (DiscourseFunction.OBJECT.Equals(discourseValue) && element.getFeatureAsBoolean(Feature.PASSIVE)) || DiscourseFunction.SPECIFIER.Equals(discourseValue) || (DiscourseFunction.COMPLEMENT.Equals(discourseValue) && element.getFeatureAsBoolean(Feature.PASSIVE)) ? 0 : 1; } realised = PRONOUNS[numberIndex][positionIndex][personIndex]; } else { realised = element.BaseForm; } StringElement realisedElement = new StringElement(realised); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); return(realisedElement); }
/** * This method performs the morphology for nouns. * * @param element * the <code>InflectedWordElement</code>. * @param baseWord * the <code>WordElement</code> as created from the lexicon * entry. * @return a <code>StringElement</code> representing the word after * inflection. */ protected internal static StringElement doNounMorphology(InflectedWordElement element, WordElement baseWord) { StringBuilder realised = new StringBuilder(); // base form from baseWord if it exists, otherwise from element string baseForm = getBaseForm(element, baseWord); if (element.Plural && !element.getFeatureAsBoolean(LexicalFeature.PROPER)) { string pluralForm = null; // AG changed: now check if default infl is uncount // if (element.getFeatureAsBoolean(LexicalFeature.NON_COUNT) // .booleanValue()) { // pluralForm = baseForm; object elementDefaultInfl = element.getFeature(LexicalFeature.DEFAULT_INFL); if (elementDefaultInfl != null && Inflection.UNCOUNT.Equals(elementDefaultInfl)) { pluralForm = baseForm; } else { pluralForm = element.getFeatureAsString(LexicalFeature.PLURAL); } if (ReferenceEquals(pluralForm, null) && baseWord != null) { // AG changed: now check if default infl is uncount // if (baseWord.getFeatureAsBoolean(LexicalFeature.NON_COUNT) // .booleanValue()) { // pluralForm = baseForm; string baseDefaultInfl = baseWord.getFeatureAsString(LexicalFeature.DEFAULT_INFL); if (!ReferenceEquals(baseDefaultInfl, null) && baseDefaultInfl.Equals("uncount")) { pluralForm = baseForm; } else { pluralForm = baseWord.getFeatureAsString(LexicalFeature.PLURAL); } } if (ReferenceEquals(pluralForm, null)) { object pattern = element.getFeature(LexicalFeature.DEFAULT_INFL); if (Inflection.GRECO_LATIN_REGULAR.Equals(pattern)) { pluralForm = buildGrecoLatinPluralNoun(baseForm); } else { pluralForm = buildRegularPluralNoun(baseForm); } } realised.Append(pluralForm); } else { realised.Append(baseForm); } checkPossessive(element, realised); StringElement realisedElement = new StringElement(realised.ToString(), element.Capitalized); // adapted by GJdV realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); return(realisedElement); }
/** * This method performs the morphology for verbs. * * @param element * the <code>InflectedWordElement</code>. * @param baseWord * the <code>WordElement</code> as created from the lexicon * entry. * @return a <code>StringElement</code> representing the word after * inflection. */ protected internal static NLGElement doVerbMorphology(InflectedWordElement element, WordElement baseWord) { string realised = null; object numberValue = element.getFeature(Feature.NUMBER); object personValue = element.getFeature(Feature.PERSON); object tense = element.getFeature(Feature.TENSE); Tense? tenseValue; // AG: change to avoid deprecated getTense // if tense value is Tense, cast it, else default to present if (tense is Tense) { tenseValue = (Tense?)tense; } else { tenseValue = Tense.PRESENT; } object formValue = element.getFeature(Feature.FORM); object patternValue = element.getFeature(LexicalFeature.DEFAULT_INFL); // base form from baseWord if it exists, otherwise from element string baseForm = getBaseForm(element, baseWord); if (element.getFeatureAsBoolean(Feature.NEGATED) || Form.BARE_INFINITIVE.Equals(formValue)) { realised = baseForm; } else if (Form.PRESENT_PARTICIPLE.Equals(formValue)) { realised = element.getFeatureAsString(LexicalFeature.PRESENT_PARTICIPLE); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.PRESENT_PARTICIPLE); } if (ReferenceEquals(realised, null)) { if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoublePresPartVerb(baseForm); } else { realised = buildRegularPresPartVerb(baseForm); } } } else if (Tense.PAST.Equals(tenseValue) || Form.PAST_PARTICIPLE.Equals(formValue)) { if (Form.PAST_PARTICIPLE.Equals(formValue)) { realised = element.getFeatureAsString(LexicalFeature.PAST_PARTICIPLE); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.PAST_PARTICIPLE); } if (ReferenceEquals(realised, null)) { if ("be".Equals(baseForm, StringComparison.OrdinalIgnoreCase)) { //$NON-NLS-1$ realised = "been"; //$NON-NLS-1$ } else if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoublePastVerb(baseForm); } else { realised = buildRegularPastVerb(baseForm, numberValue, personValue); } } } else { realised = element.getFeatureAsString(LexicalFeature.PAST); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.PAST); } if (ReferenceEquals(realised, null)) { if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoublePastVerb(baseForm); } else { realised = buildRegularPastVerb(baseForm, numberValue, personValue); } } } } else if ((numberValue == null || NumberAgreement.SINGULAR.Equals(numberValue)) && (personValue == null || Person.THIRD.Equals(personValue)) && (tenseValue == null || Tense.PRESENT.Equals(tenseValue))) { realised = element.getFeatureAsString(LexicalFeature.PRESENT3S); if (ReferenceEquals(realised, null) && baseWord != null && !"be".Equals(baseForm, StringComparison.OrdinalIgnoreCase)) { //$NON-NLS-1$ realised = baseWord.getFeatureAsString(LexicalFeature.PRESENT3S); } if (ReferenceEquals(realised, null)) { realised = buildPresent3SVerb(baseForm); } } else { if ("be".Equals(baseForm, StringComparison.OrdinalIgnoreCase)) { //$NON-NLS-1$ if (Person.FIRST.Equals(personValue) && (NumberAgreement.SINGULAR.Equals(numberValue) || numberValue == null)) { realised = "am"; //$NON-NLS-1$ } else { realised = "are"; //$NON-NLS-1$ } } else { realised = baseForm; } } StringElement realisedElement = new StringElement(realised); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); return(realisedElement); }