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); }
public void CanAttachToLeft() { IAdTree adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), new Pattern() { LeftRule = EnglishMorphemeRule.O_Lexeme, } ); IAdTree adTreeElement = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), new Pattern() { UpRule = EnglishMorphemeRule.O_Lexeme }); Assert.IsTrue(adTree.CanAttachToLeft(adTreeElement, myAttributesModel)); // Primitive transference. adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), new Pattern() { LeftRule = EnglishMorphemeRule.A_Lexeme, } ); adTreeElement = new AdTree(new Morpheme(myAttributesModel, "", EnglishAttributes.A.Lexeme), EnglishPattern.MonoTransference("O>A", EnglishAttributes.A.Lexeme, EnglishAttributes.O.Lexeme)) { Right = new AdTree(new Morpheme(myAttributesModel, "car", EnglishAttributes.O.Lexeme), new Pattern() { UpRule = EnglishMorphemeRule.O_Lexeme }) }; Assert.IsTrue(adTree.CanAttachToLeft(adTreeElement, myAttributesModel)); adTree = new AdTree(Morpheme.Epsilon(myAttributesModel), new Pattern() { LeftRule = EnglishMorphemeRule.O_Lexeme, } ); adTreeElement = new AdTree(new Morpheme(myAttributesModel, "green", EnglishAttributes.A.Lexeme), new Pattern() { UpRule = EnglishMorphemeRule.A_Lexeme }); Assert.IsFalse(adTree.CanAttachToLeft(adTreeElement, myAttributesModel)); }
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 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); }
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); }