Exemplo n.º 1
0
 // get string for head of constituent
 private string getBaseForm(INLGElement constituent)
 {
     if (constituent == null)
     {
         return(null);
     }
     else if (constituent is StringElement)
     {
         return(constituent.getRealisation());
     }
     else if (constituent is WordElement)
     {
         return(((WordElement)constituent).getBaseForm());
     }
     else if (constituent is InflectedWordElement)
     {
         return(getBaseForm(((InflectedWordElement)constituent).getBaseWord()));
     }
     else if (constituent is PhraseElement)
     {
         return(getBaseForm(((PhraseElement)constituent).getHead()));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
        /**
         * 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)
        {
            INLGElement headElement = phrase.getHead();

            if (headElement != null)
            {
                headElement.setFeature(Feature.ELIDED.ToString(), phrase
                                       .getFeature(Feature.ELIDED.ToString()));
                headElement.setFeature(LexicalFeature.GENDER, phrase
                                       .getFeature(LexicalFeature.GENDER));
                headElement.setFeature(InternalFeature.ACRONYM.ToString(), phrase
                                       .getFeature(InternalFeature.ACRONYM.ToString()));
                headElement.setFeature(Feature.NUMBER.ToString(), phrase
                                       .getFeature(Feature.NUMBER.ToString()));
                headElement.setFeature(Feature.PERSON.ToString(), phrase
                                       .getFeature(Feature.PERSON.ToString()));
                headElement.setFeature(Feature.POSSESSIVE.ToString(), phrase
                                       .getFeature(Feature.POSSESSIVE.ToString()));
                headElement.setFeature(Feature.PASSIVE.ToString(), phrase
                                       .getFeature(Feature.PASSIVE.ToString()));
                var currentElement = parent.realise(headElement);
                currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                          DiscourseFunction.SUBJECT);
                realisedElement.addComponent(currentElement);
            }
        }
Exemplo n.º 3
0
        public void correctPluralizationWithPossessives()
        {
            NPPhraseSpec sisterNP = SetupForRealiserTest.phraseFactory.createNounPhrase("sister");
            INLGElement  word     = SetupForRealiserTest.phraseFactory.createInflectedWord("Albert Einstein",
                                                                                           new LexicalCategory_NOUN());

            word.setFeature(LexicalFeature.PROPER, true);
            NPPhraseSpec possNP = SetupForRealiserTest.phraseFactory.createNounPhrase(word);

            possNP.setFeature(Feature.POSSESSIVE.ToString(), true);
            sisterNP.setSpecifier(possNP);


            Assert.AreEqual("Albert Einstein's sister",
                            SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());

            sisterNP.setPlural(true);

            SetupForRealiserTest.realiser.setDebugMode(true);
            Assert.AreEqual("Albert Einstein's sisters",
                            SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());

            sisterNP.setPlural(false);

            possNP.setFeature(LexicalFeature.GENDER, Gender.MASCULINE);
            possNP.setFeature(Feature.PRONOMINAL.ToString(), true);
            Assert.AreEqual("his sister",
                            SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
            sisterNP.setPlural(true);
            Assert.AreEqual("his sisters",
                            SetupForRealiserTest.realiser.realise(sisterNP).getRealisation());
        }
Exemplo n.º 4
0
        /**
         * Determines the maximim position at which this modifier can occur.
         *
         * @param modifier
         *            the modifier to be checked.
         * @return the maximum position for this modifier.
         */

        private static int getMaxPos(INLGElement modifier)
        {
            var position = NOUN_POSITION;

            if (modifier.isA(LexicalCategoryEnum.ADJECTIVE) ||
                modifier.isA(PhraseCategoryEnum.ADJECTIVE_PHRASE))
            {
                var adjective = getHeadWordElement(modifier);

                if (adjective.getFeatureAsBoolean(LexicalFeature.CLASSIFYING)
                    )
                {
                    position = CLASSIFYING_POSITION;
                }
                else if (adjective.getFeatureAsBoolean(LexicalFeature.COLOUR)
                         )
                {
                    position = COLOUR_POSITION;
                }
                else if (adjective
                         .getFeatureAsBoolean(LexicalFeature.QUALITATIVE)
                         )
                {
                    position = QUALITATIVE_POSITION;
                }
                else
                {
                    position = CLASSIFYING_POSITION;
                }
            }
            return(position);
        }
Exemplo n.º 5
0
        /**
         * Creates a new section element with the given title and adds the given
         * component.
         *
         * @param component
         *            an <code>NLGElement</code> that becomes the first component of
         *            this document element.
         * @return a <code>DocumentElement</code> representing the section.
         */

        public DocumentElement createList(INLGElement component)
        {
            var list = new DocumentElement(new DocumentCategory_LIST(), null);

            list.addComponent(component);
            return(list);
        }
Exemplo n.º 6
0
        /**
         * Realises the complements of the phrase adding <em>and</em> where
         * appropriate.
         *
         * @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.
         * @param realisedElement
         *            the current realisation of the noun phrase.
         */

        private static void realiseComplements(SyntaxProcessor parent,
                                               PhraseElement phrase, ListElement realisedElement)
        {
            var         firstProcessed = false;
            INLGElement currentElement = null;

            foreach (INLGElement complement in phrase.getFeatureAsElementList(InternalFeature.COMPLEMENTS.ToString()))
            {
                currentElement = parent.realise(complement);
                if (currentElement != null)
                {
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                              DiscourseFunction.COMPLEMENT);
                    if (firstProcessed)
                    {
                        realisedElement.addComponent(new InflectedWordElement(
                                                         "and", new LexicalCategory_CONJUNCTION()));
                    }
                    else
                    {
                        firstProcessed = true;
                    }
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Exemplo n.º 7
0
        /**
         * <p>
         * Add a single child component to the current list of child components. If
         * there are no existing child components a new list is created.
         * </p>
         * <p>
         * Note that there are restrictions on which child types can be added to
         * which parent types.  Intermediate nodes are added if necessary; eg,
         * if a sentence is added to a document, the sentence will be embedded
         * in a paragraph before it is added
         * See <code>
         * DocumentCategory</code> for further information.
         * </p>
         *
         * @param element
         *            the <code>NLGElement</code> to be added. If this is
         *            <code>NULL</code> the method does nothing.
         */

        public void addComponent(INLGElement element)
        {
            if (element != null)
            {
                var thisCategory = this.getCategory();
                var category     = element.getCategory();
                if (category != null && thisCategory is IDocumentCategory)
                {
                    if (((IDocumentCategory)thisCategory).hasSubPart(category))
                    {
                        addElementToComponents(element);
                    }
                    else
                    {
                        var promotedElement = promote(element);
                        if (promotedElement != null)
                        {
                            addElementToComponents(promotedElement);
                        }
                        else // error condition - add original element so something is visible
                        {
                            addElementToComponents(element);
                        }
                    }
                }
                else
                {
                    addElementToComponents(element);
                }
            }
        }
Exemplo n.º 8
0
        /**
         * Realises a list of elements appending the result to the on-going
         * realisation.
         *
         * @param realisation
         *            the <code>StringBuilder<code> containing the current
         *            realisation of the sentence.
         * @param components
         *            the <code>List</code> of <code>NLGElement</code>s representing
         *            the components that make up the sentence.
         * @param listSeparator
         *            the string to use to separate elements of the list, empty if
         *            no separator needed
         */

        private void realiseList(StringBuilder realisation, List <INLGElement> components, string listSeparator)
        {
            INLGElement realisedChild = null;

            for (var i = 0; i < components.size(); i++)
            {
                var thisElement = components.get(i);
                realisedChild = realise(thisElement);
                var childRealisation = realisedChild.getRealisation();

                // check that the child realisation is non-empty
                if (childRealisation != null && childRealisation.length() > 0 &&
                    !childRealisation.matches(@"^[\s\n]+$"))
                {
                    realisation.append(realisedChild.getRealisation());

                    if (components.size() > 1 && i < components.size() - 1)
                    {
                        realisation.append(listSeparator);
                    }

                    realisation.append(' ');
                }
            }

            if (realisation.length() > 0)
            {
                realisation.setLength(realisation.length() - 1);
            }
        }
Exemplo n.º 9
0
        /**
         * Creates a new section element with the given title and adds the given
         * component.
         *
         * @param component
         *            an <code>NLGElement</code> that becomes the first component of
         *            this document element.
         * @return a <code>DocumentElement</code> representing the section.
         * @author Rodrigo de Oliveira - Data2Text Ltd
         */

        public DocumentElement createEnumeratedList(INLGElement component)
        {
            var list = new DocumentElement(new DocumentCategory_ENUMERATED_LIST(), null);

            list.addComponent(component);
            return(list);
        }
Exemplo n.º 10
0
        /**
         * Realises the subjects of a passive clause.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param phraseFactory
         *            the phrase factory to be used.
         */

        private static void addPassiveSubjects(PhraseElement phrase,
                                               SyntaxProcessor parent,
                                               ListElement realisedElement,
                                               NLGFactory phraseFactory)
        {
            INLGElement currentElement = null;

            if (phrase.getFeatureAsBoolean(Feature.PASSIVE.ToString()))
            {
                var allSubjects = phrase.getFeatureAsElementList(InternalFeature.SUBJECTS.ToString());

                if (allSubjects.size() > 0 || phrase.hasFeature(Feature.INTERROGATIVE_TYPE.ToString()))
                {
                    realisedElement.addComponent(parent.realise(phraseFactory.createPrepositionPhrase("by")));
                }

                foreach (var subject in allSubjects)
                {
                    subject.setFeature(Feature.PASSIVE.ToString(), true);
                    if (subject.isA(PhraseCategoryEnum.NOUN_PHRASE) || subject is CoordinatedPhraseElement)
                    {
                        currentElement = parent.realise(subject);
                        if (currentElement != null)
                        {
                            currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.SUBJECT);
                            realisedElement.addComponent(currentElement);
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        /**
         * Applies backward conjunction reduction to two NLGElements e1 and e2,
         * succeeding only if they are clauses (that is, e1.getCategory() ==
         * e2.getCategory == {@link simplenlg.framework.PhraseCategory#CLAUSE}).
         *
         * @param previous
         *            the first phrase
         * @param next
         *            the second phrase
         * @return a coordinate phrase if aggregation is successful,
         *         <code>null</code> otherwise
         */

        public override INLGElement apply(INLGElement previous, INLGElement next)
        {
            var success = false;

            if (previous.getCategory().enumType == (int)PhraseCategoryEnum.CLAUSE &&
                next.getCategory().enumType == (int)PhraseCategoryEnum.CLAUSE &&
                PhraseChecker.nonePassive(new List <INLGElement> {
                previous, next
            }))
            {
                var rightPeriphery = PhraseChecker.rightPeriphery(new List <INLGElement> {
                    previous, next
                });

                foreach (var pair in rightPeriphery)
                {
                    if (pair.lemmaIdentical())
                    {
                        pair.elideLeftmost();
                        success = true;
                    }
                }
            }

            return(success
            ? factory.createCoordinatedPhrase(previous, next)
            : null);
        }
Exemplo n.º 12
0
        /**
         * Create an inflected word element. InflectedWordElement represents a word
         * that already specifies the morphological and other features that it
         * should exhibit in a realisation. While normally, phrases are constructed
         * using <code>WordElement</code>s, and features are set on phrases, it is
         * sometimes desirable to set features directly on words (for example, when
         * one wants to elide a specific word, but not its parent phrase).
         *
         * <P>
         * If the object passed is already a <code>WordElement</code>, then a new
         *
         * <code>InflectedWordElement<code> is returned which wraps this <code>WordElement</code>
         * . If the object is a <code>string</code>, then the
         * <code>WordElement</code> representing this <code>string</code> is looked
         * up, and a new
         * <code>InflectedWordElement<code> wrapping this is returned. If no such <code>WordElement</code>
         * is found, the element returned is an <code>InflectedWordElement</code>
         * with the supplied string as baseform and no base <code>WordElement</code>
         * . If an <code>NLGElement</code> is passed, this is returned unchanged.
         *
         * @param word
         *            the word
         * @param category
         *            the category
         * @return an <code>InflectedWordElement</code>, or the original supplied
         *         object if it is an <code>NLGElement</code>.
         */

        public INLGElement createInflectedWord(object word, ILexicalCategory category)
        {
            // first get the word element
            INLGElement inflElement = null;

            if (word is WordElement)
            {
                inflElement = new InflectedWordElement((WordElement)word);
            }
            else
            if (word is string)
            {
                var baseword = createWord((string)word, category);

                if (baseword != null && baseword is WordElement)
                {
                    inflElement = new InflectedWordElement((WordElement)baseword);
                }
                else
                {
                    inflElement = new InflectedWordElement((string)word, category);
                }
            }
            else if (word is INLGElement)
            {
                inflElement = (INLGElement)word;
            }

            return(inflElement);
        }
Exemplo n.º 13
0
        /**
         * Creates a list item for adding to a list element. The list item has the
         * given component.
         *
         * @return a <code>DocumentElement</code> representing the list item.
         */

        public DocumentElement createListItem(INLGElement component)
        {
            var listItem = new DocumentElement(new DocumentCategory_LIST_ITEM(), null);

            listItem.addComponent(component);
            return(listItem);
        }
Exemplo n.º 14
0
        /**
         * Creates a new sentence element
         *
         * @param components
         *            an <code>NLGElement</code> that becomes the first component of
         *            this document element.
         * @return a <code>DocumentElement</code> representing this sentence
         */

        public DocumentElement createSentence(INLGElement components)
        {
            var sentence = new DocumentElement(new DocumentCategory_SENTENCE(), null);

            sentence.addComponent(components);
            return(sentence);
        }
Exemplo n.º 15
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)
        {
            INLGElement specifierElement = phrase
                                           .getFeatureAsElement(InternalFeature.SPECIFIER.ToString());

            if (specifierElement != null &&
                !phrase.getFeatureAsBoolean(InternalFeature.RAISED.ToString()) &&
                !phrase.getFeatureAsBoolean(Feature.ELIDED.ToString()))
            {
                if (!specifierElement.isA(LexicalCategoryEnum.PRONOUN) &&
                    specifierElement.getCategory().enumType != (int)PhraseCategoryEnum.NOUN_PHRASE)
                {
                    specifierElement.setFeature(Feature.NUMBER.ToString(), phrase
                                                .getFeature(Feature.NUMBER.ToString()));
                }

                var currentElement = parent.realise(specifierElement);

                if (currentElement != null)
                {
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                              DiscourseFunction.SPECIFIER);
                    realisedElement.addComponent(currentElement);
                }
            }
        }
Exemplo n.º 16
0
        /**
         * Ensures that the verb inherits the features from the clause.
         *
         * @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 setVerbFeatures(PhraseElement phrase, INLGElement verbElement)
        {
            // this routine copies features from the clause to the VP.
            // it is disabled, as this copying is now done automatically
            // when features are set in SPhraseSpec
            // if (verbElement != null) {
            // verbElement.setFeature(Feature.INTERROGATIVE_TYPE, phrase
            // .getFeature(Feature.INTERROGATIVE_TYPE));
            // verbElement.setFeature(InternalFeature.COMPLEMENTS, phrase
            // .getFeature(InternalFeature.COMPLEMENTS));
            // verbElement.setFeature(InternalFeature.PREMODIFIERS, phrase
            // .getFeature(InternalFeature.PREMODIFIERS));
            // verbElement.setFeature(Feature.FORM, phrase
            // .getFeature(Feature.FORM));
            // verbElement.setFeature(Feature.MODAL, phrase
            // .getFeature(Feature.MODAL));
            // verbElement.setNegated(phrase.isNegated());
            // verbElement.setFeature(Feature.PASSIVE, phrase
            // .getFeature(Feature.PASSIVE));
            // verbElement.setFeature(Feature.PERFECT, phrase
            // .getFeature(Feature.PERFECT));
            // verbElement.setFeature(Feature.PROGRESSIVE, phrase
            // .getFeature(Feature.PROGRESSIVE));
            // verbElement.setTense(phrase.getTense());
            // verbElement.setFeature(Feature.FORM, phrase
            // .getFeature(Feature.FORM));
            // verbElement.setFeature(LexicalFeature.GENDER, phrase
            // .getFeature(LexicalFeature.GENDER));
            // }
        }
Exemplo n.º 17
0
        /**
         * Checks to see if the base form of the word is copular, i.e. <em>be</em>.
         *
         * @param element
         *            the element to be checked
         * @return <code>true</code> if the element is copular.
         */

        public static bool isCopular(INLGElement element)
        {
            var copular = false;

            if (element is InflectedWordElement)
            {
                copular = "be".equalsIgnoreCase(((InflectedWordElement)element)
                                                .getBaseForm());
            }
            else if (element is WordElement)
            {
                copular = "be".equalsIgnoreCase(((WordElement)element)
                                                .getBaseForm());
            }
            else if (element is PhraseElement)
            {
                // get the head and check if it's "be"
                INLGElement head = element is SPhraseSpec
                    ? ((SPhraseSpec)element)
                                   .getVerb()
                    : ((PhraseElement)element).getHead();

                if (head != null)
                {
                    copular = (head is WordElement && "be"
                               .Equals(((WordElement)head).getBaseForm()));
                }
            }

            return(copular);
        }
Exemplo n.º 18
0
        /**
         * Grabs the head verb of the verb phrase and sets it to future tense if the
         * phrase is future tense. It also turns off negation if the group has a
         * modal.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this noun phrase.
         * @param tenseValue
         *            the <code>Tense</code> of the phrase.
         * @param hasModal
         *            <code>true</code> if the verb phrase has a modal.
         * @return the modified head element
         */

        private static INLGElement grabHeadVerb(PhraseElement phrase,
                                                Tense tenseValue, bool hasModal)
        {
            INLGElement frontVG = phrase.getHead();

            if (frontVG != null)
            {
                if (frontVG is WordElement)
                {
                    frontVG = new InflectedWordElement((WordElement)frontVG);
                }


                frontVG.setFeature(Feature.TENSE.ToString(), tenseValue);

                // if (Tense.FUTURE.Equals(tenseValue) && frontVG != null) {
                // frontVG.setFeature(Feature.TENSE, Tense.FUTURE);
                // }

                if (hasModal)
                {
                    frontVG.setFeature(Feature.NEGATED.ToString(), false);
                }
            }

            return(frontVG);
        }
Exemplo n.º 19
0
        /** promote an NLGElement so that it is at the right level to be added to a DocumentElement/
         * Promotion means adding surrounding nodes at higher doc levels
         * @param element
         * @return
         */

        private INLGElement promote(INLGElement element)
        {
            // check if promotion needed
            if (((IDocumentCategory)this.getCategory()).hasSubPart(element.getCategory()))
            {
                return(element);
            }
            // if element is not a DocumentElement, embed it in a sentence and recurse
            if (!(element is DocumentElement))
            {
                var sentence = new DocumentElement(new DocumentCategory_SENTENCE(), null);
                sentence.addElementToComponents(element);
                return(promote(sentence));
            }

            // if element is a Sentence, promote it to a paragraph
            if (!(element is IDocumentCategory))
            {
                if (element.getCategory().enumType == (int)DocumentCategoryEnum.SENTENCE)
                {
                    var paragraph = new DocumentElement(new DocumentCategory_PARAGRAPH(), null);
                    paragraph.addElementToComponents(element);
                    return(promote(paragraph));
                }
            }
            // otherwise can't do anything
            return(null);
        }
Exemplo n.º 20
0
        /** add an element to a components list
         * @param element
         */

        private void addElementToComponents(INLGElement element)
        {
            var components = getComponents();

            components.Add(element);
            element.setParent(this);
            setComponents(components);
        }
Exemplo n.º 21
0
        public override INLGElement realise(INLGElement element)
        {
            INLGElement realisedElement = null;

            if (element is InflectedWordElement)
            {
                realisedElement = doMorphology((InflectedWordElement)element);
            }
            else if (element is StringElement)
            {
                realisedElement = element;
            }
            else if (element is WordElement)
            {
                // AG: now retrieves the default spelling variant, not the baseform
                // string baseForm = ((WordElement) element).getBaseForm();
                var defaultSpell = ((WordElement)element).getDefaultSpellingVariant();

                if (defaultSpell != null)
                {
                    realisedElement = new StringElement(defaultSpell);
                }
            }
            else if (element is DocumentElement)
            {
                List <INLGElement> children = element.getChildren();
                ((DocumentElement)element).setComponents(realise(children));
                realisedElement = element;
            }
            else if (element is ListElement)
            {
                realisedElement = new ListElement();
                ((ListElement)realisedElement).addComponents(realise(element.getChildren()));
            }
            else if (element is CoordinatedPhraseElement)
            {
                List <INLGElement> children = element.getChildren();
                ((CoordinatedPhraseElement)element).clearCoordinates();

                if (children != null && children.size() > 0)
                {
                    ((CoordinatedPhraseElement)element).addCoordinate(realise(children.get(0)));

                    for (var index = 1; index < children.size(); index++)
                    {
                        ((CoordinatedPhraseElement)element).addCoordinate(realise(children.get(index)));
                    }

                    realisedElement = element;
                }
            }
            else if (element != null)
            {
                realisedElement = element;
            }

            return(realisedElement);
        }
Exemplo n.º 22
0
        // note that addFrontModifier, addPostModifier, addPreModifier are inherited from PhraseElement
        // likewise getFrontModifiers, getPostModifiers, getPreModifiers


        /** Add a modifier to a verb phrase
         * Use heuristics to decide where it goes
         * @param modifier
         */

        public override void addModifier(object modifier)
        {
            // adverb is preModifier
            // string which is one lexicographic word is looked up in lexicon,
            // if it is an adverb than it becomes a preModifier
            // Everything else is postModifier

            if (modifier == null)
            {
                return;
            }

            // get modifier as NLGElement if possible
            INLGElement modifierElement = null;

            if (modifier is INLGElement)
            {
                modifierElement = (INLGElement)modifier;
            }
            else if (modifier is string)
            {
                var modifierString = (string)modifier;
                if (modifierString.length() > 0 && !modifierString.contains(" "))
                {
                    modifierElement = getFactory().createWord(modifier, new LexicalCategory_ANY());
                }
            }

            // if no modifier element, must be a complex string
            if (modifierElement == null)
            {
                addPostModifier((string)modifier);
                return;
            }

            // extract WordElement if modifier is a single word
            WordElement modifierWord = null;

            if (modifierElement != null && modifierElement is WordElement)
            {
                modifierWord = (WordElement)modifierElement;
            }
            else if (modifierElement != null && modifierElement is InflectedWordElement)
            {
                modifierWord = ((InflectedWordElement)modifierElement).getBaseWord();
            }

            if (modifierWord != null && modifierWord.getCategory().enumType == (int)LexicalCategoryEnum.ADVERB)
            {
                addPreModifier(modifierWord);
                return;
            }

            // default case
            addPostModifier(modifierElement);
        }
Exemplo n.º 23
0
        /**
         * <p>
         * Sets a complement of the phrase element. If a complement already exists
         * of the same DISCOURSE_FUNCTION, it is removed. This replaces complements
         * set earlier via {@link #addComplement(NLGElement)}
         * </p>
         *
         * @param newComplement
         *            the new complement as an <code>NLGElement</code>.
         */

        public virtual void setComplement(INLGElement newComplement)
        {
            var f = newComplement.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString());

            if (f != null)
            {
                removeComplements((DiscourseFunction)f);
            }
            addComplement(newComplement);
        }
Exemplo n.º 24
0
        /**
         * Creates a new document element with the given title and adds the given
         * component.
         *
         * @param title
         *            the title for this element.
         * @param component
         *            an <code>NLGElement</code> that becomes the first component of
         *            this document element.
         * @return a <code>DocumentElement</code>
         */

        public DocumentElement createDocument(string title, INLGElement component)
        {
            var element = new DocumentElement(new DocumentCategory_DOCUMENT(), title);

            if (component != null)
            {
                element.addComponent(component);
            }
            return(element);
        }
Exemplo n.º 25
0
        /**
         * Creates a new section element with the given title and adds the given
         * component.
         *
         * @param title
         *            the title for this element.
         * @param component
         *            an <code>NLGElement</code> that becomes the first component of
         *            this document element.
         * @return a <code>DocumentElement</code> representing the section.
         */

        public DocumentElement createSection(string title, INLGElement component)
        {
            var section = new DocumentElement(new DocumentCategory_SECTION(), title);

            if (component != null)
            {
                section.addComponent(component);
            }
            return(section);
        }
Exemplo n.º 26
0
        /**
         * Adds the <em>be</em> verb to the front of the group.
         *
         * @param frontVG
         *            the first verb in the verb group.
         * @param vgComponents
         *            the stack of verb components in the verb group.
         * @param frontForm
         *            the form the current front verb is to take.
         * @return the new element for the front of the group.
         */

        private static INLGElement addBe(INLGElement frontVG,
                                         Stack <INLGElement> vgComponents, Form frontForm)
        {
            if (frontVG != null)
            {
                frontVG.setFeature(Feature.FORM.ToString(), frontForm);
                vgComponents.push(frontVG);
            }
            return(new InflectedWordElement("be", new LexicalCategory_VERB()));
        }
Exemplo n.º 27
0
        /**
         * Creates a new paragraph element and adds the given component
         *
         * @param component
         *            an <code>NLGElement</code> that becomes the first component of
         *            this document element.
         * @return a <code>DocumentElement</code> representing this paragraph
         */

        public DocumentElement createParagraph(INLGElement component)
        {
            var paragraph = new DocumentElement(new DocumentCategory_PARAGRAPH(), null);

            if (component != null)
            {
                paragraph.addComponent(component);
            }
            return(paragraph);
        }
Exemplo n.º 28
0
        /**
         * This is the main method for performing the morphology. It effectively
         * examines the lexical category of the element and calls the relevant set
         * of rules from <code>MorphologyRules</em>.
         *
         * @param element
         *            the <code>InflectedWordElement</code>
         * @return an <code>NLGElement</code> reflecting the correct inflection for
         *         the word.
         */

        private INLGElement doMorphology(InflectedWordElement element)
        {
            INLGElement realisedElement = null;

            if (element.getFeatureAsBoolean(InternalFeature.NON_MORPH.ToString()))
            {
                realisedElement = new StringElement(element.getBaseForm());
                realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                           element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
            }
            else
            {
                INLGElement baseWord = element.getFeatureAsElement(InternalFeature.BASE_WORD.ToString());

                if (baseWord == null && this.lexicon != null)
                {
                    baseWord = this.lexicon.lookupWord(element.getBaseForm());
                }

                var category = element.getCategory();

                if (category is ILexicalCategory)
                {
                    switch ((LexicalCategoryEnum)category.enumType)
                    {
                    case LexicalCategoryEnum.PRONOUN:
                        realisedElement = MorphologyRules.doPronounMorphology(element);
                        break;

                    case LexicalCategoryEnum.NOUN:
                        realisedElement = MorphologyRules.doNounMorphology(element, (WordElement)baseWord);
                        break;

                    case LexicalCategoryEnum.VERB:
                        realisedElement = MorphologyRules.doVerbMorphology(element, (WordElement)baseWord);
                        break;

                    case LexicalCategoryEnum.ADJECTIVE:
                        realisedElement = MorphologyRules.doAdjectiveMorphology(element, (WordElement)baseWord);
                        break;

                    case LexicalCategoryEnum.ADVERB:
                        realisedElement = MorphologyRules.doAdverbMorphology(element, (WordElement)baseWord);
                        break;

                    default:
                        realisedElement = new StringElement(element.getBaseForm());
                        realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                                   element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));
                        break;
                    }
                }
            }
            return(realisedElement);
        }
Exemplo n.º 29
0
        /**
         * Copies the front modifiers of the clause to the list of post-modifiers of
         * the verb only if the phrase has infinitive form.
         *
         * @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 copyFrontModifiers(PhraseElement phrase, INLGElement verbElement)
        {
            var frontModifiers = phrase.getFeatureAsElementList(InternalFeature.FRONT_MODIFIERS.ToString());
            var clauseForm     = phrase.getFeature(Feature.FORM.ToString());

            // bug fix by Chris Howell (Agfa) -- do not overwrite existing post-mods
            // in the VP
            if (verbElement != null)
            {
                List <INLGElement> phrasePostModifiers = phrase.getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString());

                if (verbElement is PhraseElement)
                {
                    List <INLGElement> verbPostModifiers =
                        verbElement.getFeatureAsElementList(InternalFeature.POSTMODIFIERS.ToString());

                    foreach (var eachModifier in phrasePostModifiers)
                    {
                        // need to check that VP doesn't already contain the
                        // post-modifier
                        // this only happens if the phrase has already been realised
                        // and later modified, with realiser called again. In that
                        // case, postmods will be copied over twice
                        if (!verbPostModifiers.Contains(eachModifier))
                        {
                            ((PhraseElement)verbElement).addPostModifier(eachModifier);
                        }
                    }
                }
            }

            // if (verbElement != null) {
            // verbElement.setFeature(InternalFeature.POSTMODIFIERS, phrase
            // .getFeature(InternalFeature.POSTMODIFIERS));
            // }

            if (Form.INFINITIVE.Equals(clauseForm))
            {
                phrase.setFeature(Feature.SUPRESSED_COMPLEMENTISER.ToString(), true);

                foreach (var eachModifier in frontModifiers)
                {
                    if (verbElement is PhraseElement)
                    {
                        ((PhraseElement)verbElement).addPostModifier(eachModifier);
                    }
                }
                phrase.removeFeature(InternalFeature.FRONT_MODIFIERS.ToString());
                if (verbElement != null)
                {
                    verbElement.setFeature(InternalFeature.NON_MORPH.ToString(), true);
                }
            }
        }
Exemplo n.º 30
0
        /**
         * Realises the verb part of the clause.
         *
         * @param phrase
         *            the <code>PhraseElement</code> representing this clause.
         * @param parent
         *            the parent <code>SyntaxProcessor</code> that will do the
         *            realisation of the complementiser.
         * @param realisedElement
         *            the current realisation of the clause.
         * @param splitVerb
         *            an <code>NLGElement</code> representing the subjects that
         *            should split the verb
         * @param verbElement
         *            the <code>NLGElement</code> representing the verb phrase for
         *            this clause.
         * @param whObj
         *            whether the VP is part of an object WH-interrogative
         */

        private static void realiseVerb(PhraseElement phrase,
                                        SyntaxProcessor parent,
                                        ListElement realisedElement,
                                        INLGElement splitVerb,
                                        INLGElement verbElement,
                                        bool whObj)
        {
            setVerbFeatures(phrase, verbElement);

            var currentElement = parent.realise(verbElement);

            if (currentElement != null)
            {
                if (splitVerb == null)
                {
                    currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE);

                    realisedElement.addComponent(currentElement);
                }
                else
                {
                    if (currentElement is ListElement)
                    {
                        var children = currentElement.getChildren();
                        currentElement = children[0];
                        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE);
                        realisedElement.addComponent(currentElement);
                        realisedElement.addComponent(splitVerb);

                        for (var eachChild = 1; eachChild < children.Count; eachChild++)
                        {
                            currentElement = children[eachChild];
                            currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE);
                            realisedElement.addComponent(currentElement);
                        }
                    }
                    else
                    {
                        currentElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(), DiscourseFunction.VERB_PHRASE);

                        if (whObj)
                        {
                            realisedElement.addComponent(currentElement);
                            realisedElement.addComponent(splitVerb);
                        }
                        else
                        {
                            realisedElement.addComponent(splitVerb);
                            realisedElement.addComponent(currentElement);
                        }
                    }
                }
            }
        }