Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="VowpalWabbitJsonBuilder"/>.
        /// </summary>
        public VowpalWabbitJsonBuilder(VowpalWabbitJsonSerializer serializer, IVowpalWabbitExamplePool vwPool, VowpalWabbitDefaultMarshaller defaultMarshaller, JsonSerializer jsonSerializer, int multiIndex = -1)
        {
            Contract.Requires(serializer != null);
            Contract.Requires(vw != null);
            Contract.Requires(defaultMarshaller != null);
            Contract.Requires(jsonSerializer != null);

            this.extensionState = new VowpalWabbitJsonParseState
            {
                JsonBuilder = this,
                VW          = vwPool.Native,
                MultiIndex  = multiIndex
            };

            this.namespaceStrings = new List <string>();
            this.foundMulti       = false;
            if (serializer != null)
            {
                this.referenceResolver = serializer.ReferenceResolver;
            }
            this.serializer        = serializer;
            this.vw                = vwPool.Native;
            this.defaultMarshaller = defaultMarshaller;
            this.jsonSerializer    = jsonSerializer;

            this.DefaultNamespaceContext = new VowpalWabbitMarshalContext(this.vw);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VowpalWabbitJson"/> class.
        /// </summary>
        /// <param name="vw">The VW native instance.</param>
        public VowpalWabbitJsonSerializer(IVowpalWabbitExamplePool vwPool)
        {
            Contract.Requires(vwPool != null);

            this.vwPool            = vwPool;
            this.defaultMarshaller = new VowpalWabbitDefaultMarshaller();
            this.jsonSerializer    = new JsonSerializer();

            this.ExampleBuilder = new VowpalWabbitJsonBuilder(this.vwPool, this.defaultMarshaller, this.jsonSerializer);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VowpalWabbitJson"/> class.
        /// </summary>
        /// <param name="vw">The VW native instance.</param>
        public VowpalWabbitJsonSerializer(VowpalWabbit vw)
        {
            Contract.Requires(vw != null);

            this.vw = vw;
            this.defaultMarshaller = new VowpalWabbitDefaultMarshaller();
            this.jsonSerializer    = new JsonSerializer();

            this.ExampleBuilder = new VowpalWabbitJsonBuilder(vw, this.defaultMarshaller, this.jsonSerializer);
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VowpalWabbitJson"/> class.
        /// </summary>
        /// <param name="vw">The VW native instance.</param>
        public VowpalWabbitJsonSerializer(IVowpalWabbitExamplePool vwPool, VowpalWabbitJsonReferenceResolver referenceResolver = null)
        {
            Contract.Requires(vwPool != null);

            this.vwPool            = vwPool;
            this.referenceResolver = referenceResolver;
            this.defaultMarshaller = VowpalWabbitDefaultMarshaller.Instance;
            this.jsonSerializer    = new JsonSerializer();

            this.ExampleBuilder = new VowpalWabbitJsonBuilder(this, this.vwPool, this.defaultMarshaller, this.jsonSerializer);
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of <see cref="VowpalWabbitJsonBuilder"/>.
        /// </summary>
        public VowpalWabbitJsonBuilder(IVowpalWabbitExamplePool vwPool, VowpalWabbitDefaultMarshaller defaultMarshaller, JsonSerializer jsonSerializer)
        {
            Contract.Requires(vw != null);
            Contract.Requires(defaultMarshaller != null);
            Contract.Requires(jsonSerializer != null);

            this.vw = vwPool.Native;
            this.defaultMarshaller = new VowpalWabbitDefaultMarshaller();
            this.jsonSerializer    = new JsonSerializer();

            this.Context = new VowpalWabbitMarshalContext(vwPool);
            this.DefaultNamespaceContext = new VowpalWabbitMarshalContext(this.vw, this.Context.ExampleBuilder);
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of <see cref="VowpalWabbitJsonBuilder"/>.
        /// </summary>
        public VowpalWabbitJsonBuilder(VowpalWabbitJsonSerializer serializer, IVowpalWabbitExamplePool vwPool, VowpalWabbitDefaultMarshaller defaultMarshaller, JsonSerializer jsonSerializer)
        {
            Contract.Requires(serializer != null);
            Contract.Requires(vw != null);
            Contract.Requires(defaultMarshaller != null);
            Contract.Requires(jsonSerializer != null);

            this.namespaceStrings  = new List <string>();
            this.referenceResolver = serializer.ReferenceResolver;
            this.serializer        = serializer;
            this.vw = vwPool.Native;
            this.defaultMarshaller = defaultMarshaller;
            this.jsonSerializer    = jsonSerializer;

            this.DefaultNamespaceContext = new VowpalWabbitMarshalContext(this.vw);
        }
 public void Marshal(VowpalWabbitDefaultMarshaller defaultMarshaller, VowpalWabbitMarshalContext context, Namespace ns, string featureName)
 {
     this.marshal(defaultMarshaller, context, ns, featureName, this.data);
 }
        internal static void Marshal(VowpalWabbitDefaultMarshaller defaultMarshaller, VowpalWabbitMarshalContext context, Namespace ns, string featureName, float[] values, int length)
        {
            var feature = new Feature(featureName);

            defaultMarshaller.MarshalFeature(context, ns, feature, values, 0, length);
        }
        internal static void Marshal(VowpalWabbitDefaultMarshaller defaultMarshaller, VowpalWabbitMarshalContext context, Namespace ns, string featureName, long val)
        {
            var feature = new PreHashedFeature(context.VW, ns, featureName);

            defaultMarshaller.MarshalFeature(context, ns, feature, val);
        }
        internal static void Marshal(VowpalWabbitDefaultMarshaller defaultMarshaller, VowpalWabbitMarshalContext context, Namespace ns, string featureName, string val)
        {
            var feature = new Feature(featureName);

            defaultMarshaller.MarshalFeatureStringEscapeAndIncludeName(context, ns, feature, val);
        }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of <see cref="VowpalWabbitJsonBuilder"/>.
 /// </summary>
 public VowpalWabbitJsonBuilder(IVowpalWabbitExamplePool vwPool, VowpalWabbitDefaultMarshaller defaultMarshaller, JsonSerializer jsonSerializer, int multiIndex = -1)
     : this(null, vwPool, defaultMarshaller, jsonSerializer, multiIndex)
 {
 }