Esempio n. 1
0
        /**
         * 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 INLGElement createPronoun(SyntaxProcessor parent,
                                                 PhraseElement phrase)
        {
            var pronoun       = "it";
            var phraseFactory = phrase.getFactory();
            var personValue   = phrase.getFeature(Feature.PERSON.ToString());

            if (Person.FIRST.Equals(personValue))
            {
                pronoun = "I";
            }
            else if (Person.SECOND.Equals(personValue))
            {
                pronoun = "you";
            }
            else
            {
                var genderValue = phrase.getFeature(LexicalFeature.GENDER);
                if (Gender.FEMININE.Equals(genderValue))
                {
                    pronoun = "she";
                }
                else if (Gender.MASCULINE.Equals(genderValue))
                {
                    pronoun = "he";
                }
            }
            // AG: createWord now returns WordElement; so we embed it in an
            // inflected word element here
            INLGElement element;
            var         proElement = phraseFactory.createWord(pronoun,
                                                              new LexicalCategory_PRONOUN());

            if (proElement is WordElement)
            {
                element = new InflectedWordElement((WordElement)proElement);
                element.setFeature(LexicalFeature.GENDER, ((WordElement)proElement).getFeature(LexicalFeature.GENDER));
                // Ehud - also copy over person
                element.setFeature(Feature.PERSON.ToString(), ((WordElement)proElement).getFeature(Feature.PERSON.ToString()));
            }
            else
            {
                element = proElement;
            }

            element.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                               DiscourseFunction.SPECIFIER);
            element.setFeature(Feature.POSSESSIVE.ToString(), phrase
                               .getFeature(Feature.POSSESSIVE.ToString()));
            element
            .setFeature(Feature.NUMBER.ToString(), phrase.getFeature(Feature.NUMBER.ToString()));


            if (phrase.hasFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()))
            {
                element.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), phrase
                                   .getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
            }

            return(element);
        }
Esempio n. 2
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>.
         */

        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);
        }
Esempio n. 3
0
        public override INLGElement realise(INLGElement element)
        {
            //Debug.WriteLine($"realise single element {element}");
            INLGElement realisedElement = null;

            if (element != null && !element.getFeatureAsBoolean(Feature.ELIDED.ToString()))
            {
                if (element is DocumentElement)
                {
                    List <INLGElement> children = element.getChildren();
                    ((DocumentElement)element).setComponents(realise(children));
                    realisedElement = element;
                }
                else
                if (element is PhraseElement)
                {
                    realisedElement = realisePhraseElement((PhraseElement)element);
                }
                else
                if (element is ListElement)
                {
                    realisedElement = new ListElement();
                    ((ListElement)realisedElement).addComponents(realise(element
                                                                         .getChildren()));
                }
                else
                if (element is InflectedWordElement)
                {
                    var baseForm = ((InflectedWordElement)element).getBaseForm();
                    var category = element.getCategory();

                    if (lexicon != null && baseForm != null)
                    {
                        var word = ((InflectedWordElement)element).getBaseWord();

                        if (word == null)
                        {
                            if (category is ILexicalCategory)
                            {
                                word = this.lexicon.lookupWord(baseForm,
                                                               (ILexicalCategory)category);
                            }
                            else
                            {
                                word = this.lexicon.lookupWord(baseForm);
                            }
                        }

                        if (word != null)
                        {
                            ((InflectedWordElement)element).setBaseWord(word);
                        }
                    }

                    realisedElement = element;
                }
                else
                if (element is WordElement)
                {
                    // AG: need to check if it's a word element, in which case it
                    // needs to be marked for inflection
                    var infl = new InflectedWordElement(
                        (WordElement)element);

                    // // the inflected word inherits all features from the base
                    // word
                    foreach (var feature in element.getAllFeatureNames())
                    {
                        infl.setFeature(feature, element.getFeature(feature));
                    }

                    realisedElement = realise(infl);
                }
                else
                if (element is CoordinatedPhraseElement)
                {
                    realisedElement = CoordinatedPhraseHelper.realise(this,
                                                                      (CoordinatedPhraseElement)element);
                }
                else
                {
                    realisedElement = element;
                }
            }

            // Remove the spurious ListElements that have only one element.
            if (realisedElement is ListElement)
            {
                if (((ListElement)realisedElement).size() == 1)
                {
                    realisedElement = ((ListElement)realisedElement).getFirst();
                }
            }

            return(realisedElement);
        }