Exemplo n.º 1
0
        public void LexemeAddedEvent()
        {
            // Listen for events
            int lexemeAddedCount = 0;
            int senseAddedCount  = 0;
            int glossAddedCount  = 0;

            m_lexicon.LexemeAdded       += (sender, e) => lexemeAddedCount++;
            m_lexicon.LexiconSenseAdded += (sender, e) => senseAddedCount++;
            m_lexicon.LexiconGlossAdded += (sender, e) => glossAddedCount++;

            Lexeme lexeme = m_lexicon.FindOrCreateLexeme(LexemeType.Word, "word");

            Assert.AreEqual(0, lexemeAddedCount);

            m_lexicon.AddLexeme(lexeme);
            Assert.AreEqual(1, lexemeAddedCount);
            Assert.AreEqual(0, senseAddedCount);
            Assert.AreEqual(0, glossAddedCount);

            // Adding sense adds lexeme
            Lexeme lexeme2 = m_lexicon.FindOrCreateLexeme(LexemeType.Word, "word2");

            lexeme2.AddSense();
            Assert.AreEqual(2, lexemeAddedCount);
        }
Exemplo n.º 2
0
        public void GlossAddedEvent()
        {
            // Listen for events
            int    lexemeAddedCount = 0;
            int    senseAddedCount  = 0;
            int    glossAddedCount  = 0;
            string glossText        = "";

            m_lexicon.LexemeAdded       += (sender, e) => lexemeAddedCount++;
            m_lexicon.LexiconSenseAdded += (sender, e) => senseAddedCount++;
            m_lexicon.LexiconGlossAdded += (sender, e) =>
            {
                glossAddedCount++;
                glossText = e.Gloss.Text;
            };

            Lexeme lexeme = m_lexicon.FindOrCreateLexeme(LexemeType.Word, "word");

            m_lexicon.AddLexeme(lexeme);
            LexiconSense sense = lexeme.AddSense();

            sense.AddGloss("en", "somegloss");

            Assert.AreEqual(1, glossAddedCount);
            Assert.AreEqual("somegloss", glossText);
        }
Exemplo n.º 3
0
        public void SensesRetained()
        {
            Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Word, "a");

            m_lexicon.AddLexeme(lex);
            LexiconSense sense = lex.AddSense();

            sense.AddGloss("en", "glossen");
            sense.AddGloss("fr", "glossfr");

            Assert.AreEqual(1, lex.Senses.Count());
            Assert.AreEqual(2, lex.Senses.First().Glosses.Count());

            sense = m_lexicon[lex.Id].Senses.First();             // Make sure we're working with the one stored in the lexicon
            Assert.AreEqual("en", sense.Glosses.First().Language);
            Assert.AreEqual("glossen", sense.Glosses.First().Text);
            Assert.AreEqual("fr", sense.Glosses.ElementAt(1).Language);
            Assert.AreEqual("glossfr", sense.Glosses.ElementAt(1).Text);

            sense.RemoveGloss("en");

            sense = m_lexicon[lex.Id].Senses.First();             // Make sure we're working with the one stored in the lexicon
            Assert.AreEqual(1, sense.Glosses.Count());
            Assert.AreEqual("fr", sense.Glosses.First().Language);
            Assert.AreEqual("glossfr", sense.Glosses.First().Text);
        }
Exemplo n.º 4
0
        public void FindOrCreate()
        {
            Lexeme       lex   = m_lexicon.CreateLexeme(LexemeType.Word, "a");
            LexiconSense sense = lex.AddSense();

            sense.AddGloss("en", "monkey");

            Lexeme lex2 = m_lexicon.FindOrCreateLexeme(LexemeType.Word, "a");

            Assert.AreEqual(lex.Id, lex2.Id);
            Assert.AreEqual(LexemeType.Word, lex2.Type);
            Assert.AreEqual("a", lex2.LexicalForm);
            Assert.AreEqual(1, lex2.Senses.Count());
            Assert.AreEqual(1, lex2.Senses.First().Glosses.Count());
            Assert.AreEqual("en", lex2.Senses.First().Glosses.First().Language);
            Assert.AreEqual("monkey", lex2.Senses.First().Glosses.First().Text);

            Lexeme lex3 = m_lexicon.FindOrCreateLexeme(LexemeType.Suffix, "bob");

            Assert.AreNotEqual(lex.Id, lex3.Id);
            Assert.AreNotEqual(lex2.Id, lex3.Id);
            Assert.AreEqual(LexemeType.Suffix, lex3.Type);
            Assert.AreEqual("bob", lex3.LexicalForm);
            Assert.AreEqual(0, lex3.Senses.Count());
        }
Exemplo n.º 5
0
        public void RemoveSenseSucceeds()
        {
            Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Word, "a");

            m_lexicon.AddLexeme(lex);

            LexiconSense sense = lex.AddSense();

            sense.AddGloss("en", "gloss1");

            LexiconSense sense2 = lex.AddSense();

            sense.AddGloss("en", "gloss1");

            // Test remove at
            lex.RemoveSense(sense2);

            Assert.AreEqual(1, lex.Senses.Count());
            Assert.AreEqual(sense, lex.Senses.First());
        }
Exemplo n.º 6
0
        public void AddingSenseAddsLexeme()
        {
            Lexeme       lex   = m_lexicon.CreateLexeme(LexemeType.Word, "a");
            LexiconSense sense = lex.AddSense();

            sense.AddGloss("en", "test");

            Assert.AreEqual(1, m_lexicon.Lexemes.Count());

            lex = m_lexicon[lex.Id];             // Make sure we're using the one stored in the lexicon
            Assert.AreEqual(LexemeType.Word, lex.Type);
            Assert.AreEqual("a", lex.LexicalForm);
            Assert.AreEqual(1, lex.Senses.Count());
            Assert.AreEqual("en", lex.Senses.First().Glosses.First().Language);
            Assert.AreEqual("test", lex.Senses.First().Glosses.First().Text);
        }
Exemplo n.º 7
0
        public void MultipleCreatesReferToSameSenses()
        {
            Lexeme lex  = m_lexicon.CreateLexeme(LexemeType.Word, "a");
            Lexeme lex2 = m_lexicon.CreateLexeme(LexemeType.Word, "a");

            m_lexicon.AddLexeme(lex);
            LexiconSense sense = lex.AddSense();

            sense.AddGloss("en", "test");

            Assert.AreEqual(1, lex2.Senses.Count());

            // Make sure the one that was added has the right sense now
            lex = m_lexicon[lex.Id];
            Assert.AreEqual(LexemeType.Word, lex.Type);
            Assert.AreEqual("a", lex.LexicalForm);
            Assert.AreEqual(1, lex.Senses.Count());
            Assert.AreEqual("en", lex.Senses.First().Glosses.First().Language);
            Assert.AreEqual("test", lex.Senses.First().Glosses.First().Text);
        }
Exemplo n.º 8
0
        public void NormalizeStrings()
        {
            Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Stem, "Vacaci\u00f3n");             // Uses composed accented letter 'o'

            m_lexicon.AddLexeme(lex);

            lex = m_lexicon[new LexemeKey(LexemeType.Stem, "Vacaci\u00f3n").Id];
            Assert.IsNotNull(lex);
            Assert.AreEqual(LexemeType.Stem, lex.Type);
            Assert.AreEqual("Vacaci\u00f3n", lex.LexicalForm);

            LexiconSense sense = lex.AddSense();

            Assert.IsNotNull(sense);

            LanguageText gloss = sense.AddGloss("en", "D\u00f3nde");

            Lexeme reGetLex = m_lexicon[lex.Id];

            Assert.AreEqual(gloss.Text, reGetLex.Senses.First().Glosses.First().Text);
        }