Exemplo n.º 1
0
        public void I_will_read()
        {
            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme),

                EnglishPattern.O1_I.SetLeftFirst(),

                EnglishPattern.EpsilonAdPosition("I-I", "", EnglishAttributes.I.Lexeme.Verb.Modal, EnglishAttributes.I.Lexeme)
                .SetLeftFirst()
                .SetSubstitutionForLeft(SubstitutionRules.Nothing),
            };

            List <Morpheme> morphemes = new List <Morpheme>()
            {
                // Lexemes.
                new Morpheme(myAttributesModel, "I", EnglishAttributes.O.Lexeme.Pronoun),
                new Morpheme(myAttributesModel, "will", EnglishAttributes.I.Lexeme.Verb.Modal),
                new Morpheme(myAttributesModel, "read", EnglishAttributes.I.Lexeme.Verb.Form.Infinitive | EnglishAttributes.I.Lexeme.Verb.Valency.Bivalent),
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(myAttributesModel, morphemes, patterns);

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("I", "will", "read");

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("I", results[0].Left.Morpheme.Morph);
            Assert.AreEqual("will", results[0].Right.Left.Morpheme.Morph);
            Assert.AreEqual("read", results[0].Right.Right.Morpheme.Morph);
        }
Exemplo n.º 2
0
        public void World_as_people_say_lately_ends()
        {
            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.E.Lexeme),

                EnglishPattern.O1_I.SetLeftFirst(),
                EnglishPattern.MorphematicAdPosition("I-U-O", "", EnglishAttributes.U.Lexeme.Conjunction, EnglishAttributes.I.Lexeme, EnglishAttributes.O.Lexeme),
                EnglishPattern.EpsilonAdPosition("E-I", "", EnglishAttributes.E.Lexeme.Adverb, EnglishAttributes.I.Lexeme).SetSubstitutionForLeft(SubstitutionRules.Nothing),
            };

            List <Morpheme> morphemes = new List <Morpheme>()
            {
                // Lexemes.
                new Morpheme(myAttributesModel, "world", EnglishAttributes.O.Lexeme.Noun),
                new Morpheme(myAttributesModel, "as", EnglishAttributes.U.Lexeme.Conjunction),
                new Morpheme(myAttributesModel, "people", EnglishAttributes.O.Lexeme.Noun),
                new Morpheme(myAttributesModel, "say", EnglishAttributes.I.Lexeme.Verb),
                new Morpheme(myAttributesModel, "lately", EnglishAttributes.E.Lexeme.Adverb),
                new Morpheme(myAttributesModel, "ends", EnglishAttributes.I.Lexeme.Verb),
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(myAttributesModel, morphemes, patterns);

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("world", "as", "people", "say", "lately", "ends");

            // TODO:
            Assert.AreEqual(1, results.Count);
        }
Exemplo n.º 3
0
        public void Green_race_car()
        {
            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),

                EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme)
                .SetLeftFirst(),

                EnglishPattern.MonoTransference("O>A", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme),
            };

            List <Morpheme> morphemes = new List <Morpheme>()
            {
                // Lexemes.
                new Morpheme(myAttributesModel, "green", EnglishAttributes.A.Lexeme.Adjective),
                new Morpheme(myAttributesModel, "race", EnglishAttributes.O.Lexeme.Noun),
                new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme.Noun),
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(myAttributesModel, morphemes, patterns);

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("green", "race", "car");

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("green", results[0].Left.Morpheme.Morph);
            Assert.AreEqual("race", results[0].Right.Left.Right.Morpheme.Morph);
            Assert.AreEqual("car", results[0].Right.Right.Morpheme.Morph);
        }
Exemplo n.º 4
0
        public void The_good_book()
        {
            List <Morpheme> morphemes = new List <Morpheme>()
            {
                new Morpheme(myAttributesModel, "the", EnglishAttributes.A.Lexeme.Determiner.DefiniteArticle),
                new Morpheme(myAttributesModel, "good", EnglishAttributes.A.Lexeme.Adjective.Attributive),
                new Morpheme(myAttributesModel, "book", EnglishAttributes.O.Lexeme.Noun),
            };

            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),

                EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme)
                .SetLeftFirst(),
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(myAttributesModel, morphemes, patterns);

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("the", "good", "book");

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("the", results[0].Left.Morpheme.Morph);
            Assert.AreEqual("good", results[0].Right.Left.Morpheme.Morph);
            Assert.AreEqual("book", results[0].Right.Right.Morpheme.Morph);
        }
Exemplo n.º 5
0
        public void I_read_the_book()
        {
            List <Morpheme> morphemes = new List <Morpheme>()
            {
                // Lexemes.
                new Morpheme(myAttributesModel, "I", EnglishAttributes.O.Lexeme.Pronoun),
                new Morpheme(myAttributesModel, "read", EnglishAttributes.I.Lexeme.Verb.Valency.Bivalent),
                new Morpheme(myAttributesModel, "the", EnglishAttributes.A.Lexeme.Determiner.DefiniteArticle),
                new Morpheme(myAttributesModel, "book", EnglishAttributes.O.Lexeme.Noun),
            };

            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme),

                EnglishPattern.O1_I.SetLeftFirst(),
                EnglishPattern.O2_I,

                EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme).SetLeftFirst(),
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(myAttributesModel, morphemes, patterns);

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("I", "read", "the", "book");

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("I", results[0].Right.Left.Morpheme.Morph);
            Assert.AreEqual("read", results[0].Right.Right.Morpheme.Morph);
            Assert.AreEqual("the", results[0].Left.Left.Morpheme.Morph);
            Assert.AreEqual("book", results[0].Left.Right.Morpheme.Morph);
        }
Exemplo n.º 6
0
        public void IsEpsilonAdPosition()
        {
            Pattern pattern = EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A, EnglishAttributes.O);

            Assert.IsTrue(pattern.IsEpsilonAdPosition());


            pattern = new Pattern("A-U-A")
            {
                // Grammar character is not epsilon -> it is not epsilon adposition.
                UpRule    = EnglishMorphemeRule.Is(MorphRules.Something, EnglishAttributes.U),
                LeftRule  = EnglishMorphemeRule.A_Lexeme,
                RightRule = EnglishMorphemeRule.A_Lexeme,
            };
            Assert.IsFalse(pattern.IsEpsilonAdPosition());


            pattern = new Pattern("A-O")
            {
                UpRule = MorphemeRule.Epsilon,
                // It is not epsilon adposition.
                LeftRule  = MorphemeRule.Nothing,
                RightRule = EnglishMorphemeRule.O_Lexeme,
            };
            Assert.IsFalse(pattern.IsEpsilonAdPosition());
        }
Exemplo n.º 7
0
        public void RulingGrammarCharacter()
        {
            // The phrase: I read the book.
            AdTree adTree = new AdTree(new Morpheme(myAttributesModel, "", 0), EnglishPattern.O2_I)
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "", 0), EnglishPattern.O1_I)
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "read", EnglishAttributes.I), EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme)),
                    Left  = new AdTree(new Morpheme(myAttributesModel, "I", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme))
                },
                Left = new AdTree(new Morpheme(myAttributesModel, "", 0), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "book", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme)),
                    Left  = new AdTree(new Morpheme(myAttributesModel, "the", EnglishAttributes.A), EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme))
                }
            };


            // O2-I
            Assert.AreEqual(GrammarCharacter.I, adTree.RulingGrammarCharacter);

            // O: I
            Assert.AreEqual(GrammarCharacter.O, adTree.Right.Left.RulingGrammarCharacter);

            // O1-I
            Assert.AreEqual(GrammarCharacter.I, adTree.Right.RulingGrammarCharacter);

            // A-O
            Assert.AreEqual(GrammarCharacter.O, adTree.Left.RulingGrammarCharacter);
        }
Exemplo n.º 8
0
        public void He_read_s()
        {
            List <Morpheme> morphemes = new List <Morpheme>()
            {
                new Morpheme(myAttributesModel, "he", EnglishAttributes.O.Lexeme.Pronoun),
                new Morpheme(myAttributesModel, "read", EnglishAttributes.I.Lexeme.Verb.Valency.Bivalent),
                new Morpheme(myAttributesModel, "s", EnglishAttributes.I.NonLexeme.Suffix),
            };

            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme),

                EnglishPattern.Morpheme(EnglishAttributes.I.NonLexeme.Suffix),

                EnglishPattern.O1_I.SetLeftFirst(),

                EnglishPattern.EpsilonAdPosition("I>I+", "", EnglishAttributes.I.NonLexeme.Suffix, EnglishAttributes.I.Lexeme),
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(myAttributesModel, morphemes, patterns);

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("he", "reads");

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("he", results[0].Left.Morpheme.Morph);
            Assert.AreEqual("s", results[0].Right.Left.Morpheme.Morph);
            Assert.AreEqual("read", results[0].Right.Right.Morpheme.Morph);
        }
Exemplo n.º 9
0
        public void CanAttachToLeft_Substitution_Morphemic()
        {
            IAdTree adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
            {
                Left = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("O-A", "", EnglishAttributes.O.Lexeme, EnglishAttributes.A.Lexeme).SetLeftFirst())
            };

            IAdTree adTreeElement = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme));

            Assert.IsTrue(adTree.Left.CanAttachToLeft(adTreeElement, myAttributesModel));


            // The morpheme is not attached to the right yet - so only rules are evaluated.
            adTreeElement = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme));
            Assert.IsTrue(adTree.Left.CanAttachToLeft(adTreeElement, myAttributesModel));


            // Attach to the left on the root.
            adTree        = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme).SetLeftFirst());
            adTreeElement = new AdTree(new Morpheme(myAttributesModel, "green", EnglishAttributes.A.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme));
            Assert.IsTrue(adTree.CanAttachToLeft(adTreeElement, myAttributesModel));

            // Attach to the left on the root - incorrect morpheme.
            adTree        = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme));
            adTreeElement = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme));
            Assert.IsFalse(adTree.CanAttachToLeft(adTreeElement, myAttributesModel));
        }
Exemplo n.º 10
0
        public void IsMorphematicAdPosition()
        {
            Pattern pattern = EnglishPattern.MorphematicAdPosition("O-E-I", "", EnglishAttributes.E, EnglishAttributes.O, EnglishAttributes.I);

            Assert.IsTrue(pattern.IsMorphematicAdPosition());

            pattern = EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A, EnglishAttributes.O);
            Assert.IsFalse(pattern.IsMorphematicAdPosition());
        }
Exemplo n.º 11
0
        public void IsComplete()
        {
            AdTree adTree = new AdTree(new Morpheme(myAttributesModel, "book", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme));

            Assert.IsTrue(adTree.IsComplete());

            // Missing morph.
            adTree = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme));
            Assert.IsFalse(adTree.IsComplete());

            // Missing attributes.
            adTree = new AdTree(new Morpheme(myAttributesModel, "book", 0), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme));
            Assert.IsFalse(adTree.IsComplete());


            adTree = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.A.Lexeme), EnglishPattern.MonoTransference("O>A", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
            {
                Left  = null,
                Right = new AdTree(new Morpheme(myAttributesModel, "", 0), new Pattern()),
            };
            Assert.IsTrue(adTree.IsComplete());

            // Right is missing.
            adTree = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.A.Lexeme), EnglishPattern.MonoTransference("O>A", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
            {
                Left  = null,
                Right = null,
            };
            Assert.IsFalse(adTree.IsComplete());


            adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A, EnglishAttributes.O))
            {
                Left  = new AdTree(new Morpheme(myAttributesModel, "", 0), new Pattern()),
                Right = new AdTree(new Morpheme(myAttributesModel, "", 0), new Pattern()),
            };
            Assert.IsTrue(adTree.IsComplete());

            adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A, EnglishAttributes.O))
            {
                Left  = null,
                Right = new AdTree(new Morpheme(myAttributesModel, "", 0), new Pattern()),
            };
            Assert.IsFalse(adTree.IsComplete());

            adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A, EnglishAttributes.O))
            {
                Left  = new AdTree(new Morpheme(myAttributesModel, "", 0), new Pattern()),
                Right = null,
            };
            Assert.IsFalse(adTree.IsComplete());
        }
        public void PatternGraph_Itself()
        {
            IAttributesModel attributesModel = new EnglishAttributesModel();

            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.EpsilonAdPosition("A-A", "", EnglishAttributes.A.Lexeme, EnglishAttributes.A.Lexeme),
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(attributesModel, new Morpheme[0], patterns);

            Assert.AreEqual(1, dictionary.PatternGraph.Edges.Count());
            Assert.IsTrue(dictionary.PatternGraph.Edges.Any(x => x.From == GrammarCharacter.A && x.To == GrammarCharacter.A && x.Value.Name == "A-A"));
        }
Exemplo n.º 13
0
        public void GetNonconformities_MonoTransference()
        {
            AdTree adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme)),
                Left  = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.A.Lexeme), EnglishPattern.MonoTransference("O>A", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "race", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme)),
                    Left  = null,
                },
            };

            List <IAdTree> nonconformities = adTree.GetNonconformities(myAttributesModel).ToList();

            Assert.AreEqual(0, nonconformities.Count);
        }
Exemplo n.º 14
0
        public void It_is_good_and_bad_book()
        {
            List <Morpheme> morphemes = new List <Morpheme>()
            {
                // Lexemes.
                new Morpheme(myAttributesModel, "it", EnglishAttributes.O.Lexeme.Pronoun),
                new Morpheme(myAttributesModel, "is", EnglishAttributes.I.Lexeme.Verb.Valency.Bivalent),
                new Morpheme(myAttributesModel, "good", EnglishAttributes.A.Lexeme.Adjective.Attributive),
                new Morpheme(myAttributesModel, "and", EnglishAttributes.U.Lexeme.Conjunction),
                new Morpheme(myAttributesModel, "bad", EnglishAttributes.A.Lexeme.Adjective.Attributive),
                new Morpheme(myAttributesModel, "book", EnglishAttributes.O.Lexeme.Noun),
            };

            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme),

                EnglishPattern.O1_I.SetLeftFirst(),
                EnglishPattern.O2_I,

                EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme)
                .SetLeftFirst(),

                new Pattern("A-U-A")
                {
                    UpRule    = EnglishMorphemeRule.U_Lexeme,
                    LeftRule  = EnglishMorphemeRule.A_Lexeme,
                    RightRule = EnglishMorphemeRule.A_Lexeme,
                },
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(myAttributesModel, morphemes, patterns);

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("it", "is", "good", "and", "bad", "book");

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("it", results[0].Right.Left.Morpheme.Morph);
            Assert.AreEqual("is", results[0].Right.Right.Morpheme.Morph);
            Assert.AreEqual("good", results[0].Left.Left.Right.Morpheme.Morph);
            Assert.AreEqual("and", results[0].Left.Left.Morpheme.Morph);
            Assert.AreEqual("bad", results[0].Left.Left.Left.Morpheme.Morph);
            Assert.AreEqual("book", results[0].Left.Right.Morpheme.Morph);
        }
Exemplo n.º 15
0
        public void The_world_as_you_know_ends()
        {
            List <Morpheme> morphemes = new List <Morpheme>()
            {
                // Lexemes.
                new Morpheme(myAttributesModel, "the", EnglishAttributes.A.Lexeme.Determiner),
                new Morpheme(myAttributesModel, "world", EnglishAttributes.O.Lexeme.Noun),
                new Morpheme(myAttributesModel, "as", EnglishAttributes.U.Lexeme.Conjunction),
                new Morpheme(myAttributesModel, "you", EnglishAttributes.O.Lexeme.Pronoun),
                new Morpheme(myAttributesModel, "know", EnglishAttributes.I.Lexeme.Verb.Valency.Bivalent),
                new Morpheme(myAttributesModel, "ends", EnglishAttributes.I.Lexeme.Verb.Valency.Monovalent),
            };

            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme),

                EnglishPattern.O1_I.SetLeftFirst(),

                EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme)
                .SetLeftFirst()
                .SetSubstitutionForRight(SubstitutionRules.Epsilon),

                new Pattern("I-U-O")
                {
                    UpRule    = EnglishMorphemeRule.Is(MorphRules.Something, EnglishAttributes.U.Lexeme.Conjunction),
                    LeftRule  = EnglishMorphemeRule.I_Lexeme,
                    RightRule = EnglishMorphemeRule.O_Lexeme,
                },
            };

            ConstructiveDictionary dictionary = new ConstructiveDictionary(myAttributesModel, morphemes, patterns);

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("the", "world", "as", "you", "know", "ends");

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("the", results[0].Left.Right.Left.Morpheme.Morph);
            Assert.AreEqual("world", results[0].Left.Right.Right.Morpheme.Morph);
            Assert.AreEqual("as", results[0].Left.Morpheme.Morph);
            Assert.AreEqual("you", results[0].Left.Left.Left.Morpheme.Morph);
            Assert.AreEqual("know", results[0].Left.Left.Right.Morpheme.Morph);
            Assert.AreEqual("ends", results[0].Right.Morpheme.Morph);
        }
Exemplo n.º 16
0
        public void TryGetTransferenceMorpheme_MonoTransference()
        {
            AdTree adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme)),

                // Mono-transference.
                Left = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.A.Lexeme), EnglishPattern.MonoTransference("O>A", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "race", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme)),
                    Left  = null,
                },
            };

            Assert.IsTrue(adTree.Left.Pattern.IsMonoTransference);

            var result = adTree.Left.TryGetTransferenceMorpheme();

            // Attributes shall be taken from the parent.
            Assert.AreEqual(adTree.Left.Morpheme.Attributes, result.Attributes);

            // Morph shall be taken from the child.
            Assert.AreEqual(adTree.Left.Right.Morpheme.Morph, result.Morph);
        }
Exemplo n.º 17
0
        public void SubjectAndPredicate_with_circumstantial()
        {
            var adTree = new AdTree(new Morpheme(myAttributesModel, ".", EnglishAttributes.U.NonLexeme.PunctuationMark.Period), EnglishPattern.MorphematicAdPosition("I-U-I", "", EnglishAttributes.U.NonLexeme.PunctuationMark, EnglishAttributes.I.Lexeme, EnglishAttributes.I.Lexeme))
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "in", EnglishAttributes.E.Lexeme.Preposition), EnglishPattern.MorphematicAdPosition("O-E-I", "", EnglishAttributes.E.Lexeme, EnglishAttributes.O.Lexeme, EnglishAttributes.I.Lexeme))
                {
                    Right = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.O2_I)
                    {
                        Right = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.O1_I.SetLeftFirst())
                        {
                            Right = new AdTree(new Morpheme(myAttributesModel, "read", EnglishAttributes.I.Lexeme.Verb.Valency.Bivalent), EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme)),
                            Left  = new AdTree(new Morpheme(myAttributesModel, "I", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme))
                        },
                        Left = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A, EnglishAttributes.O).SetLeftFirst())
                        {
                            Right = new AdTree(new Morpheme(myAttributesModel, "book", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O)),
                            Left  = new AdTree(new Morpheme(myAttributesModel, "the", EnglishAttributes.A.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.A))
                        }
                    },
                    Left = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A, EnglishAttributes.O).SetLeftFirst())
                    {
                        Right = new AdTree(new Morpheme(myAttributesModel, "room", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme)),
                        Left  = new AdTree(new Morpheme(myAttributesModel, "the", EnglishAttributes.A), EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme))
                    }
                }
            };

            var factory = new LinguisticStructureFactory(myAttributesModel);
            var clause  = factory.CreateClause(adTree, 0);

            Assert.AreEqual("I", clause.Subject.Value);
            Assert.AreEqual("read the book in the room", clause.Predicate.Value);
        }
Exemplo n.º 18
0
        public void SubjectAndPredicate()
        {
            var adTree = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.O2_I)
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.O1_I.SetLeftFirst())
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "read", EnglishAttributes.I.Lexeme.Verb.Valency.Bivalent), EnglishPattern.Morpheme(EnglishAttributes.I)),
                    Left  = new AdTree(new Morpheme(myAttributesModel, "I", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O)),
                },
                Left = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.EpsilonAdPosition("", "", EnglishAttributes.A, EnglishAttributes.O).SetLeftFirst())
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "book", EnglishAttributes.O.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.O)),
                    Left  = new AdTree(new Morpheme(myAttributesModel, "the", EnglishAttributes.A.Lexeme), EnglishPattern.Morpheme(EnglishAttributes.A))
                }
            };

            var factory = new LinguisticStructureFactory(myAttributesModel);
            var clause  = factory.CreateClause(adTree, 0);

            Assert.AreEqual("I", clause.Subject.Value);
            Assert.AreEqual("read the book", clause.Predicate.Value);
        }
Exemplo n.º 19
0
        public void GetSignature_NotFilled()
        {
            AdTree adTree = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.O2_I)
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.O1_I.SetLeftFirst())
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "read", EnglishAttributes.I), EnglishPattern.Morpheme(EnglishAttributes.I)),
                    Left  = new AdTree(new Morpheme(myAttributesModel, "I", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O)),
                },
                Left = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.EpsilonAdPosition("", "", EnglishAttributes.A, EnglishAttributes.O)
                                  .SetLeftFirst())
                {
                    // Note: O is not filled yet. The signature shall not contain it.
                    Right = null,
                    Left  = new AdTree(new Morpheme(myAttributesModel, "the", EnglishAttributes.A), EnglishPattern.Morpheme(EnglishAttributes.A))
                }
            };

            Assert.AreEqual("OIA", adTree.GetSignature());
        }
Exemplo n.º 20
0
        public void GetSignature()
        {
            AdTree adTree = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.O2_I)
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.O1_I.SetLeftFirst())
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "read", EnglishAttributes.I), EnglishPattern.Morpheme(EnglishAttributes.I)),
                    Left  = new AdTree(new Morpheme(myAttributesModel, "I", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O)),
                },
                Left = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.Epsilon), EnglishPattern.EpsilonAdPosition("", "", EnglishAttributes.A, EnglishAttributes.O).SetLeftFirst())
                {
                    Right = new AdTree(new Morpheme(myAttributesModel, "book", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O)),
                    Left  = new AdTree(new Morpheme(myAttributesModel, "the", EnglishAttributes.A), EnglishPattern.Morpheme(EnglishAttributes.A))
                }
            };

            Assert.AreEqual("OIAO", adTree.GetSignature());
        }
Exemplo n.º 21
0
        public void RulingGrammarCharacter_E()
        {
            AdTree adTree = new AdTree(new Morpheme(myAttributesModel, ".", EnglishAttributes.U), EnglishPattern.MorphematicAdPosition("I-U-I", "", EnglishAttributes.U.NonLexeme.PunctuationMark, EnglishAttributes.I.Lexeme, EnglishAttributes.I.Lexeme))
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "in", EnglishAttributes.E), EnglishPattern.MorphematicAdPosition("O-E-I", "", EnglishAttributes.E.Lexeme, EnglishAttributes.O.Lexeme, EnglishAttributes.I.Lexeme))
                {
                    Right = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.O1_I)
                    {
                        Right = new AdTree(new Morpheme(myAttributesModel, "read", EnglishAttributes.I), EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme)),
                        Left  = new AdTree(new Morpheme(myAttributesModel, "I", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme))
                    },
                    Left = new AdTree(new Morpheme(myAttributesModel, "in", EnglishAttributes.E), EnglishPattern.EpsilonAdPosition("A-O", "", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme))
                    {
                        Right = new AdTree(new Morpheme(myAttributesModel, "room", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme)),
                        Left  = new AdTree(new Morpheme(myAttributesModel, "the", EnglishAttributes.A), EnglishPattern.Morpheme(EnglishAttributes.A.Lexeme))
                    }
                }
            };

            // Although there is E in between but the ruling grammar character is I.
            Assert.AreEqual(GrammarCharacter.I, adTree.RulingGrammarCharacter);
        }