/** * 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>. */ static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase) { ListElement realisedElement = null; if (phrase != null && !phrase.getFeatureAsBoolean(Feature.ELIDED).booleanValue()) { realisedElement = new ListElement(); if (phrase.getFeatureAsBoolean(Feature.PRONOMINAL).booleanValue()) { 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), 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) { List<NLGElement> preModifiers = phrase.getPreModifiers(); if (phrase.getFeatureAsBoolean(Feature.ADJECTIVE_ORDERING).booleanValue()) { preModifiers = sortNPPreModifiers(preModifiers); } PhraseHelper.realiseList(parent, realisedElement, preModifiers, DiscourseFunction.PRE_MODIFIER); }
/** * Realises a phrase element. * * @param phrase the element to be realised * @return the realised element. */ private NLGElement realisePhraseElement(PhraseElement phrase) { NLGElement realisedElement = null; if (phrase != null) { ElementCategory category = phrase.getCategory(); if (category instanceof PhraseCategory) { switch ((PhraseCategory) category) { case CLAUSE: realisedElement = ClauseHelper.realise(this, phrase); break; case NOUN_PHRASE: realisedElement = NounPhraseHelper.realise(this, phrase); break; case VERB_PHRASE: realisedElement = VerbPhraseHelper.realise(this, phrase); break; case PREPOSITIONAL_PHRASE: case ADJECTIVE_PHRASE: case ADVERB_PHRASE: realisedElement = PhraseHelper.realise(this, phrase); break; default: realisedElement = phrase; break; } } } return realisedElement; }
/** * 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) { NLGElement specifierElement = phrase.getFeatureAsElement(InternalFeature.SPECIFIER); if (specifierElement != null && !phrase.getFeatureAsBoolean(InternalFeature.RAISED).booleanValue() && !phrase.getFeatureAsBoolean(Feature.ELIDED).booleanValue()) { if (!specifierElement.isA(LexicalCategory.PRONOUN)) { specifierElement.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER)); } NLGElement currentElement = parent.realise(specifierElement); if (currentElement != null) { currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SPECIFIER); 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) { NLGElement headElement = phrase.getHead(); if (headElement != null) { headElement.setFeature(Feature.ELIDED, phrase.getFeature(Feature.ELIDED)); headElement.setFeature(LexicalFeature.GENDER, phrase.getFeature(LexicalFeature.GENDER)); headElement.setFeature(InternalFeature.ACRONYM, phrase.getFeature(InternalFeature.ACRONYM)); headElement.setFeature(Feature.NUMBER, phrase.getFeature(Feature.NUMBER)); headElement.setFeature(Feature.PERSON, phrase.getFeature(Feature.PERSON)); headElement.setFeature(Feature.POSSESSIVE, phrase.getFeature(Feature.POSSESSIVE)); headElement.setFeature(Feature.PASSIVE, phrase.getFeature(Feature.PASSIVE)); NLGElement currentElement = parent.realise(headElement); currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, DiscourseFunction.SUBJECT); realisedElement.addComponent(currentElement); } }
/** * 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.getFactory(); 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, LexicalCategory.PRONOUN); if (proElement instanceof 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; }