/** * 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 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); } } }
/** * Checks the discourse function of the clause and alters the form of the * clause as necessary. The following algorithm is used: <br> * * <pre> * If the clause represents a direct or indirect object then * If form is currently Imperative then * Set form to Infinitive * Suppress the complementiser * If form is currently Gerund and there are no subjects * Suppress the complementiser * If the clause represents a subject then * Set the form to be Gerund * Suppress the complementiser * </pre> * * @param phrase * the <code>PhraseElement</code> representing this clause. */ private static void checkDiscourseFunction(PhraseElement phrase) { List <INLGElement> subjects = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS.ToString()); var clauseForm = phrase.getFeature(Feature.FORM.ToString()); var discourseValue = phrase.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()); if (DiscourseFunction.OBJECT.Equals(discourseValue) || DiscourseFunction.INDIRECT_OBJECT.Equals(discourseValue)) { if (Form.IMPERATIVE.Equals(clauseForm)) { phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true); phrase.setFeature(Feature.FORM.ToString(), Form.INFINITIVE.ToString()); } else if (Form.GERUND.Equals(clauseForm) && subjects.Count == 0) { phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true); } } else if (DiscourseFunction.SUBJECT.Equals(discourseValue)) { phrase.setFeature(Feature.FORM.ToString(), Form.GERUND); phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true); } }
/** * Ensures that the verb inherits the features from the clause. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param verbElement * the <code>NLGElement</code> representing the verb phrase for * this clause. */ private static void setVerbFeatures(PhraseElement phrase, INLGElement verbElement) { // this routine copies features from the clause to the VP. // it is disabled, as this copying is now done automatically // when features are set in SPhraseSpec // if (verbElement != null) { // verbElement.setFeature(Feature.INTERROGATIVE_TYPE, phrase // .getFeature(Feature.INTERROGATIVE_TYPE)); // verbElement.setFeature(InternalFeature.COMPLEMENTS, phrase // .getFeature(InternalFeature.COMPLEMENTS)); // verbElement.setFeature(InternalFeature.PREMODIFIERS, phrase // .getFeature(InternalFeature.PREMODIFIERS)); // verbElement.setFeature(Feature.FORM, phrase // .getFeature(Feature.FORM)); // verbElement.setFeature(Feature.MODAL, phrase // .getFeature(Feature.MODAL)); // verbElement.setNegated(phrase.isNegated()); // verbElement.setFeature(Feature.PASSIVE, phrase // .getFeature(Feature.PASSIVE)); // verbElement.setFeature(Feature.PERFECT, phrase // .getFeature(Feature.PERFECT)); // verbElement.setFeature(Feature.PROGRESSIVE, phrase // .getFeature(Feature.PROGRESSIVE)); // verbElement.setTense(phrase.getTense()); // verbElement.setFeature(Feature.FORM, phrase // .getFeature(Feature.FORM)); // verbElement.setFeature(LexicalFeature.GENDER, phrase // .getFeature(LexicalFeature.GENDER)); // } }
/** Sets the object of a PP * * @param object */ public void setObject(object objectg) { PhraseElement objectPhrase = getFactory().createNounPhrase(objectg); objectPhrase.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.OBJECT); addComplement(objectPhrase); }
/** * 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); }
/** * 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 INLGElement grabHeadVerb(PhraseElement phrase, Tense tenseValue, bool hasModal) { INLGElement frontVG = phrase.getHead(); if (frontVG != null) { if (frontVG is WordElement) { frontVG = new InflectedWordElement((WordElement)frontVG); } frontVG.setFeature(Feature.TENSE.ToString(), tenseValue); // if (Tense.FUTURE.Equals(tenseValue) && frontVG != null) { // frontVG.setFeature(Feature.TENSE, Tense.FUTURE); // } if (hasModal) { frontVG.setFeature(Feature.NEGATED.ToString(), false); } } return(frontVG); }
/** * Realises the complements of the phrase adding <em>and</em> where * appropriate. * * @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 firstProcessed = false; INLGElement currentElement = null; foreach (INLGElement complement in phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString())) { currentElement = parent.realise(complement); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.COMPLEMENT); if (firstProcessed) { realisedElement.addComponent(new InflectedWordElement( "and", new LexicalCategory_CONJUNCTION())); } else { firstProcessed = true; } realisedElement.addComponent(currentElement); } } }
/** * Realises the cue phrase for the clause if it exists. * * @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 addCuePhrase(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement) { var currentElement = parent.realise(phrase.getFeatureAsElement(Feature.CUE_PHRASE.ToString())); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.CUE_PHRASE); realisedElement.addComponent(currentElement); } }
/** * Pushes the modal onto the stack of verb components. * * @param actualModal * the modal to be used. * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param vgComponents * the stack of verb components in the verb group. */ private static void pushModal(string actualModal, PhraseElement phrase, Stack <INLGElement> vgComponents) { if (actualModal != null && !phrase.getFeatureAsBoolean(InternalFeature.IGNORE_MODAL.ToString()) ) { vgComponents.push(new InflectedWordElement(actualModal, new LexicalCategory_MODAL())); } }
/** * 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)); } }
/** * Copies the front modifiers of the clause to the list of post-modifiers of * the verb only if the phrase has infinitive form. * * @param phrase * the <code>PhraseElement</code> representing this clause. * @param verbElement * the <code>NLGElement</code> representing the verb phrase for * this clause. */ private static void copyFrontModifiers(PhraseElement phrase, INLGElement verbElement) { var frontModifiers = phrase.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS.ToString()); var clauseForm = phrase.getFeature(Feature.FORM.ToString()); // bug fix by Chris Howell (Agfa) -- do not overwrite existing post-mods // in the VP if (verbElement != null) { List <INLGElement> phrasePostModifiers = phrase.getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString()); if (verbElement is PhraseElement) { List <INLGElement> verbPostModifiers = verbElement.getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString()); foreach (var eachModifier in phrasePostModifiers) { // need to check that VP doesn't already contain the // post-modifier // this only happens if the phrase has already been realised // and later modified, with realiser called again. In that // case, postmods will be copied over twice if (!verbPostModifiers.Contains(eachModifier)) { ((PhraseElement)verbElement).addPostModifier(eachModifier); } } } } // if (verbElement != null) { // verbElement.setFeature(InternalFeature.POSTMODIFIERS, phrase // .getFeature(InternalFeature.POSTMODIFIERS)); // } if (Form.INFINITIVE.Equals(clauseForm)) { phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true); foreach (var eachModifier in frontModifiers) { if (verbElement is PhraseElement) { ((PhraseElement)verbElement).addPostModifier(eachModifier); } } phrase.removeFeature(InternalFeature.FRONT_MODIFIERS.ToString()); if (verbElement != null) { verbElement.setFeature(InternalFeature.NON_MORPH.ToString(), true); } } }
/** * 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 a <em>do</em> verb to the realisation of this 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 addDoAuxiliary(PhraseElement phrase, SyntaxProcessor parent, NLGFactory phraseFactory, ListElement realisedElement) { PhraseElement doPhrase = phraseFactory.createVerbPhrase("do"); doPhrase.setFeature(Feature.TENSE.ToString(), phrase.getFeatureTense(Feature.TENSE.ToString())); doPhrase.setFeature(Feature.PERSON.ToString(), phrase.getFeature(Feature.PERSON.ToString())); doPhrase.setFeature(Feature.NUMBER.ToString(), phrase.getFeature(Feature.NUMBER.ToString())); realisedElement.addComponent(parent.realise(doPhrase)); }
/** * Pushes the front verb onto the stack of verb components. * * @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 formValue * the <code>Form</code> of the phrase. * @param interrogative * <code>true</code> if the phrase is interrogative. */ private static void pushFrontVerb(PhraseElement phrase, Stack <INLGElement> vgComponents, INLGElement frontVG, object formValue, bool interrogative) { var interrogType = phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString()); if (Form.GERUND.Equals(formValue)) { frontVG.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE); vgComponents.push(frontVG); } else if (Form.PAST_PARTICIPLE.Equals(formValue)) { frontVG.setFeature(Feature.FORM.ToString(), Form.PAST_PARTICIPLE); vgComponents.push(frontVG); } else if (Form.PRESENT_PARTICIPLE.Equals(formValue)) { frontVG.setFeature(Feature.FORM.ToString(), Form.PRESENT_PARTICIPLE); vgComponents.push(frontVG); } else if ((!(formValue == null || Form.NORMAL.Equals(formValue)) || interrogative) && !isCopular(phrase.getHead()) && vgComponents.isEmpty()) { // AG: fix below: if interrogative, only set non-morph feature in // case it's not WHO_SUBJECT OR WHAT_SUBJECT if (!(InterrogativeType.WHO_SUBJECT.Equals(interrogType) || InterrogativeType.WHAT_SUBJECT .Equals(interrogType))) { frontVG.setFeature(InternalFeature.NON_MORPH.ToString(), true); } vgComponents.push(frontVG); } else { var numToUse = determineNumber(phrase.getParent(), phrase); frontVG.setFeature(Feature.TENSE.ToString(), phrase.getFeatureTense(Feature.TENSE.ToString())); frontVG.setFeature(Feature.PERSON.ToString(), phrase .getFeature(Feature.PERSON.ToString())); frontVG.setFeature(Feature.NUMBER.ToString(), numToUse); //don't push the front VG if it's a negated interrogative WH object question if (!(phrase.getFeatureAsBoolean(Feature.NEGATED.ToString()) && (InterrogativeType.WHO_OBJECT .Equals(interrogType) || InterrogativeType.WHAT_OBJECT .Equals(interrogType)))) { vgComponents.push(frontVG); } } }
/** * 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); }
/** * 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 INLGElement createNot(PhraseElement phrase, Stack <INLGElement> vgComponents, INLGElement frontVG, bool hasModal) { var newFront = frontVG; if (phrase.getFeatureAsBoolean(Feature.NEGATED.ToString())) { var factory = phrase.getFactory(); // 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 var interrType = phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString()); var addDo = !(InterrogativeType.WHAT_OBJECT.Equals(interrType) || InterrogativeType.WHO_OBJECT .Equals(interrType)); if (!vgComponents.empty() || frontVG != null && isCopular(frontVG)) { vgComponents.push(new InflectedWordElement( "not", new LexicalCategory_ADVERB())); } else { if (frontVG != null && !hasModal) { frontVG.setFeature(Feature.NEGATED.ToString(), true); vgComponents.push(frontVG); } vgComponents.push(new InflectedWordElement( "not", new LexicalCategory_ADVERB())); if (addDo) { if (factory != null) { newFront = factory.createInflectedWord("do", new LexicalCategory_VERB()); } else { newFront = new InflectedWordElement( "do", new LexicalCategory_VERB()); } } } } return(newFront); }
/** * 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)); } }
/** * A helper method to set the head feature of the phrase. * * @param phraseElement * the phrase element. * @param headElement * the head element. */ private void setPhraseHead(PhraseElement phraseElement, INLGElement headElement) { if (headElement != null) { if (phraseElement is NPPhraseSpec) { ((NPPhraseSpec)phraseElement).setHead(headElement); } else { phraseElement.setHead(headElement); } headElement.setParent(phraseElement); } }
/** * Checks to see if this clause is a subordinate clause. If it is then the * complementiser is added as a component to the realised element * <b>unless</b> the complementiser has been suppressed. * * @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 addComplementiser(PhraseElement phrase, SyntaxProcessor parent, ListElement realisedElement) { INLGElement currentElement; if (ClauseStatus.SUBORDINATE.Equals(phrase.getFeature(InternalFeature.CLAUSE_STATUS.ToString())) && !phrase.getFeatureAsBoolean(Feature.SUPRESSED_COMPLEMENTISER.ToString())) { currentElement = parent.realise(phrase.getFeatureAsElement(Feature.COMPLEMENTISER.ToString())); if (currentElement != null) { realisedElement.addComponent(currentElement); } } }
/** * 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()); } }
/** * Pushes the front verb on to the stack if the phrase has a modal. * * @param hasModal * the phrase has a modal * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @param frontVG * the first verb in the verb group. * @param vgComponents * the stack of verb components in the verb group. * @return the new element for the front of the group. */ private static INLGElement pushIfModal(bool hasModal, PhraseElement phrase, INLGElement frontVG, Stack <INLGElement> vgComponents) { var newFront = frontVG; if (hasModal && !phrase.getFeatureAsBoolean(InternalFeature.IGNORE_MODAL.ToString()) ) { if (frontVG != null) { frontVG.setFeature(InternalFeature.NON_MORPH.ToString(), true); vgComponents.push(frontVG); } newFront = null; } return(newFront); }
/** * The main method for realising 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) { realisedElement = new ListElement(); realiseList(parent, realisedElement, phrase.getPreModifiers(), DiscourseFunction.PRE_MODIFIER); realiseHead(parent, phrase, realisedElement); realiseComplements(parent, phrase, realisedElement); PhraseHelper.realiseList(parent, realisedElement, phrase .getPostModifiers(), DiscourseFunction.POST_MODIFIER); } return(realisedElement); }
/** * 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); }
/** * Determines the number agreement for the phrase ensuring that any number * agreement on the parent element is inherited by the phrase. * * @param parent * the parent element of the phrase. * @param phrase * the <code>PhraseElement</code> representing this noun phrase. * @return the <code>NumberAgreement</code> to be used for the phrase. */ private static NumberAgreement determineNumber(INLGElement parent, PhraseElement phrase) { var numberValue = phrase.getFeature(Feature.NUMBER.ToString()); NumberAgreement number; if (numberValue != null && numberValue is NumberAgreement) { number = (NumberAgreement)numberValue; } else { number = NumberAgreement.SINGULAR; } // Ehud Reiter = modified below to force number from VP for WHAT_SUBJECT // and WHO_SUBJECT interrogatuves if (parent is PhraseElement) { if (parent.isA(PhraseCategoryEnum.CLAUSE) && (PhraseHelper.isExpletiveSubject((PhraseElement)parent) || InterrogativeType.WHO_SUBJECT.Equals(parent .getFeature(Feature.INTERROGATIVE_TYPE.ToString())) || InterrogativeType.WHAT_SUBJECT .Equals(parent .getFeature(Feature.INTERROGATIVE_TYPE.ToString()))) && isCopular(phrase.getHead())) { if (hasPluralComplement(phrase .getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString()))) { number = NumberAgreement.PLURAL; } else { number = NumberAgreement.SINGULAR; } } } return(number); }