/** * Realises the specifier of the noun phrase. * * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the noun phrase. */ private static void realiseSpecifier(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement) { INLGElement specifierElement = phrase .getFeatureAsElement(InternalFeature.SPECIFIER.ToString()); if (specifierElement != null && !phrase.getFeatureAsBoolean(InternalFeature.RAISED.ToString()) && !phrase.getFeatureAsBoolean(Feature.ELIDED.ToString())) { if (!specifierElement.isA(LexicalCategoryEnum.PRONOUN) && specifierElement.getCategory().enumType != (int)PhraseCategoryEnum.NOUN_PHRASE) { specifierElement.setFeature(Feature.NUMBER.ToString(), phrase .getFeature(Feature.NUMBER.ToString())); } var currentElement = parent.realise(specifierElement); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.SPECIFIER); realisedElement.addComponent(currentElement); } } }
/** * Realises the subjects of a passive clause. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. * @param phraseFactory * the phrase factory to be used. */ private static void addPassiveSubjects(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, NLGFactory phraseFactory) { INLGElement currentElement = null; if (phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString())) { var allSubjects = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS.ToString()); if (allSubjects.size() > 0 || phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString())) { realisedElement.addComponent(parent.realise(phraseFactory.createPrepositionPhrase("by"))); } foreach (var subject in allSubjects) { subject.setFeature(Feature.PASSIVE.ToString(), true); if (subject.isA(PhraseCategoryEnum.NOUN_PHRASE) || subject is CoordinatedPhraseElement) { currentElement = parent.realise(subject); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.SUBJECT); realisedElement.addComponent(currentElement); } } } } }
/** * Realises the head noun of the noun phrase. * * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the noun phrase. */ private static void realiseHeadNoun(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement) { INLGElement headElement = phrase.getHead(); if (headElement != null) { headElement.setFeature(Feature.ELIDED.ToString(), phrase .getFeature(Feature.ELIDED.ToString())); headElement.setFeature(LexicalFeature.GENDER, phrase .getFeature(LexicalFeature.GENDER)); headElement.setFeature(InternalFeature.ACRONYM.ToString(), phrase .getFeature(InternalFeature.ACRONYM.ToString())); headElement.setFeature(Feature.NUMBER.ToString(), phrase .getFeature(Feature.NUMBER.ToString())); headElement.setFeature(Feature.PERSON.ToString(), phrase .getFeature(Feature.PERSON.ToString())); headElement.setFeature(Feature.POSSESSIVE.ToString(), phrase .getFeature(Feature.POSSESSIVE.ToString())); headElement.setFeature(Feature.PASSIVE.ToString(), phrase .getFeature(Feature.PASSIVE.ToString())); var currentElement = parent.realise(headElement); currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.SUBJECT); realisedElement.addComponent(currentElement); } }
/** * The main method for realising noun phrases. * * @param parent * the <code>SyntaxProcessor</code> that called this method. * @param phrase * the <code>PhraseElement</code> to be realised. * @return the realised <code>NLGElement</code>. */ public static INLGElement realise(SyntaxProcessor parent, PhraseElement phrase) { ListElement realisedElement = null; if (phrase != null && !phrase.getFeatureAsBoolean(Feature.ELIDED.ToString())) { realisedElement = new ListElement(); if (phrase.getFeatureAsBoolean(Feature.PRONOMINAL.ToString())) { realisedElement.addComponent(createPronoun(parent, phrase)); } else { realiseSpecifier(phrase, parent, realisedElement); realisePreModifiers(phrase, parent, realisedElement); realiseHeadNoun(phrase, parent, realisedElement); PhraseHelper.realiseList(parent, realisedElement, phrase .getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString()), DiscourseFunction.COMPLEMENT); PhraseHelper.realiseList(parent, realisedElement, phrase .getPostModifiers(), DiscourseFunction.POST_MODIFIER); } } return(realisedElement); }
/** * Adds <em>to</em> to the end of interrogatives concerning indirect * objects. For example, <em>who did John give the flower <b>to</b></em>. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. * @param phraseFactory * the phrase factory to be used. */ private static void addEndingTo(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, NLGFactory phraseFactory) { if (InterrogativeType.WHO_INDIRECT_OBJECT.Equals(phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString()))) { var word = phraseFactory.createWord("to", new LexicalCategory_PREPOSITION()); realisedElement.addComponent(parent.realise(word)); } }
/** * Realises the verb part of the clause. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. * @param splitVerb * an <code>NLGElement</code> representing the subjects that * should split the verb * @param verbElement * the <code>NLGElement</code> representing the verb phrase for * this clause. * @param whObj * whether the VP is part of an object WH-interrogative */ private static void realiseVerb(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, INLGElement splitVerb, INLGElement verbElement, bool whObj) { setVerbFeatures(phrase, verbElement); var currentElement = parent.realise(verbElement); if (currentElement != null) { if (splitVerb == null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE); realisedElement.addComponent(currentElement); } else { if (currentElement is ListElement) { var children = currentElement.getChildren(); currentElement = children[0]; currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE); realisedElement.addComponent(currentElement); realisedElement.addComponent(splitVerb); for (var eachChild = 1; eachChild < children.Count; eachChild++) { currentElement = children[eachChild]; currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE); realisedElement.addComponent(currentElement); } } else { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE); if (whObj) { realisedElement.addComponent(currentElement); realisedElement.addComponent(splitVerb); } else { realisedElement.addComponent(splitVerb); realisedElement.addComponent(currentElement); } } } } }
/** * Adds the subjects to the beginning of the clause unless the clause is * infinitive, imperative or passive, or the subjects split the verb. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. * @param splitVerb * an <code>NLGElement</code> representing the subjects that * should split the verb */ private static void addSubjectsToFront(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, INLGElement splitVerb) { if (!Form.INFINITIVE.Equals(phrase.getFeature(Feature.FORM.ToString())) && !Form.IMPERATIVE.Equals(phrase.getFeature(Feature.FORM.ToString())) && !phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString()) && splitVerb == null) { realisedElement.addComponents(realiseSubjects(phrase, parent).getChildren()); } }
/** * Realises the pre-modifiers of the noun phrase. Before being realised, * pre-modifiers undergo some basic sorting based on adjective ordering. * * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the noun phrase. */ private static void realisePreModifiers(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement) { var preModifiers = phrase.getPreModifiers(); if (phrase.getFeatureAsBoolean(Feature.ADJECTIVE_ORDERING.ToString()) ) { preModifiers = sortNPPreModifiers(preModifiers); } PhraseHelper.realiseList(parent, realisedElement, preModifiers, DiscourseFunction.PRE_MODIFIER); }
/** * Pushes the particles of the main verb onto the verb group stack. * * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param vgComponents * the stack of verb components in the verb group. */ private static void pushParticles(PhraseElement phrase, SyntaxProcessor parent, Stack <INLGElement> vgComponents) { var particle = phrase.getFeature(Feature.PARTICLE.ToString()); if (particle is string) { vgComponents.push(new StringElement((string)particle)); } else if (particle is INLGElement) { vgComponents.push(parent.realise((INLGElement)particle)); } }
/** * Realises the auxiliary verbs in the verb group. * * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the noun phrase. * @param auxiliaryRealisation * the stack of auxiliary verbs. */ private static void realiseAuxiliaries(SyntaxProcessor parent, ListElement realisedElement, Stack <INLGElement> auxiliaryRealisation) { while (!auxiliaryRealisation.isEmpty()) { var aux = auxiliaryRealisation.pop(); var currentElement = parent.realise(aux); if (currentElement != null) { realisedElement.addComponent(currentElement); currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.AUXILIARY); } } }
/** * The main method for realising verb phrases. * * @param parent * the <code>SyntaxProcessor</code> that called this method. * @param phrase * the <code>PhraseElement</code> to be realised. * @return the realised <code>NLGElement</code>. */ public static INLGElement realise(SyntaxProcessor parent, PhraseElement phrase) { ListElement realisedElement = null; var mainVerbRealisation = new Stack <INLGElement>(); var auxiliaryRealisation = new Stack <INLGElement>(); if (phrase != null) { var vgComponents = createVerbGroup(parent, phrase); splitVerbGroup(vgComponents, mainVerbRealisation, auxiliaryRealisation); realisedElement = new ListElement(); if (!phrase.hasFeature(InternalFeature.REALISE_AUXILIARY.ToString()) || phrase.getFeatureAsBoolean( InternalFeature.REALISE_AUXILIARY.ToString())) { realiseAuxiliaries(parent, realisedElement, auxiliaryRealisation); PhraseHelper.realiseList(parent, realisedElement, phrase .getPreModifiers(), DiscourseFunction.PRE_MODIFIER); realiseMainVerb(parent, phrase, mainVerbRealisation, realisedElement); } else if (isCopular(phrase.getHead())) { realiseMainVerb(parent, phrase, mainVerbRealisation, realisedElement); PhraseHelper.realiseList(parent, realisedElement, phrase .getPreModifiers(), DiscourseFunction.PRE_MODIFIER); } else { PhraseHelper.realiseList(parent, realisedElement, phrase .getPreModifiers(), DiscourseFunction.PRE_MODIFIER); realiseMainVerb(parent, phrase, mainVerbRealisation, realisedElement); } realiseComplements(parent, phrase, realisedElement); PhraseHelper.realiseList(parent, realisedElement, phrase .getPostModifiers(), DiscourseFunction.POST_MODIFIER); } return(realisedElement); }
/** * Realises the main group of verbs in the phrase. * * @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. * @param mainVerbRealisation * the stack of the main verbs in the phrase. * @param realisedElement * the current realisation of the noun phrase. */ private static void realiseMainVerb(SyntaxProcessor parent, PhraseElement phrase, Stack <INLGElement> mainVerbRealisation, ListElement realisedElement) { while (!mainVerbRealisation.isEmpty()) { var main = mainVerbRealisation.pop(); main.setFeature(Feature.INTERROGATIVE_TYPE.ToString(), phrase .getFeature(Feature.INTERROGATIVE_TYPE.ToString())); var currentElement = parent.realise(main); if (currentElement != null) { realisedElement.addComponent(currentElement); } } }
/** * Realises the complements of this phrase. * * @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. * @param realisedElement * the current realisation of the noun phrase. */ private static void realiseComplements(SyntaxProcessor parent, PhraseElement phrase, ListElement realisedElement) { var indirects = new ListElement(); var directs = new ListElement(); var unknowns = new ListElement(); foreach (INLGElement complement in phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString())) { var discourseValue = complement .getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()); var currentElement = parent.realise(complement); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.COMPLEMENT); if (DiscourseFunction.INDIRECT_OBJECT.Equals(discourseValue)) { indirects.addComponent(currentElement); } else if (DiscourseFunction.OBJECT.Equals(discourseValue)) { directs.addComponent(currentElement); } else { unknowns.addComponent(currentElement); } } } if (!InterrogativeTypeExtensions.isIndirectObject(phrase .getFeature(Feature.INTERROGATIVE_TYPE.ToString()))) { realisedElement.addComponents(indirects.getChildren()); } if (!phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString())) { if (!InterrogativeTypeExtensions.isAndObject(phrase .getFeature(Feature.INTERROGATIVE_TYPE.ToString()))) { realisedElement.addComponents(directs.getChildren()); } realisedElement.addComponents(unknowns.getChildren()); } }
/** * Adds the front modifiers to the end of the clause when dealing with * interrogatives. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. */ private static void addInterrogativeFrontModifiers(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement) { INLGElement currentElement = null; if (phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString())) { foreach (var subject in phrase.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS.ToString())) { currentElement = parent.realise(subject); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.FRONT_MODIFIER); realisedElement.addComponent(currentElement); } } } }
/** * Realises the subjects for the clause. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. */ private static ListElement realiseSubjects(PhraseElement phrase, SyntaxProcessor parent) { INLGElement currentElement = null; var realisedElement = new ListElement(); foreach (INLGElement subject in phrase.getFeatureAsElementList(InternalFeature.SUBJECTS.ToString())) { subject.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.SUBJECT); if (Form.GERUND.Equals(phrase.getFeature(Feature.FORM.ToString())) && !phrase.getFeatureAsBoolean(Feature.SUPPRESS_GENITIVE_IN_GERUND.ToString())) { subject.setFeature(Feature.POSSESSIVE.ToString(), true); } currentElement = parent.realise(subject); if (currentElement != null) { realisedElement.addComponent(currentElement); } } return(realisedElement); }
public override void initialise() { _syntax = new SyntaxProcessor(); _factory = new NLGFactory(); }
/** * Realises the complements of passive clauses; also sets number, person for * passive * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param parent * the parent <code>SyntaxProcessor</code> that will do the * realisation of the complementiser. * @param realisedElement * the current realisation of the clause. * @param verbElement * the <code>NLGElement</code> representing the verb phrase for * this clause. */ private static INLGElement addPassiveComplementsNumberPerson(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement, INLGElement verbElement) { object passiveNumber = null; object passivePerson = null; INLGElement currentElement = null; INLGElement splitVerb = null; var verbPhrase = phrase.getFeatureAsElement(InternalFeature.VERB_PHRASE.ToString()); // count complements to set plural feature if more than one var numComps = 0; var coordSubj = false; if (phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString()) && verbPhrase != null && !InterrogativeType.WHAT_OBJECT.Equals(phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString()))) { // complements of a clause are stored in the VPPhraseSpec foreach (var subject in verbPhrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString())) { // AG: complement needn't be an NP // subject.isA(PhraseCategory.NOUN_PHRASE) && if (DiscourseFunction.OBJECT.Equals(subject.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()))) { subject.setFeature(Feature.PASSIVE.ToString(), true); numComps++; currentElement = parent.realise(subject); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.OBJECT); if (phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString())) { splitVerb = currentElement; } else { realisedElement.addComponent(currentElement); } } // flag if passive subject is coordinated with an "and" if (!coordSubj && subject is CoordinatedPhraseElement) { var conj = ((CoordinatedPhraseElement)subject).getConjunction(); coordSubj = (conj != null && conj.Equals("and")); } if (passiveNumber == null) { passiveNumber = subject.getFeature(Feature.NUMBER.ToString()); } else { passiveNumber = NumberAgreement.PLURAL; } if (Person.FIRST.Equals(subject.getFeature(Feature.PERSON.ToString()))) { passivePerson = Person.FIRST; } else if (Person.SECOND.Equals(subject.getFeature(Feature.PERSON.ToString())) && !Person.FIRST.Equals(passivePerson)) { passivePerson = Person.SECOND; } else if (passivePerson == null) { passivePerson = Person.THIRD; } if (Form.GERUND.Equals(phrase.getFeature(Feature.FORM.ToString())) && !phrase.getFeatureAsBoolean(Feature.SUPPRESS_GENITIVE_IN_GERUND.ToString())) { subject.setFeature(Feature.POSSESSIVE.ToString(), true); } } } } if (verbElement != null) { if (passivePerson != null) { verbElement.setFeature(Feature.PERSON.ToString(), passivePerson); // below commented out. for non-passive, number and person set // by checkSubjectNumberPerson // } else { // verbElement.setFeature(Feature.PERSON, phrase // .getFeature(Feature.PERSON)); } if (numComps > 1 || coordSubj) { verbElement.setFeature(Feature.NUMBER.ToString(), NumberAgreement.PLURAL); } else if (passiveNumber != null) { verbElement.setFeature(Feature.NUMBER.ToString(), passiveNumber); } } return(splitVerb); }
/** * Creates a stack of verbs for the verb phrase. Additional auxiliary verbs * are added as required based on the features of the verb phrase. * * @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 verb group as a <code>Stack</code> of <code>NLGElement</code> * s. */ public static Stack <INLGElement> createVerbGroup( SyntaxProcessor parent, PhraseElement phrase) { string actualModal = null; var formValue = phrase.getFeature(Feature.FORM.ToString()); Tense tenseValue = phrase.getFeatureTense(Feature.TENSE.ToString()); var modal = phrase.getFeatureAsString(Feature.MODAL.ToString()); var modalPast = false; var vgComponents = new Stack <INLGElement>(); var interrogative = phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString()); if (Form.GERUND.Equals(formValue) || Form.INFINITIVE.Equals(formValue)) { tenseValue = Tense.PRESENT; } if (Form.INFINITIVE.Equals(formValue)) { actualModal = "to"; } else if (formValue == null || Form.NORMAL.Equals(formValue)) { if (Tense.FUTURE.Equals(tenseValue) && modal == null && ((!(phrase.getHead() is CoordinatedPhraseElement)) || (phrase .getHead() is CoordinatedPhraseElement && interrogative))) { actualModal = "will"; } else if (modal != null) { actualModal = modal; if (Tense.PAST.Equals(tenseValue)) { modalPast = true; } } } pushParticles(phrase, parent, vgComponents); var frontVG = grabHeadVerb(phrase, tenseValue, modal != null); checkImperativeInfinitive(formValue, frontVG); if (phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString())) { frontVG = addBe(frontVG, vgComponents, Form.PAST_PARTICIPLE); } if (phrase.getFeatureAsBoolean(Feature.PROGRESSIVE.ToString())) { frontVG = addBe(frontVG, vgComponents, Form.PRESENT_PARTICIPLE); } if (phrase.getFeatureAsBoolean(Feature.PERFECT.ToString()) || modalPast) { frontVG = addHave(frontVG, vgComponents, modal, tenseValue); } frontVG = pushIfModal(actualModal != null, phrase, frontVG, vgComponents); frontVG = createNot(phrase, vgComponents, frontVG, modal != null); if (frontVG != null) { pushFrontVerb(phrase, vgComponents, frontVG, formValue, interrogative); } pushModal(actualModal, phrase, vgComponents); return(vgComponents); }