コード例 #1
0
        public void Test_Vector_Conversion_Simple_Numbers_And_Chars_As_Enum()
        {
            Descriptor d = new Descriptor();

            var dictionary = StringHelpers.BuildCharArray(ShortStrings);

            d.Features = new Property[]
            {
                new Property {
                    Name = "Age"
                },
                new Property {
                    Name = "Height"
                },
                new StringProperty {
                    Name       = "Chars",
                    Dictionary = dictionary,
                    SplitType  = StringSplitType.Character,
                    AsEnum     = true
                },
                new Property {
                    Name = "Weight"
                },
                new Property {
                    Name = "Good"
                },
            };

            // ["O",  "N",  "E", "#SYM#", "T", "W", "#NUM#", "H", "R"]
            // [  2,    1,   0,        1,   0,   0,       1,   0,   3]

            var o = new { Age = 23, Height = 6.21d, Chars = "N", Weight = 220m, Good = false, };

            // array generated by descriptor ordering
            var truths = new double[] { 23, 6.21,
                                        /* BEGIN CHARS */
                                        1,
                                        /* END CHARS */
                                        220, -1 };

            var actual = d.Convert(o);

            Assert.Equal(truths, actual);


            o = new { Age = 23, Height = 6.21d, Chars = "!", Weight = 220m, Good = false, };

            // array generated by descriptor ordering
            truths = new double[] { 23, 6.21,
                                    /* BEGIN CHARS */
                                    3,
                                    /* END CHARS */
                                    220, -1 };

            actual = d.Convert(o);
            Assert.Equal(truths, actual);
        }
コード例 #2
0
        public void Test_Char_Dictionary_Gen()
        {
            var d = StringHelpers.BuildCharArray(ShortStrings);
            // should have the following:
            // O, N, E, #SYM#, T, W, #NUM#, H, R
            var dict = new string[]
            {
                "O",
                "N",
                "E",
                "#SYM#",
                "T",
                "W",
                "#NUM#",
                "H",
                "R",
            };

            Assert.Equal(dict, d);
        }
コード例 #3
0
        /// <summary>Preprocess data set to create dictionary.</summary>
        /// <param name="examples">.</param>
        public override void PreProcess(IEnumerable <object> examples)
        {
            var q = from s in examples
                    select Ject.Get(s, Name).ToString();

            if (AsEnum)
            {
                Dictionary = StringHelpers.BuildEnumArray(q);
            }
            else
            {
                switch (SplitType)
                {
                case StringSplitType.Character:
                    Dictionary = StringHelpers.BuildCharArray(q, Exclude);
                    break;

                case StringSplitType.Word:
                    Dictionary = StringHelpers.BuildDistinctWordArray(q, Separator, Exclude);
                    break;
                }
            }
        }