Exemple #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);
        }
Exemple #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();
            // }
        }