コード例 #1
0
        public void TestCustomFeaturizer()
        {
            var context = new MyContext() { Feature = new CustomClass() { X = 5 }};
            using (var vw = new VowpalWabbit(""))
            {
                var serializer = VowpalWabbitSerializerFactory.CreateSerializer<MyContext>(new VowpalWabbitSettings(customFeaturizer: new List<Type> { typeof(CustomFeaturizer) }))
                    .Create(vw);

                var example = serializer.Serialize(context);

                Assert.IsNotNull(example);

                example.Dispose();
            }

            Assert.IsTrue(context.Feature.HasVisited);
        }
コード例 #2
0
        public void TestCustomFeaturizerOverideMethod()
        {
            var context = new MyContext() { Feature = new CustomClass() { X = 5 } };
            using (var vw = new VowpalWabbit(""))
            {
                var serializer = VowpalWabbitSerializerFactory.CreateSerializer<MyContext>(new VowpalWabbitSettings(allFeatures: new List<FeatureExpression>
                {
                    new FeatureExpression(typeof(CustomClass), "Feature",
                        // TODO: looks a bit awkward for an API. The compiler needs to know what property to access to copy the value into the Feature<T> object
                        valueExpression => Expression.Property(valueExpression, (PropertyInfo)ReflectionHelper.GetInfo((MyContext m) => m.Feature)),
                        overrideSerializeMethod: (MethodInfo)ReflectionHelper.GetInfo((CustomFeaturizer c) => c.MarshalFeature(null, null, null, null)))
                })).Create(vw);
                var example = serializer.Serialize(context);

                Assert.IsNotNull(example);

                example.Dispose();
            }

            Assert.IsTrue(context.Feature.HasVisited);
        }