Ejemplo n.º 1
0
        /**
         * This method performs the morphology for determiners.
         *
         * @param determiner
         *            the <code>InflectedWordElement</code>.
         * @param realisation
         *            the current realisation of the determiner.
         */
        public static void doDeterminerMorphology(NLGElement determiner, string realisation)
        {
            if (!ReferenceEquals(realisation, null))
            {
                if (!(determiner.Realisation.Equals("a")))
                {
                    if (determiner.Plural)
                    {
                        // Use default inflection rules:
                        if ("that".Equals(determiner.Realisation))
                        {
                            determiner.Realisation = "those";
                        }
                        else if ("this".Equals(determiner.Realisation))
                        {
                            determiner.Realisation = "these";
                        }
                    }
                    else if (!determiner.Plural)
                    {
                        // Use default push back to base form rules:
                        if ("those".Equals(determiner.Realisation))
                        {
                            determiner.Realisation = "that";
                        }
                        else if ("these".Equals(determiner.Realisation))
                        {
                            determiner.Realisation = "this";
                        }
                    }
                }

                // Special "a" determiner and perform a/an agreement:
                if (determiner.Realisation.Equals("a"))
                {                 //$NON-NLS-1$
                    if (determiner.Plural)
                    {
                        determiner.Realisation = "some";
                    }
                    else if (DeterminerAgrHelper.requiresAn(realisation))
                    {
                        determiner.Realisation = "an";
                    }
                }
            }
        }
        public override IList <NLGElement> realise(IList <NLGElement> elements)
        {
            IList <NLGElement> realisedElements = new List <NLGElement>();
            NLGElement         currentElement   = null;
            NLGElement         determiner       = null;
            NLGElement         prevElement      = null;

            if (elements != null)
            {
                foreach (NLGElement eachElement in elements)
                {
                    currentElement = realise(eachElement);

                    if (currentElement != null)
                    {
                        //pass the discourse function and appositive features -- important for orth processor
                        currentElement.setFeature(Feature.APPOSITIVE, eachElement.getFeature(Feature.APPOSITIVE));
                        object function = eachElement.getFeature(InternalFeature.DISCOURSE_FUNCTION);

                        if (function != null)
                        {
                            currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, function);
                        }

                        if (prevElement != null && prevElement is StringElement && eachElement is InflectedWordElement && ((InflectedWordElement)eachElement).Category == LexicalCategory.LexicalCategoryEnum.NOUN)
                        {
                            string prevString = prevElement.Realisation;

                            //realisedElements.get(realisedElements.size() - 1)

                            prevElement.Realisation = DeterminerAgrHelper.checkEndsWithIndefiniteArticle(prevString, currentElement.Realisation);
                        }

                        // realisedElements.add(realise(currentElement));
                        realisedElements.Add(currentElement);

                        if (determiner == null && DiscourseFunction.SPECIFIER.Equals(currentElement.getFeature(InternalFeature.DISCOURSE_FUNCTION)))
                        {
                            determiner = currentElement;
                            determiner.setFeature(Feature.NUMBER, eachElement.getFeature(Feature.NUMBER));
                            // MorphologyRules.doDeterminerMorphology(determiner,
                            // currentElement.getRealisation());
                        }
                        else if (determiner != null)
                        {
                            if (currentElement is ListElement)
                            {
                                // list elements: ensure det matches first element
                                NLGElement firstChild = ((ListElement)currentElement).Children[0];

                                if (firstChild != null)
                                {
                                    //AG: need to check if child is a coordinate
                                    if (firstChild is CoordinatedPhraseElement)
                                    {
                                        MorphologyRules.doDeterminerMorphology(determiner, firstChild.Children[0].Realisation);
                                    }
                                    else
                                    {
                                        MorphologyRules.doDeterminerMorphology(determiner, firstChild.Realisation);
                                    }
                                }
                            }
                            else
                            {
                                // everything else: ensure det matches realisation
                                MorphologyRules.doDeterminerMorphology(determiner, currentElement.Realisation);
                            }

                            determiner = null;
                        }
                    }
                    prevElement = eachElement;
                }
            }

            return(realisedElements);
        }