Example #1
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);
        }
Example #2
0
        public void Number_of_people_say()
        {
            List <Pattern> patterns = new List <Pattern>()
            {
                EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme),
                EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme),

                EnglishPattern.O1_I.SetLeftFirst(),
                EnglishPattern.MorphematicAdPosition("O-E-O", "", EnglishAttributes.E.Lexeme.Preposition, EnglishAttributes.O.Lexeme, EnglishAttributes.O.Lexeme),
            };

            List <Morpheme> morphemes = new List <Morpheme>()
            {
                // Lexemes.
                new Morpheme(myAttributesModel, "number", EnglishAttributes.O.Lexeme.Noun),
                new Morpheme(myAttributesModel, "people", EnglishAttributes.O.Lexeme.Noun),
                new Morpheme(myAttributesModel, "say", EnglishAttributes.I.Lexeme.Verb),
                new Morpheme(myAttributesModel, "of", EnglishAttributes.E.Lexeme.Preposition),
            };

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

            AdTreeCreator  creator = new AdTreeCreator(dictionary);
            List <IAdTree> results = creator.Create("number", "of", "people", "say");

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("number", results[0].Left.Right.Morpheme.Morph);
            Assert.AreEqual("of", results[0].Left.Morpheme.Morph);
            Assert.AreEqual("people", results[0].Left.Left.Morpheme.Morph);
            Assert.AreEqual("say", results[0].Right.Morpheme.Morph);
        }
Example #3
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());
        }
Example #4
0
        public void CanAttachToLeft_MorphemicAdPosition()
        {
            IAdTree adTree = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.U.Lexeme.Conjunction),
                                        EnglishPattern.MorphematicAdPosition("O-U-O", "", EnglishAttributes.U.Lexeme.Conjunction, EnglishAttributes.O.Lexeme, EnglishAttributes.O.Lexeme).SetLeftFirst()
                                        );
            IAdTree adTreeElement = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), new Pattern()
            {
                UpRule = EnglishMorphemeRule.O_Lexeme
            });

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


            adTree = new AdTree(new Morpheme(myAttributesModel, "and", EnglishAttributes.U.Lexeme.Conjunction),
                                EnglishPattern.MorphematicAdPosition("O-U-O", "", EnglishAttributes.U.Lexeme.Conjunction, EnglishAttributes.O.Lexeme, EnglishAttributes.O.Lexeme)
                                )
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), new Pattern()
                {
                    UpRule = EnglishMorphemeRule.O_Lexeme
                })
            };
            adTreeElement = new AdTree(new Morpheme(myAttributesModel, "bike", EnglishAttributes.O.Lexeme), new Pattern()
            {
                UpRule = EnglishMorphemeRule.O_Lexeme
            });
            Assert.IsTrue(adTree.CanAttachToLeft(adTreeElement, myAttributesModel));


            // Note: the adposition morpheme is not set therefore it should not be allowsed to attach the second child.
            adTree = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.U.Lexeme.Conjunction),
                                EnglishPattern.MorphematicAdPosition("O-U-O", "", EnglishAttributes.U.Lexeme.Conjunction, EnglishAttributes.O.Lexeme, EnglishAttributes.O.Lexeme)
                                )
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), new Pattern()
                {
                    UpRule = EnglishMorphemeRule.O_Lexeme
                })
            };
            adTreeElement = new AdTree(new Morpheme(myAttributesModel, "bike", EnglishAttributes.O.Lexeme), new Pattern()
            {
                UpRule = EnglishMorphemeRule.O_Lexeme
            });
            Assert.IsFalse(adTree.CanAttachToLeft(adTreeElement, myAttributesModel));
        }
Example #5
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);
        }
Example #6
0
        public void Clauses_ComplexSentence()
        {
            var adTree = new AdTree(new Morpheme(myAttributesModel, ".", EnglishAttributes.U.NonLexeme.PunctuationMark), EnglishPattern.MorphematicAdPosition(".", "", EnglishAttributes.U.NonLexeme.PunctuationMark, EnglishAttributes.I.Lexeme, EnglishAttributes.I.Lexeme))
            {
                Right = new AdTree(new Morpheme(myAttributesModel, "and", EnglishAttributes.U.Lexeme.Conjunction.Coordinating), EnglishPattern.MorphematicAdPosition("I-U-I", "", EnglishAttributes.U.Lexeme.Conjunction.Coordinating, EnglishAttributes.I.Lexeme, EnglishAttributes.I.Lexeme))
                {
                    Right = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.O1_I.SetLeftFirst())
                    {
                        Right = new AdTree(new Morpheme(myAttributesModel, "read", EnglishAttributes.I.Lexeme.Verb), EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme)),
                        Left  = new AdTree(new Morpheme(myAttributesModel, "I", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme))
                    },
                    Left = new AdTree(Morpheme.Epsilon(myAttributesModel), EnglishPattern.O1_I.SetLeftFirst())
                    {
                        Right = new AdTree(new Morpheme(myAttributesModel, "learn", EnglishAttributes.I.Lexeme.Verb), EnglishPattern.Morpheme(EnglishAttributes.I.Lexeme)),
                        Left  = new AdTree(new Morpheme(myAttributesModel, "I", EnglishAttributes.O), EnglishPattern.Morpheme(EnglishAttributes.O.Lexeme))
                    }
                }
            };


            var factory  = new LinguisticStructureFactory(myAttributesModel);
            var sentence = factory.CreateSentence(adTree, 0);

            var clauses = sentence.Clauses.ToList();

            Assert.AreEqual(2, clauses.Count);
            Assert.AreEqual("I read", clauses[0].Value);

            Assert.AreEqual("I learn", clauses[1].Value);
        }
Example #7
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);
        }