/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Realises a phrase element. * * @param phrase * the element to be realised * @return the realised element. */ private INLGElement realisePhraseElement(PhraseElement phrase) { //Debug.WriteLine($"realise phrase element {phrase}"); INLGElement realisedElement = null; if (phrase != null) { var category = phrase.getCategory(); realisedElement = phrase; if (category is IPhraseCategory) { switch ((PhraseCategoryEnum)category.enumType) { case PhraseCategoryEnum.CLAUSE: realisedElement = ClauseHelper.realise(this, phrase); break; case PhraseCategoryEnum.NOUN_PHRASE: realisedElement = NounPhraseHelper.realise(this, phrase); break; case PhraseCategoryEnum.VERB_PHRASE: realisedElement = VerbPhraseHelper.realise(this, phrase); break; case PhraseCategoryEnum.PREPOSITIONAL_PHRASE: case PhraseCategoryEnum.ADJECTIVE_PHRASE: case PhraseCategoryEnum.ADVERB_PHRASE: realisedElement = PhraseHelper.realise(this, phrase); break; } } } return(realisedElement); }
/** * The main method for controlling the syntax realisation of clauses. * * @param parent * the parent <code>SyntaxProcessor</code> that called this * method. * @param phrase * the <code>PhraseElement</code> representation of the clause. * @return the <code>NLGElement</code> representing the realised clause. */ public static INLGElement realise(SyntaxProcessor parent, PhraseElement phrase) { ListElement realisedElement = null; var phraseFactory = phrase.getFactory(); INLGElement splitVerb = null; var interrogObj = false; if (phrase != null) { realisedElement = new ListElement(); var verbElement = phrase.getFeatureAsElement(InternalFeature.VERB_PHRASE.ToString()); if (verbElement == null) { verbElement = phrase.getHead(); } checkSubjectNumberPerson(phrase, verbElement); checkDiscourseFunction(phrase); copyFrontModifiers(phrase, verbElement); addComplementiser(phrase, parent, realisedElement); addCuePhrase(phrase, parent, realisedElement); if (phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString())) { var inter = phrase.getFeature(Feature.INTERROGATIVE_TYPE.ToString()); interrogObj = (InterrogativeType.WHAT_OBJECT.Equals(inter) || InterrogativeType.WHO_OBJECT.Equals(inter) || InterrogativeType.HOW_PREDICATE.Equals(inter) || InterrogativeType.HOW.Equals(inter) || InterrogativeType.WHY.Equals(inter) || InterrogativeType.WHERE.Equals(inter)); splitVerb = realiseInterrogative(phrase, parent, realisedElement, phraseFactory, verbElement); } else { PhraseHelper.realiseList(parent, realisedElement, phrase.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS.ToString()), DiscourseFunction.FRONT_MODIFIER); } addSubjectsToFront(phrase, parent, realisedElement, splitVerb); var passiveSplitVerb = addPassiveComplementsNumberPerson(phrase, parent, realisedElement, verbElement); if (passiveSplitVerb != null) { splitVerb = passiveSplitVerb; } // realise verb needs to know if clause is object interrogative realiseVerb(phrase, parent, realisedElement, splitVerb, verbElement, interrogObj); addPassiveSubjects(phrase, parent, realisedElement, phraseFactory); addInterrogativeFrontModifiers(phrase, parent, realisedElement); addEndingTo(phrase, parent, realisedElement, phraseFactory); } return(realisedElement); }
/** * 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>. */ public static INLGElement realise(SyntaxProcessor parent, CoordinatedPhraseElement phrase) { ListElement realisedElement = null; if (phrase != null) { realisedElement = new ListElement(); PhraseHelper.realiseList(parent, realisedElement, phrase .getPreModifiers(), DiscourseFunction.PRE_MODIFIER); var coordinated = new CoordinatedPhraseElement(); List <INLGElement> children = phrase.getChildren(); var conjunction = phrase.getFeatureAsString(Feature.CONJUNCTION.ToString()); coordinated.setFeature(Feature.CONJUNCTION.ToString(), conjunction); coordinated.setFeature(Feature.CONJUNCTION_TYPE.ToString(), phrase .getFeature(Feature.CONJUNCTION_TYPE.ToString())); InflectedWordElement conjunctionElement = null; if (children != null && children.size() > 0) { if (phrase.getFeatureAsBoolean(Feature.RAISE_SPECIFIER.ToString()) ) { raiseSpecifier(children); } var child = phrase.getLastCoordinate(); if (child is SPhraseSpec) { ((SPhraseSpec)child).setFeature(Feature.POSSESSIVE.ToString(), phrase .getFeature(Feature.POSSESSIVE.ToString())); } else { child.setFeature(Feature.POSSESSIVE.ToString(), phrase .getFeature(Feature.POSSESSIVE.ToString())); } child = children.get(0); setChildFeatures(phrase, child); coordinated.addCoordinate(parent.realise(child)); for (var index = 1; index < children.size(); index++) { child = children.get(index); setChildFeatures(phrase, child); if (child is SPhraseSpec) { if (phrase.getFeatureAsBoolean(Feature.AGGREGATE_AUXILIARY.ToString()) ) { ((SPhraseSpec)child).setFeature(InternalFeature.REALISE_AUXILIARY.ToString(), false); } } else { if (phrase.getFeatureAsBoolean(Feature.AGGREGATE_AUXILIARY.ToString()) ) { child.setFeature(InternalFeature.REALISE_AUXILIARY.ToString(), false); } } if (child.isA(PhraseCategoryEnum.CLAUSE)) { ((SPhraseSpec)child) .setFeature( Feature.SUPRESSED_COMPLEMENTISER.ToString(), phrase .getFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString())); } //skip conjunction if it's null or empty string if (conjunction != null && conjunction.length() > 0) { conjunctionElement = new InflectedWordElement( conjunction, new LexicalCategory_CONJUNCTION()); conjunctionElement.setFeature( InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.CONJUNCTION); coordinated.addCoordinate(conjunctionElement); } coordinated.addCoordinate(parent.realise(child)); } realisedElement.addComponent(coordinated); } PhraseHelper.realiseList(parent, realisedElement, phrase .getPostModifiers(), DiscourseFunction.POST_MODIFIER); PhraseHelper.realiseList(parent, realisedElement, phrase .getComplements(), DiscourseFunction.COMPLEMENT); } return(realisedElement); }