#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Problems.DataAnalysis.Symbolic; using HeuristicLab.Problems.DataAnalysis.Transformations; namespace HeuristicLab.DataPreprocessing { public class PreprocessingTransformator { private readonly ITransactionalPreprocessingData preprocessingData; public PreprocessingTransformator(IPreprocessingData preprocessingData) { this.preprocessingData = (ITransactionalPreprocessingData)preprocessingData; } public bool ApplyTransformations(IEnumerable transformations) { bool success = true; preprocessingData.InTransaction(() => { var doubleTransformations = transformations.OfType>().ToList(); ApplyDoubleTranformations(doubleTransformations, out success); }, DataPreprocessingChangedEventType.Transformation); if (!success) { // TODO: check undo remove transformations preprocessingData.Undo(); } return success; } private void ApplyDoubleTranformations(IEnumerable> transformations, out bool success) { foreach (var transformation in transformations) { int colIndex = preprocessingData.GetColumnIndex(transformation.Column); var originalData = preprocessingData.GetValues(colIndex); var transformedData = ApplyDoubleTransformation(transformation, originalData, out success); if (!success) return; preprocessingData.SetValues(colIndex, transformedData.ToList()); preprocessingData.Transformations.Add(transformation); } success = true; } private IEnumerable ApplyDoubleTransformation(Transformation transformation, IEnumerable data, out bool success) { string errorMsg; if (transformation.Check(data, out errorMsg)) { success = true; return transformation.Apply(data); } throw new NotImplementedException("Display Check Result"); } } }