/** * 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); }
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); }
/** * 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); }
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 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); }
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); }
/** * 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); }
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); }