Beispiel #1
0
        /// <summary>
        /// If any column names in <param name="colNames" /> are present in <param name="input" />, this
        /// method will create a transform that copies them to temporary columns. It will populate <param name="hiddenNames" />
        /// with an array of string pairs containing the original name and the generated temporary column name, respectively.
        /// </summary>
        /// <param name="env"></param>
        private static IDataView AliasIfNeeded(IHostEnvironment env, IDataView input, string[] colNames, out KeyValuePair <string, string>[] hiddenNames)
        {
            hiddenNames = null;
            var toHide = new List <string>(colNames.Length);

            foreach (var name in colNames)
            {
                int discard;
                if (input.Schema.TryGetColumnIndex(name, out discard))
                {
                    toHide.Add(name);
                }
            }

            if (toHide.Count == 0)
            {
                return(input);
            }

            hiddenNames = toHide.Select(colName =>
                                        new KeyValuePair <string, string>(colName, input.Schema.GetTempColumnName(colName))).ToArray();
            return(ColumnCopyingTransformer.Create(env, new ColumnCopyingTransformer.Arguments()
            {
                Column = hiddenNames.Select(pair => new ColumnCopyingTransformer.Column()
                {
                    Name = pair.Value, Source = pair.Key
                }).ToArray()
            }, input));
        }
Beispiel #2
0
        public static CommonOutputs.TransformOutput CopyColumns(IHostEnvironment env, ColumnCopyingTransformer.Arguments input)
        {
            Contracts.CheckValue(env, nameof(env));
            var host = env.Register("CopyColumns");

            host.CheckValue(input, nameof(input));
            EntryPointUtils.CheckInputArgs(host, input);
            var xf = ColumnCopyingTransformer.Create(env, input, input.Data);

            return(new CommonOutputs.TransformOutput {
                Model = new TransformModelImpl(env, xf, input.Data), OutputData = xf
            });
        }
Beispiel #3
0
        private static IDataView UnaliasIfNeeded(IHostEnvironment env, IDataView input, KeyValuePair <string, string>[] hiddenNames)
        {
            if (Utils.Size(hiddenNames) == 0)
            {
                return(input);
            }

            input = ColumnCopyingTransformer.Create(env, new ColumnCopyingTransformer.Arguments()
            {
                Column = hiddenNames.Select(pair => new ColumnCopyingTransformer.Column()
                {
                    Name = pair.Key, Source = pair.Value
                }).ToArray()
            }, input);

            return(ColumnSelectingTransformer.CreateDrop(env, input, hiddenNames.Select(pair => pair.Value).ToArray()));
        }