Exemplo n.º 1
0
        /**
         * Determines the minimim position at which this modifier can occur.
         *
         * @param modifier
         *            the modifier to be checked.
         * @return the minimum position for this modifier.
         */
        private static int getMinPos(NLGElement modifier)
        {
            int position = QUALITATIVE_POSITION;

            if (modifier.isA(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)) || modifier.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)))
            {
                position = NOUN_POSITION;
            }
            else if (modifier.isA(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE)) || modifier.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.ADJECTIVE_PHRASE)))
            {
                WordElement adjective = getHeadWordElement(modifier);

                if (adjective.getFeatureAsBoolean(LexicalFeature.QUALITATIVE))
                {
                    position = QUALITATIVE_POSITION;
                }
                else if (adjective.getFeatureAsBoolean(LexicalFeature.COLOUR))
                {
                    position = COLOUR_POSITION;
                }
                else if (adjective.getFeatureAsBoolean(LexicalFeature.CLASSIFYING))
                {
                    position = CLASSIFYING_POSITION;
                }
            }
            return(position);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public virtual void testPronounArguments()
        {
            // the subject of s2 should have been cast into a pronominal NP
            NLGElement subj = s2.getFeatureAsElementList(InternalFeature.SUBJECTS)[0];

            Assert.IsTrue(subj.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)));
            // Assert.assertTrue(LexicalCategory.PRONOUN.equals(((PhraseElement) subj).getCategory()));
        }
Exemplo n.º 4
0
        /**
         * Determines if the given phrase has an expletive as a subject.
         *
         * @param phrase
         *            the <code>PhraseElement</code> to be examined.
         * @return <code>true</code> if the phrase has an expletive subject.
         */
        public static bool isExpletiveSubject(PhraseElement phrase)
        {
            IList <NLGElement> subjects = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS);
            bool expletive = false;

            if (subjects.Count == 1)
            {
                NLGElement subjectNP = subjects[0];

                if (subjectNP.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)))
                {
                    expletive = subjectNP.getFeatureAsBoolean(LexicalFeature.EXPLETIVE_SUBJECT);
                }
                else if (subjectNP.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.CANNED_TEXT)))
                {
                    expletive = "there".Equals(subjectNP.Realisation, StringComparison.OrdinalIgnoreCase);                     //$NON-NLS-1$
                }
            }
            return(expletive);
        }
Exemplo n.º 5
0
        /**
         * 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) && !phrase.getFeatureAsBoolean(Feature.ELIDED))
            {
                if (!specifierElement.isA(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PRONOUN)) && specifierElement.Category != PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)
                {
                    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);
                }
            }
        }
Exemplo n.º 6
0
        /**
         * Checks to see if any of the complements to the phrase are plural.
         *
         * @param complements
         *            the list of complements of the phrase.
         * @return <code>true</code> if any of the complements are plural.
         */
        private static bool hasPluralComplement(IList <NLGElement> complements)
        {
            bool plural = false;
            IEnumerator <NLGElement> complementIterator = complements.GetEnumerator();
            NLGElement eachComplement = null;
            object     numberValue    = null;

            while (complementIterator.MoveNext() && !plural)
            {
                eachComplement = complementIterator.Current;

                if (eachComplement != null && eachComplement.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)))
                {
                    numberValue = eachComplement.getFeature(Feature.NUMBER);
                    if (numberValue != null && NumberAgreement.PLURAL.Equals(numberValue))
                    {
                        plural = true;
                    }
                }
            }
            return(plural);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        /**
         * Checks the subjects of the phrase to determine if there is more than one
         * subject. This ensures that the verb phrase is correctly set. Also set
         * person correctly
         *
         * @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 checkSubjectNumberPerson(PhraseElement phrase, NLGElement verbElement)
        {
            NLGElement         currentElement = null;
            IList <NLGElement> subjects       = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS);
            bool   pluralSubjects             = false;
            Person?person = null;

            if (subjects != null)
            {
                switch (subjects.Count)
                {
                case 0:
                    break;

                case 1:
                    currentElement = subjects[0];
                    // coordinated NP with "and" are plural (not coordinated NP with "or")
                    if (currentElement is CoordinatedPhraseElement && ((CoordinatedPhraseElement)currentElement).checkIfPlural())
                    {
                        pluralSubjects = true;
                    }
                    else if (((NumberAgreement?)currentElement.getFeature(Feature.NUMBER) == NumberAgreement.PLURAL) && !(currentElement is SPhraseSpec))                     // ER mod-
                    {
                        // ER mod-clauses are singular as NPs, even if they are plural internally
                        pluralSubjects = true;
                    }
                    else if (currentElement.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE)))
                    {
                        NLGElement currentHead = currentElement.getFeatureAsElement(InternalFeature.HEAD);
                        person = (Person?)currentElement.getFeature(Feature.PERSON);

                        if (currentHead == null)
                        {
                            // subject is null and therefore is not gonna be plural
                            pluralSubjects = false;
                        }
                        else if ((NumberAgreement?)currentHead.getFeature(Feature.NUMBER) == NumberAgreement.PLURAL)
                        {
                            pluralSubjects = true;
                        }
                        else if (currentHead is ListElement)
                        {
                            pluralSubjects = true;

                            /*
                             * } else if (currentElement instanceof
                             * CoordinatedPhraseElement &&
                             * "and".equals(currentElement.getFeatureAsString(
                             * //$NON-NLS-1$ Feature.CONJUNCTION))) { pluralSubjects
                             * = true;
                             */
                        }
                    }
                    break;

                default:
                    pluralSubjects = true;
                    break;
                }
            }
            if (verbElement != null)
            {
                verbElement.setFeature(Feature.NUMBER, pluralSubjects ? NumberAgreement.PLURAL : (NumberAgreement?)phrase.getFeature(Feature.NUMBER));
                if (person != null)
                {
                    verbElement.setFeature(Feature.PERSON, person);
                }
            }
        }