public virtual void nounInflectionalVariantsTest()
        {
            WordElement word =
                lexicon.getWord("sanctum", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN));

            Assert.AreEqual(Inflection.REGULAR, word.getDefaultInflectionalVariant());


            // reg plural shouldn't be stored
            Assert.AreEqual(null, word.getFeature(LexicalFeature.PLURAL));
            InflectedWordElement infl = new InflectedWordElement(word);

            infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            string plur = realiser.realise(infl).Realisation;

            Assert.AreEqual("sanctums", plur);

            // switch to glreg
            word.setDefaultInflectionalVariant(Inflection.GRECO_LATIN_REGULAR);
            infl = new InflectedWordElement(word);
            infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            plur = realiser.realise(infl).Realisation;
            Assert.AreEqual("sancta", plur);

            // and back to reg
            word.setDefaultInflectionalVariant(Inflection.REGULAR);
            infl = new InflectedWordElement(word);
            infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            plur = realiser.realise(infl).Realisation;
            Assert.AreEqual("sanctums", plur);
        }
        public virtual void verbInflectionalVariantsTest()
        {
            WordElement word = lexicon.getWord("lie", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB));

            Assert.AreEqual(Inflection.REGULAR, word.getDefaultInflectionalVariant());


            // default past is "lied"
            InflectedWordElement infl = new InflectedWordElement(word);

            infl.setFeature(Feature.TENSE, Tense.PAST);
            string past = realiser.realise(infl).Realisation;

            Assert.AreEqual("lied", past);

            // switch to irregular
            word.setDefaultInflectionalVariant(Inflection.IRREGULAR);
            infl = new InflectedWordElement(word);
            infl.setFeature(Feature.TENSE, Tense.PAST);
            past = realiser.realise(infl).Realisation;
            Assert.AreEqual("lay", past);

            // switch back to regular
            word.setDefaultInflectionalVariant(Inflection.REGULAR);
            Assert.AreEqual(null, word.getFeature(LexicalFeature.PAST));
            infl = new InflectedWordElement(word);
            infl.setFeature(Feature.TENSE, Tense.PAST);
            past = realiser.realise(infl).Realisation;
            Assert.AreEqual("lied", past);
        }
        public virtual void spellingVariantWithInflectionTest()
        {
            WordElement    word      = lexicon.getWord("formalization");
            IList <string> spellVars = word.getFeatureAsStringList(LexicalFeature.SPELL_VARS);

            Assert.IsTrue(spellVars.Contains("formalisation"));
            Assert.AreEqual(Inflection.REGULAR, word.getDefaultInflectionalVariant());


            // create with default spelling
            NPPhraseSpec np = factory.createNounPhrase("the", word);

            np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
            Assert.AreEqual("the formalizations", realiser.realise(np).Realisation);


            // reset spell var
            word.DefaultSpellingVariant = "formalisation";
            Assert.AreEqual("the formalisations", realiser.realise(np).Realisation);
        }
예제 #4
0
        /**
         * make a WordElement from a lexical record. Currently just specifies basic
         * params and inflections Should do more in the future!
         *
         * @param record
         * @return
         */
        private WordElement makeWord(LexRecord record) // LexRecord
        {
            // get basic data
            String          baseForm = record.GetBase();
            LexicalCategory category = record.GetSimpleNLGCategory(record);
            String          id       = record.GetEui();

            // create word class
            WordElement wordElement = new WordElement(baseForm, category, id);

            // now add type information
            switch (category.GetLexicalCategory())
            {
            case LexicalCategory.LexicalCategoryEnum.ADJECTIVE:
                addAdjectiveInfo(wordElement, record.GetCatEntry().GetAdjEntry());
                break;

            case LexicalCategory.LexicalCategoryEnum.ADVERB:
                addAdverbInfo(wordElement, record.GetCatEntry().GetAdvEntry());
                break;

            case LexicalCategory.LexicalCategoryEnum.NOUN:
                addNounInfo(wordElement, record.GetCatEntry().GetNounEntry());
                break;

            case LexicalCategory.LexicalCategoryEnum.VERB:
                addVerbInfo(wordElement, record.GetCatEntry().GetVerbEntry());
                break;
                // ignore closed class words
            }

            Inflection?defaultInfl = wordElement.getDefaultInflectionalVariant();

            // now add inflected forms
            // if (keepStandardInflections || !standardInflections(record,
            // category)) {
            foreach (InflVar inflection in record.GetInflVarsAndAgreements().GetInflValues())
            {
                String simplenlgInflection = getSimplenlgInflection(inflection
                                                                    .GetInflection());

                if (simplenlgInflection != null)
                {
                    String     inflectedForm = inflection.GetVar();
                    Inflection?inflType      = Inflection.REGULAR.getInflCode(inflection.GetType());

                    // store all inflectional variants, except for regular ones
                    // unless explicitly set
                    if (inflType != null &&
                        !(Inflection.REGULAR == inflType && !keepStandardInflections))
                    {
                        wordElement.addInflectionalVariant((Inflection)inflType,
                                                           simplenlgInflection, inflectedForm);
                    }

                    // if the infl variant is the default, also set this feature on
                    // the word
                    if (defaultInfl == null ||
                        (defaultInfl.Equals(inflType) && !(Inflection.REGULAR.Equals(inflType) && !keepStandardInflections)))
                    {
                        wordElement.setFeature(simplenlgInflection, inflectedForm);
                    }

                    // wordElement
                    // .setFeature(simplenlgInflection, inflection.GetVar());
                }
            }
            // }

            // add acronym info
            addAcronymInfo(wordElement, record);

            // now add spelling variants
            addSpellingVariants(wordElement, record);

            return(wordElement);
        }
        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");
        }