예제 #1
0
        private static void CheckJsonEquivalent(StringTokens tokens, TokenPredictor l, TokenPredictor r)
        {
            var lString = l.ToJson(tokens);
            var rString = r.ToJson(tokens);

            Assert.AreEqual(lString, rString);
        }
예제 #2
0
        /// <summary>
        /// Convert predictor to JSON.
        /// </summary>
        /// <param name="predictor"></param>
        /// <param name="tokens"></param>
        /// <returns></returns>
        public static string ToJson(this TokenPredictor predictor, StringTokens tokens)
        {
            var utf8 = predictor.ToJsonUtf8(tokens);

            var json = Encoding.UTF8.GetString(utf8);

            return(json);
        }
예제 #3
0
        /// <summary>
        /// Convert predictor to JSON.
        /// </summary>
        /// <param name="predictor"></param>
        /// <param name="tokens"></param>
        /// <returns></returns>
        public static byte[] ToJsonUtf8(this TokenPredictor predictor, StringTokens tokens)
        {
            var dictionary = predictor.ToJsonDictionary(tokens);

            var utf8 = JsonSerializer.SerializeToUtf8Bytes(dictionary);

            return(utf8);
        }
예제 #4
0
        public void CreateAlphabetTest()
        {
            var tokens    = new StringTokens();
            var predictor = new TokenPredictor(3);

            List <int> alphabet = GetAlphabet(tokens);

            predictor.AddSequence(alphabet, 1);

            var json = predictor.ToJson(tokens);

            Assert.AreEqual(AlphabetJson, json);
        }
예제 #5
0
        public void CreateAlphabetLetterByLetterTest()
        {
            var tokens    = new StringTokens();
            var predictor = new TokenPredictor(3);

            var alphabet = GetAlphabet(tokens);

            var incrementalAlphabet = new List <int>();

            foreach (var token in alphabet)
            {
                incrementalAlphabet.Add(token);
                predictor.AddSequenceTail(incrementalAlphabet, 1);
            }

            var json = predictor.ToJson(tokens);

            Assert.AreEqual(AlphabetJson, json);
        }
예제 #6
0
        public void BuildSeedPredictor()
        {
            var tokens     = new StringTokens();
            var predictor1 = new TokenPredictor(3);
            var predictor2 = new TokenPredictor(3);
            var predictor3 = new TokenPredictor(3);

            var predictor1plus2 = predictor1.CreateCopy();

            CheckJsonEquivalent(tokens, predictor1plus2, predictor1);
            predictor1plus2.Add(predictor2);
            CheckJsonEquivalent(tokens, predictor1plus2, predictor3);

            var predictor3minus2 = predictor3.CreateCopy();

            CheckJsonEquivalent(tokens, predictor3minus2, predictor3);
            predictor3minus2.Subtract(predictor2);
            CheckJsonEquivalent(tokens, predictor3minus2, predictor1);

            predictor3minus2.Subtract(predictor1);
            var predictor0 = predictor1.CreateEmpty();

            CheckJsonEquivalent(tokens, predictor3minus2, predictor0);
        }