public virtual void nounInflectionalVariantsTest() { WordElement word = lexicon.getWord("sanctum", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); Assert.AreEqual(Inflection.REGULAR, word.getDefaultInflectionalVariant()); // reg plural shouldn't be stored Assert.AreEqual(null, word.getFeature(LexicalFeature.PLURAL)); InflectedWordElement infl = new InflectedWordElement(word); infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); string plur = realiser.realise(infl).Realisation; Assert.AreEqual("sanctums", plur); // switch to glreg word.setDefaultInflectionalVariant(Inflection.GRECO_LATIN_REGULAR); infl = new InflectedWordElement(word); infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); plur = realiser.realise(infl).Realisation; Assert.AreEqual("sancta", plur); // and back to reg word.setDefaultInflectionalVariant(Inflection.REGULAR); infl = new InflectedWordElement(word); infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); plur = realiser.realise(infl).Realisation; Assert.AreEqual("sanctums", plur); }
public virtual void verbInflectionalVariantsTest() { WordElement word = lexicon.getWord("lie", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)); Assert.AreEqual(Inflection.REGULAR, word.getDefaultInflectionalVariant()); // default past is "lied" InflectedWordElement infl = new InflectedWordElement(word); infl.setFeature(Feature.TENSE, Tense.PAST); string past = realiser.realise(infl).Realisation; Assert.AreEqual("lied", past); // switch to irregular word.setDefaultInflectionalVariant(Inflection.IRREGULAR); infl = new InflectedWordElement(word); infl.setFeature(Feature.TENSE, Tense.PAST); past = realiser.realise(infl).Realisation; Assert.AreEqual("lay", past); // switch back to regular word.setDefaultInflectionalVariant(Inflection.REGULAR); Assert.AreEqual(null, word.getFeature(LexicalFeature.PAST)); infl = new InflectedWordElement(word); infl.setFeature(Feature.TENSE, Tense.PAST); past = realiser.realise(infl).Realisation; Assert.AreEqual("lied", past); }
/** * Grabs the head verb of the verb phrase and sets it to future tense if the * phrase is future tense. It also turns off negation if the group has a * modal. * * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param tenseValue * the <code>Tense</code> of the phrase. * @param hasModal * <code>true</code> if the verb phrase has a modal. * @return the modified head element */ private static NLGElement grabHeadVerb(PhraseElement phrase, Tense?tenseValue, bool hasModal) { NLGElement frontVG = phrase.getHead(); if (frontVG != null) { if (frontVG is WordElement) { frontVG = new InflectedWordElement((WordElement)frontVG); } // AG: tense value should always be set on frontVG if (tenseValue != null) { frontVG.setFeature(Feature.TENSE, tenseValue); } // if (Tense.FUTURE.equals(tenseValue) && frontVG != null) { // frontVG.setFeature(Feature.TENSE, Tense.FUTURE); // } if (hasModal) { frontVG.setFeature(Feature.NEGATED, false); } } return(frontVG); }
/** * 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); }
/** * Creates the appropriate pronoun if the subject of the noun phrase is * pronominal. * * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @return the <code>NLGElement</code> representing the pronominal. */ private static NLGElement createPronoun(SyntaxProcessor parent, PhraseElement phrase) { string pronoun = "it"; //$NON-NLS-1$ NLGFactory phraseFactory = phrase.Factory; object personValue = phrase.getFeature(Feature.PERSON); if (Person.FIRST.Equals(personValue)) { pronoun = "I"; //$NON-NLS-1$ } else if (Person.SECOND.Equals(personValue)) { pronoun = "you"; //$NON-NLS-1$ } else { object genderValue = phrase.getFeature(LexicalFeature.GENDER); if (Gender.FEMININE.Equals(genderValue)) { pronoun = "she"; //$NON-NLS-1$ } else if (Gender.MASCULINE.Equals(genderValue)) { pronoun = "he"; //$NON-NLS-1$ } } // AG: createWord now returns WordElement; so we embed it in an // inflected word element here NLGElement element; NLGElement proElement = phraseFactory.createWord(pronoun, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PRONOUN)); if (proElement is WordElement) { element = new InflectedWordElement((WordElement)proElement); element.setFeature(LexicalFeature.GENDER, ((WordElement)proElement).getFeature(LexicalFeature.GENDER)); // Ehud - also copy over person element.setFeature(Feature.PERSON, ((WordElement)proElement).getFeature(Feature.PERSON)); } else { element = proElement; } element.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SPECIFIER); element.setFeature(Feature.POSSESSIVE, phrase.getFeature(Feature.POSSESSIVE)); element.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER)); if (phrase.hasFeature(InternalFeature.DISCOURSE_FUNCTION)) { element.setFeature(InternalFeature.DISCOURSE_FUNCTION, phrase.getFeature(InternalFeature.DISCOURSE_FUNCTION)); } return(element); }
/** * 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); }
/** * return the base form of a word * * @param element * @param baseWord * @return */ private static string getBaseForm(InflectedWordElement element, WordElement baseWord) { // unclear what the right behaviour should be // for now, prefer baseWord.getBaseForm() to element.getBaseForm() for // verbs (ie, "is" mapped to "be") // but prefer element.getBaseForm() to baseWord.getBaseForm() for other // words (ie, "children" not mapped to "child") // AG: changed this to get the default spelling variant // needed to preserve spelling changes in the VP if (element.Category == LexicalCategory.LexicalCategoryEnum.VERB) { if (baseWord != null && baseWord.DefaultSpellingVariant != null) { return(baseWord.DefaultSpellingVariant); } else { return(element.BaseForm); } } else { if (element.BaseForm != null) { return(element.BaseForm); } else if (baseWord == null) { return(null); } else { return(baseWord.DefaultSpellingVariant); } } // if (LexicalCategory.VERB == element.getCategory()) { // if (baseWord != null && baseWord.getBaseForm() != null) // return baseWord.getBaseForm(); // else // return element.getBaseForm(); // } else { // if (element.getBaseForm() != null) // return element.getBaseForm(); // else if (baseWord == null) // return null; // else // return baseWord.getBaseForm(); // } }
/** * 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); }
/** * Checks to see if the noun is possessive. If it is then nouns in ending in * <em>-s</em> become <em>-s'</em> while every other noun has <em>-'s</em> appended to * the end. * * @param element * the <code>InflectedWordElement</code> * @param realised * the realisation of the word. */ private static void checkPossessive(InflectedWordElement element, StringBuilder realised) { if (element.getFeatureAsBoolean(Feature.POSSESSIVE)) { if (realised[realised.Length - 1] == 's') { realised.Append('\''); } else { realised.Append("'s"); //$NON-NLS-1$ } } }
private static bool isWHPronoun(InflectedWordElement word) { string @base = word.BaseForm; bool wh = false; if (!ReferenceEquals(@base, null)) { for (int i = 0; i < WH_PRONOUNS.Length && !wh; i++) { wh = WH_PRONOUNS[i].Equals(@base); } } return(wh); }
/** * Adds <em>have</em> to the stack. * * @param frontVG * the first verb in the verb group. * @param vgComponents * the stack of verb components in the verb group. * @param modal * the modal to be used. * @param tenseValue * the <code>Tense</code> of the phrase. * @return the new element for the front of the group. */ private static NLGElement addHave(NLGElement frontVG, Stack <NLGElement> vgComponents, string modal, Tense tenseValue) { NLGElement newFront = frontVG; if (frontVG != null) { frontVG.setFeature(Feature.FORM, Form.PAST_PARTICIPLE); vgComponents.Push(frontVG); } newFront = new InflectedWordElement("have", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)); //$NON-NLS-1$ newFront.setFeature(Feature.TENSE, tenseValue); if (!ReferenceEquals(modal, null)) { newFront.setFeature(InternalFeature.NON_MORPH, true); } return(newFront); }
/** * Adds <em>not</em> to the stack if the phrase is negated. * * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param vgComponents * the stack of verb components in the verb group. * @param frontVG * the first verb in the verb group. * @param hasModal * the phrase has a modal * @return the new element for the front of the group. */ private static NLGElement createNot(PhraseElement phrase, Stack <NLGElement> vgComponents, NLGElement frontVG, bool hasModal) { NLGElement newFront = frontVG; if (phrase.getFeatureAsBoolean(Feature.NEGATED)) { NLGFactory factory = phrase.Factory; // before adding "do", check if this is an object WH interrogative // in which case, don't add anything as it's already done by ClauseHelper object interrType = phrase.getFeature(Feature.INTERROGATIVE_TYPE); bool addDo = !(InterrogativeType.WHAT_OBJECT.Equals(interrType) || InterrogativeType.WHO_OBJECT.Equals(interrType)); if (vgComponents.Any() || frontVG != null && isCopular(frontVG)) { vgComponents.Push(new InflectedWordElement("not", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB))); //$NON-NLS-1$ } else { if (frontVG != null && !hasModal) { frontVG.setFeature(Feature.NEGATED, true); vgComponents.Push(frontVG); } vgComponents.Push(new InflectedWordElement("not", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB))); //$NON-NLS-1$ if (addDo) { if (factory != null) { newFront = factory.createInflectedWord("do", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)); } else { newFront = new InflectedWordElement("do", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)); //$NON-NLS-1$ } } } } return(newFront); }
public virtual void layTest() { string lemma = "slap"; WordElement word = lexicon.lookupWord(lemma, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)); InflectedWordElement inflectedWord = new InflectedWordElement(word); inflectedWord.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE); string form = realiser.realise(inflectedWord).Realisation; Assert.AreEqual("slapping", form); VPPhraseSpec v = phraseFactory.createVerbPhrase("slap"); v.setFeature(Feature.PROGRESSIVE, true); string progressive = realiser.realise(v).Realisation; Assert.AreEqual("is slapping", progressive); }
public virtual void kalijurandTest() { string lemma = "walk"; WordElement word = lexicon.lookupWord(lemma, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)); InflectedWordElement inflectedWord = new InflectedWordElement(word); inflectedWord.setFeature(Feature.FORM, Form.PAST_PARTICIPLE); string form = realiser.realise(inflectedWord).Realisation; Assert.AreEqual("walked", form); inflectedWord = new InflectedWordElement(word); inflectedWord.setFeature(Feature.PERSON, Person.THIRD); form = realiser.realise(inflectedWord).Realisation; Assert.AreEqual("walks", form); }
public void kalijurandTest() { // K Kalijurand's test var lemma = "walk"; var word = SetupForExternalTest.lexicon.lookupWord(lemma, new LexicalCategory_VERB()); var inflectedWord = new InflectedWordElement(word); inflectedWord.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE); var form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation(); Assert.AreEqual("walked", form); inflectedWord = new InflectedWordElement(word); inflectedWord.setFeature(Feature.PERSON.ToString(), Person.THIRD); form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation(); Assert.AreEqual("walks", form); }
public void layTest() { // Richard Lay's test var lemma = "slap"; var word = SetupForExternalTest.lexicon.lookupWord(lemma, new LexicalCategory_VERB()); var inflectedWord = new InflectedWordElement(word); inflectedWord.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE); var form = SetupForExternalTest.realiser.realise(inflectedWord).getRealisation(); Assert.AreEqual("slapping", form); var v = SetupForExternalTest.phraseFactory.createVerbPhrase("slap"); v.setFeature(Feature.PROGRESSIVE.ToString(), true); var progressive = SetupForExternalTest.realiser.realise(v).getRealisation(); Assert.AreEqual("is slapping", progressive); }
/** * The main method for realising coordinated phrases. * * @param parent * the <code>SyntaxProcessor</code> that called this method. * @param phrase * the <code>CoordinatedPhrase</code> to be realised. * @return the realised <code>NLGElement</code>. */ internal static NLGElement realise(SyntaxProcessor parent, CoordinatedPhraseElement phrase) { ListElement realisedElement = null; if (phrase != null) { realisedElement = new ListElement(); PhraseHelper.realiseList(parent, realisedElement, phrase.PreModifiers, DiscourseFunction.PRE_MODIFIER); CoordinatedPhraseElement coordinated = new CoordinatedPhraseElement(); IList <NLGElement> children = phrase.Children; string conjunction = phrase.getFeatureAsString(Feature.CONJUNCTION); coordinated.setFeature(Feature.CONJUNCTION, conjunction); coordinated.setFeature(Feature.CONJUNCTION_TYPE, phrase.getFeature(Feature.CONJUNCTION_TYPE)); InflectedWordElement conjunctionElement = null; if (children != null && children.Any()) { if (phrase.getFeatureAsBoolean(Feature.RAISE_SPECIFIER)) { raiseSpecifier(children); } NLGElement child = phrase.LastCoordinate; child.setFeature(Feature.POSSESSIVE, phrase.getFeature(Feature.POSSESSIVE)); child = children[0]; setChildFeatures(phrase, child); coordinated.addCoordinate(parent.realise(child)); for (int index = 1; index < children.Count; index++) { child = children[index]; setChildFeatures(phrase, child); if (phrase.getFeatureAsBoolean(Feature.AGGREGATE_AUXILIARY)) { child.setFeature(InternalFeature.REALISE_AUXILIARY, false); } if (child.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.CLAUSE))) { child.setFeature(Feature.SUPRESSED_COMPLEMENTISER, phrase.getFeature(Feature.SUPRESSED_COMPLEMENTISER)); } //skip conjunction if it's null or empty string if (!ReferenceEquals(conjunction, null) && conjunction.Length > 0) { conjunctionElement = new InflectedWordElement(conjunction, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.CONJUNCTION)); conjunctionElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.CONJUNCTION); coordinated.addCoordinate(conjunctionElement); } coordinated.addCoordinate(parent.realise(child)); } realisedElement.addComponent(coordinated); } PhraseHelper.realiseList(parent, realisedElement, phrase.PostModifiers, DiscourseFunction.POST_MODIFIER); PhraseHelper.realiseList(parent, realisedElement, phrase.Complements, DiscourseFunction.COMPLEMENT); } 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); }
/** * 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); }
/** * @param args */ public static void Main(string[] args) { // below is a simple complete example of using simplenlg V4 // afterwards is an example of using simplenlg just for morphology // set up Lexicon lexicon = new XMLLexicon(); // default simplenlg lexicon NLGFactory nlgFactory = new NLGFactory(lexicon); // factory based on lexicon // create sentences // "John did not go to the bigger park. He played football there." NPPhraseSpec thePark = nlgFactory.createNounPhrase("the", "park"); // create an NP AdjPhraseSpec bigp = nlgFactory.createAdjectivePhrase("big"); // create AdjP bigp.setFeature(Feature.IS_COMPARATIVE, true); // use comparative form ("bigger") thePark.addModifier(bigp); // add adj as modifier in NP // above relies on default placement rules. You can force placement as a premodifier // (before head) by using addPreModifier PPPhraseSpec toThePark = nlgFactory.createPrepositionPhrase("to"); // create a PP toThePark.setObject(thePark); // set PP object // could also just say nlgFactory.createPrepositionPhrase("to", the Park); SPhraseSpec johnGoToThePark = nlgFactory.createClause("John", "go", toThePark); // create sentence johnGoToThePark.setFeature(Feature.TENSE, Tense.PAST); // set tense johnGoToThePark.setFeature(Feature.NEGATED, true); // set negated // note that constituents (such as subject and object) are set with setXXX methods // while features are set with setFeature DocumentElement sentence = nlgFactory.createSentence(johnGoToThePark); // below creates a sentence DocumentElement by concatenating strings StringElement hePlayed = new StringElement("he played"); StringElement there = new StringElement("there"); WordElement football = new WordElement("football"); DocumentElement sentence2 = nlgFactory.createSentence(); sentence2.addComponent(hePlayed); sentence2.addComponent(football); sentence2.addComponent(there); // now create a paragraph which contains these sentences DocumentElement paragraph = nlgFactory.createParagraph(); paragraph.addComponent(sentence); paragraph.addComponent(sentence2); // create a realiser. Note that a lexicon is specified, this should be // the same one used by the NLGFactory Realiser realiser = new Realiser(lexicon); //realiser.setDebugMode(true); // uncomment this to print out debug info during realisation NLGElement realised = realiser.realise(paragraph); Console.WriteLine(realised.Realisation); // end of main example // second example - using simplenlg just for morphology // below is clumsy as direct access to morphology isn't properly supported in V4.2 // hopefully will be better supported in later versions // get word element for "child" WordElement word = (WordElement)nlgFactory.createWord("child", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); // create InflectedWordElement from word element InflectedWordElement inflectedWord = new InflectedWordElement(word); // set the inflected word to plural inflectedWord.Plural = true; // realise the inflected word string result = realiser.realise(inflectedWord).Realisation; Console.WriteLine(result); }
public virtual void beInflectionTest() { Realiser r = new Realiser(); WordElement word = lexicon.getWord("be", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)); InflectedWordElement inflWord = new InflectedWordElement(word); inflWord.setFeature(Feature.PERSON, Person.FIRST); inflWord.setFeature(Feature.TENSE, Tense.PAST); Assert.AreEqual("was", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.SECOND); inflWord.setFeature(Feature.TENSE, Tense.PAST); Assert.AreEqual("were", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.THIRD); inflWord.setFeature(Feature.TENSE, Tense.PAST); Assert.AreEqual("was", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.FIRST); inflWord.setFeature(Feature.TENSE, Tense.PRESENT); Assert.AreEqual("am", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.SECOND); inflWord.setFeature(Feature.TENSE, Tense.PRESENT); Assert.AreEqual("are", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.THIRD); inflWord.setFeature(Feature.TENSE, Tense.PRESENT); Assert.AreEqual("is", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.NUMBER, NumberAgreement.PLURAL); inflWord.setFeature(Feature.PERSON, Person.FIRST); inflWord.setFeature(Feature.TENSE, Tense.PAST); Assert.AreEqual("were", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.SECOND); inflWord.setFeature(Feature.TENSE, Tense.PAST); Assert.AreEqual("were", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.THIRD); inflWord.setFeature(Feature.TENSE, Tense.PAST); Assert.AreEqual("were", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.FIRST); inflWord.setFeature(Feature.TENSE, Tense.PRESENT); Assert.AreEqual("are", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.SECOND); inflWord.setFeature(Feature.TENSE, Tense.PRESENT); Assert.AreEqual("are", r.realise(inflWord).ToString()); inflWord.setFeature(Feature.PERSON, Person.THIRD); inflWord.setFeature(Feature.TENSE, Tense.PRESENT); Assert.AreEqual("are", r.realise(inflWord).ToString()); }
public override NLGElement realise(NLGElement element) { NLGElement realisedElement = null; if (element != null && !element.getFeatureAsBoolean(Feature.ELIDED)) { if (element is DocumentElement) { IList <NLGElement> children = element.Children; ((DocumentElement)element).Components = realise(children); realisedElement = element; } else if (element is PhraseElement) { realisedElement = realisePhraseElement((PhraseElement)element); } else if (element is ListElement) { realisedElement = new ListElement(); ((ListElement)realisedElement).addComponents(realise(element.Children)); } else if (element is InflectedWordElement) { string baseForm = ((InflectedWordElement)element).BaseForm; ElementCategory category = element.Category; if (lexicon != null && !ReferenceEquals(baseForm, null)) { WordElement word = ((InflectedWordElement)element).BaseWord; if (word == null) { if (category is LexicalCategory) { word = lexicon.lookupWord(baseForm, (LexicalCategory)category); } else { word = lexicon.lookupWord(baseForm); } } if (word != null) { ((InflectedWordElement)element).BaseWord = word; } } realisedElement = element; } else if (element is WordElement) { // AG: need to check if it's a word element, in which case it // needs to be marked for inflection InflectedWordElement infl = new InflectedWordElement((WordElement)element); // the inflected word inherits all features from the base word foreach (string feature in element.AllFeatureNames) { infl.setFeature(feature, element.getFeature(feature)); } realisedElement = realise(infl); } else if (element is CoordinatedPhraseElement) { realisedElement = CoordinatedPhraseHelper.realise(this, (CoordinatedPhraseElement)element); } else { realisedElement = element; } } // Remove the spurious ListElements that have only one element. if (realisedElement is ListElement) { if (((ListElement)realisedElement).size() == 1) { realisedElement = ((ListElement)realisedElement).First; } } return(realisedElement); }