public void Test_TrainTokenList_TrainsPartnersCorrectly()
        {
            var inputText = new TokenList("An interesting new sentence.");

            mockTokenMemoryManager.Object.TrainTokenList(inputText, mainToken, null);
            var existingTokens = mockTokenMemoryManager.Object.GetExisitingTokens(inputText, mainToken);
            var linkedTokens   = mockTokenMemoryManager.Object.GetExisitingTokens(inputText, mainToken);

            inputText.Invert();
            mockTokenMemoryManager.Object.TrainTokenList(inputText, backwardsMainToken, null, linkedTokens);
            var existingBackwardsTokens = mockTokenMemoryManager.Object.GetExisitingTokens(inputText, backwardsMainToken);

            var inputText2 = new TokenList("An interesting old sentence.");

            mockTokenMemoryManager.Object.TrainTokenList(inputText2, mainToken, null);
            linkedTokens = mockTokenMemoryManager.Object.GetExisitingTokens(inputText, mainToken);
            inputText.Invert();
            mockTokenMemoryManager.Object.TrainTokenList(inputText2, backwardsMainToken, null, linkedTokens);

            existingBackwardsTokens.Reverse();
            for (var i = 0; i < existingTokens.Count; i++)
            {
                Assert.AreEqual(existingTokens[i].PartnerID, existingBackwardsTokens[i].ID);
                Assert.AreEqual(existingBackwardsTokens[i].PartnerID, existingTokens[i].ID);
            }
        }
Ejemplo n.º 2
0
        public void TrainTokenList(TokenList tokenList)
        {
            var backwardsTokens = GetExisitingTokens(tokenList, GetForwardsRoot());

            tokenList.Invert();
            var forwardsTokens = GetExisitingTokens(tokenList, GetBackwardsRoot());

            if (forwardsTokens.Count == 0 || (backwardsTokens.Count != 0 && backwardsTokens.Count >= forwardsTokens.Count))
            {
                TrainTokenList(tokenList, GetBackwardsRoot(), null);
                var forwardsTokenLinks = GetExisitingTokens(tokenList, GetBackwardsRoot());
                tokenList.Invert();
                TrainTokenList(tokenList, GetForwardsRoot(), backwardsTokens, forwardsTokenLinks);
            }
            else
            {
                tokenList.Invert();
                TrainTokenList(tokenList, GetForwardsRoot(), null);
                var backwardsTokenLinks = GetExisitingTokens(tokenList, GetForwardsRoot());
                tokenList.Invert();
                TrainTokenList(tokenList, GetBackwardsRoot(), forwardsTokens, backwardsTokenLinks);
            }
        }