Exemplo n.º 1
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(NLGElement modifier)
        {
            int position = NOUN_POSITION;

            if (modifier.isA(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE)) || modifier.isA(new PhraseCategory(PhraseCategory.PhraseCategoryEnum.ADJECTIVE_PHRASE)))
            {
                WordElement 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);
        }
        public virtual void doBasicTests(Lexicon lexicon)
        {
            // test getWords. Should be 2 "can" (of any cat), 1 noun tree, 0 adj
            // trees
            Assert.AreEqual(3, lexicon.getWords("can").Count);
            Assert.AreEqual(1,
                            lexicon.getWords("can", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)).Count);
            Assert.AreEqual(0,
                            lexicon.getWords("can", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE)).Count);
            // below test removed as standard morph variants no longer recorded in
            // lexicon
            // WordElement early = lexicon.getWord("early",
            // LexicalCategory.ADJECTIVE);
            // Assert.assertEquals("earlier",
            // early.getFeatureAsString(Feature.COMPARATIVE));

            // test getWord. Comparative of ADJ "good" is "better", superlative is
            // "best", this is a qualitative and predicative adjective
            WordElement good =
                lexicon.getWord("good", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE));

            Assert.AreEqual("better", good.getFeatureAsString(LexicalFeature.COMPARATIVE));
            Assert.AreEqual("best", good.getFeatureAsString(LexicalFeature.SUPERLATIVE));
            Assert.AreEqual(true, good.getFeatureAsBoolean(LexicalFeature.QUALITATIVE));
            Assert.AreEqual(true, good.getFeatureAsBoolean(LexicalFeature.PREDICATIVE));
            Assert.AreEqual(false, good.getFeatureAsBoolean(LexicalFeature.COLOUR));
            Assert.AreEqual(false, good.getFeatureAsBoolean(LexicalFeature.CLASSIFYING));


            // test getWord. There is only one "woman", and its plural is "women".
            // It is not an acronym, not proper, and countable
            WordElement woman = lexicon.getWord("woman");

            Assert.AreEqual("women", woman.getFeatureAsString(LexicalFeature.PLURAL));
            Assert.AreEqual(null, woman.getFeatureAsString(LexicalFeature.ACRONYM_OF));
            Assert.AreEqual(false, woman.getFeatureAsBoolean(LexicalFeature.PROPER));
            Assert.IsFalse(woman.hasInflectionalVariant(Inflection.UNCOUNT));

            // NB: This fails if the lexicon is XMLLexicon. No idea why.
            // Assert.assertEquals("irreg",
            // woman.getFeatureAsString(LexicalFeature.DEFAULT_INFL));

            // test getWord. Noun "sand" is non-count
            WordElement sand = lexicon.getWord("sand", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN));

            Assert.AreEqual(true, sand.hasInflectionalVariant(Inflection.UNCOUNT));
            Assert.AreEqual(Inflection.UNCOUNT, sand.getDefaultInflectionalVariant());

            // test hasWord
            Assert.AreEqual(true, lexicon.hasWord("tree")); // "tree" exists
            Assert.AreEqual(false,
                            lexicon.hasWord("tree",
                                            new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB))); // but not as an adverb


            // test getWordByID; quickly, also check that this is a verb_modifier
            WordElement quickly = lexicon.getWordByID("E0051632");

            Assert.AreEqual("quickly", quickly.BaseForm);
            Assert.AreEqual(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB), quickly.Category);
            Assert.AreEqual(true, quickly.getFeatureAsBoolean(LexicalFeature.VERB_MODIFIER));
            Assert.AreEqual(false, quickly.getFeatureAsBoolean(LexicalFeature.SENTENCE_MODIFIER));
            Assert.AreEqual(false, quickly.getFeatureAsBoolean(LexicalFeature.INTENSIFIER));


            // test getWordFromVariant, verb type (tran or intran, not ditran)
            WordElement eat = lexicon.getWordFromVariant("eating");

            Assert.AreEqual("eat", eat.BaseForm);
            Assert.AreEqual(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB), eat.Category);
            Assert.AreEqual(true, eat.getFeatureAsBoolean(LexicalFeature.INTRANSITIVE));
            Assert.AreEqual(true, eat.getFeatureAsBoolean(LexicalFeature.TRANSITIVE));
            Assert.AreEqual(false, eat.getFeatureAsBoolean(LexicalFeature.DITRANSITIVE));


            Assert.AreEqual("been",
                            lexicon.getWordFromVariant("is", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB))
                            .getFeatureAsString(LexicalFeature.PAST_PARTICIPLE));
            // test BE is handled OK

            // test modal
            WordElement can = lexicon.getWord("can", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.MODAL));

            Assert.AreEqual("could", can.getFeatureAsString(LexicalFeature.PAST));

            // test non-existent word
            Assert.AreEqual(0, lexicon.getWords("akjmchsgk").Count);

            // test lookup word method
            Assert.AreEqual(
                lexicon.lookupWord("say", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)).BaseForm,
                "say");
            Assert.AreEqual(
                lexicon.lookupWord("said", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)).BaseForm,
                "say");
            Assert.AreEqual(
                lexicon.lookupWord("E0054448", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)).BaseForm,
                "say");
        }
Exemplo n.º 3
0
        // note that addFrontModifier, addPostModifier, addPreModifier are inherited
        // from PhraseElement
        // likewise getFrontModifiers, getPostModifiers, getPreModifiers

        /**
         * Add a modifier to a clause Use heuristics to decide where it goes
         *
         * @param modifier
         */
        public override void addModifier(object modifier)
        {
            // adverb is frontModifier if sentenceModifier
            // otherwise adverb is preModifier
            // string which is one lexicographic word is looked up in lexicon,
            // above rules apply if adverb
            // Everything else is postModifier

            if (modifier == null)
            {
                return;
            }

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

            if (modifier is NLGElement)
            {
                modifierElement = (NLGElement)modifier;
            }
            else if (modifier is string)
            {
                string modifierString = (string)modifier;
                if (modifierString.Length > 0 && !modifierString.Contains(" "))
                {
                    modifierElement = Factory.createWord(modifier, new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ANY));
                }
            }

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

            // AdvP is premodifer (probably should look at head to see if sentenceModifier)
            if (modifierElement is AdvPhraseSpec)
            {
                addPreModifier(modifierElement);
                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).BaseWord;
            }

            if (modifierWord != null && modifierWord.Category == LexicalCategory.LexicalCategoryEnum.ADVERB)
            {
                // adverb rules
                if (modifierWord.getFeatureAsBoolean(LexicalFeature.SENTENCE_MODIFIER))
                {
                    addFrontModifier(modifierWord);
                }
                else
                {
                    addPreModifier(modifierWord);
                }
                return;
            }

            // default case
            addPostModifier(modifierElement);
        }