Example #1
0
            public ColInfoEx(Column item, Arguments args)
            {
                NgramLength = item.NgramLength ?? args.NgramLength;
                Contracts.CheckUserArg(0 < NgramLength && NgramLength <= NgramBufferBuilder.MaxSkipNgramLength, nameof(item.NgramLength));
                SkipLength = item.SkipLength ?? args.SkipLength;
                Contracts.CheckUserArg(0 <= SkipLength && SkipLength <= NgramBufferBuilder.MaxSkipNgramLength, nameof(item.SkipLength));
                if (NgramLength + SkipLength > NgramBufferBuilder.MaxSkipNgramLength)
                {
                    throw Contracts.ExceptUserArg(nameof(item.SkipLength),
                                                  "The sum of skipLength and ngramLength must be less than or equal to {0}",
                                                  NgramBufferBuilder.MaxSkipNgramLength);
                }
                Contracts.CheckUserArg(Enum.IsDefined(typeof(WeightingCriteria), args.Weighting), nameof(args.Weighting));
                Weighting = item.Weighting ?? args.Weighting;

                NonEmptyLevels = new bool[NgramLength];
            }
Example #2
0
            public ColInfoEx(ModelLoadContext ctx, bool readWeighting)
            {
                Contracts.AssertValue(ctx);

                // *** Binary format ***
                // int: NgramLength
                // int: SkipLength
                // int: Weighting Criteria (if readWeighting == true)
                // bool[NgramLength]: NonEmptyLevels

                NgramLength = ctx.Reader.ReadInt32();
                Contracts.CheckDecode(0 < NgramLength && NgramLength <= NgramBufferBuilder.MaxSkipNgramLength);
                SkipLength = ctx.Reader.ReadInt32();
                Contracts.CheckDecode(0 <= SkipLength && SkipLength <= NgramBufferBuilder.MaxSkipNgramLength);
                Contracts.CheckDecode(NgramLength <= NgramBufferBuilder.MaxSkipNgramLength - SkipLength);

                if (readWeighting)
                {
                    Weighting = (WeightingCriteria)ctx.Reader.ReadInt32();
                }
                Contracts.CheckDecode(Enum.IsDefined(typeof(WeightingCriteria), Weighting));
                NonEmptyLevels = ctx.Reader.ReadBoolArray(NgramLength);
            }