コード例 #1
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);
        }
コード例 #2
0
        /**
         * return the base form of a word
         *
         * @param element
         * @param baseWord
         * @return
         */

        private static string getBaseForm(InflectedWordElement element, WordElement baseWord)
        {
            // unclear what the right behaviour should be
            // for now, prefer baseWord.getBaseForm() to element.getBaseForm() for
            // verbs (ie, "is" mapped to "be")
            // but prefer element.getBaseForm() to baseWord.getBaseForm() for other
            // words (ie, "children" not mapped to "child")

            // AG: changed this to get the default spelling variant
            // needed to preserve spelling changes in the VP

            if ((int)LexicalCategoryEnum.VERB == element.getCategory().enumType)
            {
                if (baseWord != null && baseWord.getDefaultSpellingVariant() != null)
                {
                    return(baseWord.getDefaultSpellingVariant());
                }
                else
                {
                    return(element.getBaseForm());
                }
            }
            else
            {
                if (element.getBaseForm() != null)
                {
                    return(element.getBaseForm());
                }
                else if (baseWord == null)
                {
                    return(null);
                }
                else
                {
                    return(baseWord.getDefaultSpellingVariant());
                }
            }

            // if (LexicalCategory.VERB == element.getCategory()) {
            // if (baseWord != null && baseWord.getBaseForm() != null)
            // return baseWord.getBaseForm();
            // else
            // return element.getBaseForm();
            // } else {
            // if (element.getBaseForm() != null)
            // return element.getBaseForm();
            // else if (baseWord == null)
            // return null;
            // else
            // return baseWord.getBaseForm();
            // }
        }
コード例 #3
0
        /**
         * This method performs the morphology for pronouns.
         *
         * @param element
         *            the <code>InflectedWordElement</code>.
         * @return a <code>StringElement</code> representing the word after
         *         inflection.
         */

        public static INLGElement doPronounMorphology(InflectedWordElement element)
        {
            string realised = null;

            if (!element.getFeatureAsBoolean(InternalFeature.NON_MORPH.ToString()) && !isWHPronoun(element))
            {
                var genderValue    = element.getFeature(LexicalFeature.GENDER);
                var personValue    = element.getFeature(Feature.PERSON.ToString());
                var discourseValue = element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString());

                var numberIndex = element.isPlural() ? 1 : 0;
                var genderIndex = (genderValue is Gender) ? ((Gender)genderValue).ordinal() : 2;

                var personIndex = (personValue is Person) ? ((Person)personValue).ordinal() : 2;

                if (personIndex == 2)
                {
                    personIndex += genderIndex;
                }

                var positionIndex = 0;

                if (element.getFeatureAsBoolean(LexicalFeature.REFLEXIVE))
                {
                    positionIndex = 2;
                }
                else if (element.getFeatureAsBoolean(Feature.POSSESSIVE.ToString()))
                {
                    positionIndex = 3;
                    if (DiscourseFunction.SPECIFIER.Equals(discourseValue))
                    {
                        positionIndex++;
                    }
                }
                else
                {
                    positionIndex = (DiscourseFunction.SUBJECT.Equals(discourseValue) && !element.getFeatureAsBoolean(
                                         Feature.PASSIVE.ToString())) ||
                                    (DiscourseFunction.OBJECT.Equals(discourseValue) &&
                                     element.getFeatureAsBoolean(Feature.PASSIVE.ToString())) ||
                                    DiscourseFunction.SPECIFIER.Equals(discourseValue) || (
                        DiscourseFunction.COMPLEMENT.Equals(discourseValue) &&
                        element.getFeatureAsBoolean(Feature.PASSIVE.ToString()))
                        ? 0
                        : 1;
                }
                realised = PRONOUNS[numberIndex][positionIndex][personIndex];
            }
            else
            {
                realised = element.getBaseForm();
            }
            var realisedElement = new StringElement(realised);

            realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION.ToString(),
                                       element.getFeature(InternalFeature.DISCOURSE_FUNCTION.ToString()));

            return(realisedElement);
        }
コード例 #4
0
        private static bool isWHPronoun(InflectedWordElement word)
        {
            var bases = word.getBaseForm();
            var wh    = false;

            if (bases != null)
            {
                for (var i = 0; i < WH_PRONOUNS.Length && !wh; i++)
                {
                    wh = WH_PRONOUNS[i].Equals(bases);
                }
            }

            return(wh);
        }