internal override unsafe void CreateTransformerFromEstimator(DateTimeEstimator.HolidayList country) { _transformerHandler = CreateTransformerFromEstimatorBase(country); }
private protected unsafe TransformerEstimatorSafeHandle CreateTransformerFromEstimatorBase(DateTimeEstimator.HolidayList country) { bool success; IntPtr errorHandle; IntPtr estimator; if (country == DateTimeEstimator.HolidayList.None) { success = CreateEstimatorHelper(null, null, out estimator, out errorHandle); } else { byte[] dataRoot; if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Data/DateTimeFeaturizer")) { dataRoot = Encoding.UTF8.GetBytes(AppDomain.CurrentDomain.BaseDirectory + char.MinValue); } else { dataRoot = Encoding.UTF8.GetBytes(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + char.MinValue); } fixed(byte *dataRootDir = dataRoot) fixed(byte *countryPointer = Encoding.UTF8.GetBytes(Enum.GetName(typeof(DateTimeEstimator.HolidayList), country) + char.MinValue)) { success = CreateEstimatorHelper(countryPointer, dataRootDir, out estimator, out errorHandle); } } if (!success) { throw new Exception(GetErrorDetailsAndFreeNativeMemory(errorHandle)); } using (var estimatorHandler = new TransformerEstimatorSafeHandle(estimator, DestroyEstimatorHelper)) { success = CreateTransformerFromEstimatorHelper(estimatorHandler, out IntPtr transformer, out errorHandle); if (!success) { throw new Exception(GetErrorDetailsAndFreeNativeMemory(errorHandle)); } return(new TransformerEstimatorSafeHandle(transformer, DestroyTransformerHelper)); } }
/// <summary> /// Create a <see cref="DateTimeEstimator"/>, which splits up the input column specified by <paramref name="inputColumnName"/> /// into all its individual datetime components. Input column must be of type Int64 representing the number of seconds since the unix epoc. /// This transformer will append the <paramref name="columnPrefix"/> to all the output columns. If you specify a country, /// Holiday details will be looked up for that country as well. /// </summary> /// <param name="catalog">Transform catalog</param> /// <param name="inputColumnName">Input column name</param> /// <param name="columnPrefix">Prefix to add to the generated columns</param> /// <param name="country">Country name to get holiday details for</param> /// <returns><see cref="DateTimeEstimator"/></returns> public static DateTimeEstimator FeaturizeDateTime(this TransformsCatalog catalog, string inputColumnName, string columnPrefix, DateTimeEstimator.HolidayList country = DateTimeEstimator.HolidayList.None) => new DateTimeEstimator(CatalogUtils.GetEnvironment(catalog), inputColumnName, columnPrefix, country);
internal abstract void CreateTransformerFromEstimator(DateTimeEstimator.HolidayList country);
internal DateTimeTransformer(IHostEnvironment host, string inputColumnName, string columnPrefix, DateTimeEstimator.HolidayList country) : base(host.Register(nameof(DateTimeTransformer))) { host.Check(!CommonExtensions.OsIsCentOS7(), "CentOS7 is not supported"); _column = new LongTypedColumn(inputColumnName, columnPrefix); _column.CreateTransformerFromEstimator(country); }
internal DateTimeTransformer(IHostEnvironment host, string inputColumnName, string columnPrefix, DateTimeEstimator.HolidayList country, DataViewSchema schema) : base(host.Register(nameof(DateTimeTransformer))) { host.Check(!CommonExtensions.OsIsCentOS7(), "CentOS7 is not supported"); _schema = schema; if (_schema[inputColumnName].Type.RawType != typeof(long) && _schema[inputColumnName].Type.RawType != typeof(DateTime)) { throw new Exception($"Unsupported type {_schema[inputColumnName].Type.RawType} for input column ${inputColumnName}. Only long and System.DateTime are supported"); } _column = new LongTypedColumn(inputColumnName, columnPrefix); _column.CreateTransformerFromEstimator(country); }