public void GetMetadata <TValue>(string kind, int col, ref TValue value)
 {
     _ectx.CheckParam(col == 0, nameof(col));
     if (kind == MetadataUtils.Kinds.SlotNames && _hasSlotNames)
     {
         _parentSchema.GetMetadata(kind, _featureCol, ref value);
     }
     else
     {
         throw MetadataUtils.ExceptGetMetadata();
     }
 }
예제 #2
0
                public void GetMetadata <TValue>(string kind, int col, ref TValue value)
                {
                    Contracts.CheckParam(0 <= col && col < ColumnCount, nameof(col));
                    var meta = _parent._columns[col].Metadata;
                    int mcol;

                    if (meta == null || !meta.Schema.TryGetColumnIndex(kind, out mcol))
                    {
                        throw MetadataUtils.ExceptGetMetadata();
                    }
                    // REVIEW: Again, since this is a shim, not going to sweat the potential for inappropriate exception message.
                    meta.GetGetter <TValue>(mcol)(ref value);
                }
예제 #3
0
 protected override void GetMetadataCore<TValue>(string kind, int iinfo, ref TValue value)
 {
     Contracts.Assert(0 <= iinfo && iinfo < InfoCount);
     switch (kind)
     {
         case MetadataUtils.Kinds.ScoreColumnSetId:
             _getScoreColumnSetId.Marshal(iinfo, ref value);
             break;
         default:
             if (iinfo < DerivedColumnCount)
                 throw MetadataUtils.ExceptGetMetadata();
             Mapper.OutputSchema.GetMetadata<TValue>(kind, iinfo - DerivedColumnCount, ref value);
             break;
     }
 }
예제 #4
0
                public void GetMetadata <TValue>(string kind, int col, ref TValue value)
                {
                    _ectx.CheckNonEmpty(kind, nameof(kind));
                    _ectx.CheckParam(0 <= col && col < ColumnCount, nameof(col));

                    if (kind == MetadataUtils.Kinds.SlotNames && _getSlotNamesDict.ContainsKey(_names[col]))
                    {
                        MetadataUtils.Marshal <VBuffer <ReadOnlyMemory <char> >, TValue>(GetSlotNames, col, ref value);
                    }
                    else if (kind == MetadataUtils.Kinds.KeyValues && _getKeyValuesDict.ContainsKey(_names[col]))
                    {
                        MetadataUtils.Marshal <VBuffer <ReadOnlyMemory <char> >, TValue>(GetKeyValues, col, ref value);
                    }
                    else
                    {
                        throw MetadataUtils.ExceptGetMetadata();
                    }
                }
예제 #5
0
        /// <summary>
        /// Assumes all columns have ScoreColumnKind and ScoreValueKind.
        /// </summary>
        public virtual void GetMetadata <TValue>(string kind, int col, ref TValue value)
        {
            Contracts.CheckNonEmpty(kind, nameof(kind));
            Contracts.CheckParam(0 <= col && col < ColumnCount, nameof(col));
            switch (kind)
            {
            case MetadataUtils.Kinds.ScoreColumnKind:
                ScoreColumnKindGetter.Marshal(col, ref value);
                break;

            case MetadataUtils.Kinds.ScoreValueKind:
                ScoreValueKindGetter.Marshal(col, ref value);
                break;

            default:
                throw MetadataUtils.ExceptGetMetadata();
            }
        }
예제 #6
0
        public override void GetMetadata <TValue>(string kind, int col, ref TValue value)
        {
            Contracts.CheckNonEmpty(kind, nameof(kind));
            Contracts.CheckParam(col == 0, nameof(col));
            switch (kind)
            {
            case MetadataUtils.Kinds.KeyValues:
                if (!HasKeyNames)
                {
                    throw MetadataUtils.ExceptGetMetadata();
                }
                _getKeyNames.Marshal(col, ref value);
                break;

            default:
                base.GetMetadata(kind, col, ref value);
                break;
            }
        }
        private void GetSlotNames(int iinfo, ref VBuffer <ReadOnlyMemory <char> > dst)
        {
            Host.Assert(0 <= iinfo && iinfo < Infos.Length);

            int size = _types[iinfo].VectorSize;

            if (size == 0)
            {
                throw MetadataUtils.ExceptGetMetadata();
            }

            var values = dst.Values;

            if (Utils.Size(values) < size)
            {
                values = new ReadOnlyMemory <char> [size];
            }

            var type = Infos[iinfo].TypeSrc;

            if (!type.IsVector)
            {
                Host.Assert(_types[iinfo].VectorSize == 2);
                var columnName = Source.Schema.GetColumnName(Infos[iinfo].Source);
                values[0] = columnName.AsMemory();
                values[1] = (columnName + IndicatorSuffix).AsMemory();
            }
            else
            {
                Host.Assert(type.IsKnownSizeVector);
                Host.Assert(size == 2 * type.VectorSize);

                // REVIEW: Do we need to verify that there is metadata or should we just call GetMetadata?
                var typeNames = Source.Schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.SlotNames, Infos[iinfo].Source);
                if (typeNames == null || typeNames.VectorSize != type.VectorSize || !typeNames.ItemType.IsText)
                {
                    throw MetadataUtils.ExceptGetMetadata();
                }

                var names = default(VBuffer <ReadOnlyMemory <char> >);
                Source.Schema.GetMetadata(MetadataUtils.Kinds.SlotNames, Infos[iinfo].Source, ref names);

                // We both assert and check. If this fails, there is a bug somewhere (possibly in this code
                // but more likely in the implementation of Base. On the other hand, we don't want to proceed
                // if we've received garbage.
                Host.Check(names.Length == type.VectorSize, "Unexpected slot name vector size");

                var sb   = new StringBuilder();
                int slot = 0;
                foreach (var kvp in names.Items(all: true))
                {
                    Host.Assert(0 <= slot && slot < size);
                    Host.Assert(slot % 2 == 0);

                    sb.Clear();
                    if (kvp.Value.IsEmpty)
                    {
                        sb.Append('[').Append(slot / 2).Append(']');
                    }
                    else
                    {
                        sb.AppendMemory(kvp.Value);
                    }

                    int len = sb.Length;
                    sb.Append(IndicatorSuffix);
                    var str = sb.ToString();

                    values[slot++] = str.AsMemory().Slice(0, len);
                    values[slot++] = str.AsMemory();
                }
                Host.Assert(slot == size);
            }

            dst = new VBuffer <ReadOnlyMemory <char> >(size, values, dst.Indices);
        }
예제 #8
0
 public void GetMetadata <TValue>(string kind, int col, ref TValue value)
 {
     throw MetadataUtils.ExceptGetMetadata();
 }
 protected virtual void GetMetadataCore <TValue>(string kind, int iinfo, ref TValue value)
 {
     Contracts.AssertNonEmpty(kind);
     Contracts.Assert(0 <= iinfo && iinfo < InfoCount);
     throw MetadataUtils.ExceptGetMetadata();
 }