コード例 #1
0
        /**
         * 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>.
         */
        internal static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement realisedElement = null;

            if (phrase != null && !phrase.getFeatureAsBoolean(Feature.ELIDED))
            {
                realisedElement = new ListElement();

                if (phrase.getFeatureAsBoolean(Feature.PRONOMINAL))
                {
                    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.PostModifiers, DiscourseFunction.POST_MODIFIER);
                }
            }

            return(realisedElement);
        }
コード例 #2
0
        /**
         * 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)
        {
            IList <NLGElement> preModifiers = phrase.PreModifiers;

            if (phrase.getFeatureAsBoolean(Feature.ADJECTIVE_ORDERING))
            {
                preModifiers = sortNPPreModifiers(preModifiers);
            }
            PhraseHelper.realiseList(parent, realisedElement, preModifiers, DiscourseFunction.PRE_MODIFIER);
        }
コード例 #3
0
        /**
         * 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.
         */
        internal static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement realisedElement = null;
            NLGFactory  phraseFactory   = phrase.Factory;
            NLGElement  splitVerb       = null;
            bool        interrogObj     = false;

            if (phrase != null)
            {
                realisedElement = new ListElement();
                NLGElement verbElement = phrase.getFeatureAsElement(InternalFeature.VERB_PHRASE);

                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))
                {
                    object inter = phrase.getFeature(Feature.INTERROGATIVE_TYPE);
                    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), DiscourseFunction.FRONT_MODIFIER);
                }

                addSubjectsToFront(phrase, parent, realisedElement, splitVerb);

                NLGElement 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);
        }
コード例 #4
0
        /**
         * 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.Category;

                if (category is PhraseCategory)
                {
                    switch (((PhraseCategory)category).GetPhraseCategory())
                    {
                    case PhraseCategory.PhraseCategoryEnum.CLAUSE:
                        realisedElement = ClauseHelper.realise(this, phrase);
                        break;

                    case PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE:
                        realisedElement = NounPhraseHelper.realise(this, phrase);
                        break;

                    case PhraseCategory.PhraseCategoryEnum.VERB_PHRASE:
                        realisedElement = VerbPhraseHelper.realise(this, phrase);
                        break;

                    case PhraseCategory.PhraseCategoryEnum.PREPOSITIONAL_PHRASE:
                    case PhraseCategory.PhraseCategoryEnum.ADJECTIVE_PHRASE:
                    case PhraseCategory.PhraseCategoryEnum.ADVERB_PHRASE:
                        realisedElement = PhraseHelper.realise(this, phrase);
                        break;

                    default:
                        realisedElement = phrase;
                        break;
                    }
                }
            }

            return(realisedElement);
        }
コード例 #5
0
        /**
         * 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>.
         */
        internal static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase)
        {
            ListElement        realisedElement      = null;
            Stack <NLGElement> vgComponents         = null;
            Stack <NLGElement> mainVerbRealisation  = new Stack <NLGElement>();
            Stack <NLGElement> auxiliaryRealisation = new Stack <NLGElement>();

            if (phrase != null)
            {
                vgComponents = createVerbGroup(parent, phrase);
                splitVerbGroup(vgComponents, mainVerbRealisation, auxiliaryRealisation);

                realisedElement = new ListElement();

                if (!phrase.hasFeature(InternalFeature.REALISE_AUXILIARY) || phrase.getFeatureAsBoolean(InternalFeature.REALISE_AUXILIARY))
                {
                    realiseAuxiliaries(parent, realisedElement, auxiliaryRealisation);

                    PhraseHelper.realiseList(parent, realisedElement, phrase.PreModifiers, DiscourseFunction.PRE_MODIFIER);

                    realiseMainVerb(parent, phrase, mainVerbRealisation, realisedElement);
                }
                else if (isCopular(phrase.getHead()))
                {
                    realiseMainVerb(parent, phrase, mainVerbRealisation, realisedElement);
                    PhraseHelper.realiseList(parent, realisedElement, phrase.PreModifiers, DiscourseFunction.PRE_MODIFIER);
                }
                else
                {
                    PhraseHelper.realiseList(parent, realisedElement, phrase.PreModifiers, DiscourseFunction.PRE_MODIFIER);
                    realiseMainVerb(parent, phrase, mainVerbRealisation, realisedElement);
                }
                realiseComplements(parent, phrase, realisedElement);
                PhraseHelper.realiseList(parent, realisedElement, phrase.PostModifiers, DiscourseFunction.POST_MODIFIER);
            }

            return(realisedElement);
        }
コード例 #6
0
        /**
         * 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);
        }
コード例 #7
0
        /**
         * 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(NLGElement parent, PhraseElement phrase)
        {
            object          numberValue = phrase.getFeature(Feature.NUMBER);
            NumberAgreement?number      = null;

            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(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.CLAUSE)) && (PhraseHelper.isExpletiveSubject((PhraseElement)parent) || InterrogativeType.WHO_SUBJECT.Equals(parent.getFeature(Feature.INTERROGATIVE_TYPE)) || InterrogativeType.WHAT_SUBJECT.Equals(parent.getFeature(Feature.INTERROGATIVE_TYPE))) && isCopular(phrase.getHead()))
                {
                    if (hasPluralComplement(phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS)))
                    {
                        number = NumberAgreement.PLURAL;
                    }
                    else
                    {
                        number = NumberAgreement.SINGULAR;
                    }
                }
            }
            return(number);
        }