/// <summary> /// Gets the categories names. /// </summary> /// <param name="categories">The categories.</param> /// <param name="maxCategoriesNames">The max categories names.</param> /// <returns> /// Names of categories. (or empty array of strings if /// count of categories is greater than specified /// <c>maxCategoriesNames</c>) /// </returns> public static string[] GetCategoriesNames(CategoriesStruct categories, long maxCategoriesNames) { long count = GetCategoriesCount(categories); if ((maxCategoriesNames > 0 && count > maxCategoriesNames) || (count == 0)) return new string[0]; int actualCount = 0; string[] result = new string[count]; if (categories.dateTimeIntervals != null) { categories.dateTimeIntervals.Keys.CopyTo(result, actualCount); actualCount += categories.dateTimeIntervals.Count; } if (categories.floatIntervals != null) { categories.floatIntervals.Keys.CopyTo(result, actualCount); actualCount += categories.floatIntervals.Count; } if (categories.longIntervals != null) { categories.longIntervals.Keys.CopyTo(result, actualCount); actualCount += categories.longIntervals.Count; } if (categories.enums != null) { categories.enums.Keys.CopyTo(result, actualCount); actualCount += categories.enums.Count; } return result; }
/// <summary> /// Initializes a new instance of the <see cref="GeneratedAttribute"/> class. /// </summary> public GeneratedAttribute() { this.categoriesStruct = new CategoriesStruct(); this.categoriesCount = 0; this.includeNullCategoryName = String.Empty; this.categoriesNames = new SelectString[0]; }
/// <summary> /// Gets the setting for new attribute box. /// </summary> /// <param name="categoriesStruct">The categories struct.</param> /// <param name="xCategory">The x category.</param> /// <param name="includeNullCategory">The include null category.</param> /// <param name="nameInLiterals">The name in literals.</param> /// <returns>Property settings for new derived attribute box module.</returns> public static PropertySetting[] GetSettingForNewAttributeBox(CategoriesStruct categoriesStruct, string xCategory, string includeNullCategory, string nameInLiterals) { PropertySetting categoriesProperty = new PropertySetting(); categoriesProperty.propertyName = "Categories"; categoriesProperty.value = new CategoriesTI(categoriesStruct); /* PropertySetting countOfCategoriesProperty = new PropertySetting(); countOfCategoriesProperty.propertyName = "CountOfCategories"; countOfCategoriesProperty.result = new Ferda.Modules.LongTI(countOfCategories); */ PropertySetting xCategoryProperty = new PropertySetting(); xCategoryProperty.propertyName = "XCategory"; xCategoryProperty.value = new Ferda.Modules.StringTI(xCategory); PropertySetting includeNullProperty = new PropertySetting(); includeNullProperty.propertyName = "IncludeNullCategory"; includeNullProperty.value = new Ferda.Modules.StringTI(includeNullCategory); PropertySetting nameInLiteralsProperty = new PropertySetting(); nameInLiteralsProperty.propertyName = "NameInLiterals"; nameInLiteralsProperty.value = new Ferda.Modules.StringTI(nameInLiterals); return new PropertySetting[] { categoriesProperty, xCategoryProperty, includeNullProperty, nameInLiteralsProperty }; }
/// <summary> /// Initializes a new instance of the <see cref="GeneratedAttribute"/> class. /// </summary> /// <param name="categoriesStruct">The categories struct.</param> /// <param name="includeNullCategoryName">Name of the include null category.</param> public GeneratedAttribute(CategoriesStruct categoriesStruct, string includeNullCategoryName) { this.categoriesStruct = categoriesStruct; this.categoriesCount = Ferda.Modules.Helpers.Data.Attribute.GetCategoriesCount(categoriesStruct); this.includeNullCategoryName = includeNullCategoryName; this.categoriesNames = Ferda.Modules.Boxes.BoxInfoHelper.StringArrayToSelectStringArray( Ferda.Modules.Helpers.Data.Attribute.GetCategoriesNames( categoriesStruct, Ferda.Modules.Boxes.DataMiningCommon.Attributes.AbstractAttributeConstants.MaxLengthOfCategoriesNamesSelectStringArray ) ); }
/// <summary> /// Gets the categories count. /// </summary> /// <param name="categories">The categories.</param> /// <returns>Categories count.</returns> public static long GetCategoriesCount(CategoriesStruct categories) { long result = 0; if (categories != null) { if (categories.enums != null) result += categories.enums.Count; if (categories.longIntervals != null) result += categories.longIntervals.Count; if (categories.floatIntervals != null) result += categories.floatIntervals.Count; if (categories.dateTimeIntervals != null) result += categories.dateTimeIntervals.Count; } return result; }
/// <summary> /// Generates the attribute. /// </summary> /// <param name="connectionString">The connection string.</param> /// <param name="dataMatrixName">Name of the data matrix.</param> /// <param name="columnSelectExpression">The column select expression.</param> /// <param name="boxIdentity">The box identity.</param> /// <returns>Generated attribute.</returns> public static GeneratedAttribute Generate( string connectionString, string dataMatrixName, string columnSelectExpression, string boxIdentity) { DataTable dataTable = Ferda.Modules.Helpers.Data.Column.GetDistincts(connectionString, dataMatrixName, columnSelectExpression, boxIdentity); CategoriesStruct categoriesStructValue = new CategoriesStruct(); List<SelectString> categoriesNames = new List<SelectString>(); categoriesStructValue.enums = new EnumCategorySeq(); string rowValue; string categoryName; SelectString item; bool getNames = (dataTable.Rows.Count <= AbstractAttributeConstants.MaxLengthOfCategoriesNamesSelectStringArray); string includeNullCategoryNameValue = null; foreach (DataRow dataRow in dataTable.Rows) { rowValue = dataRow.ItemArray[0].ToString(); if (String.IsNullOrEmpty(rowValue)) { categoryName = Ferda.Modules.Helpers.Common.Constants.DbNullCategoryName; includeNullCategoryNameValue = categoryName; } else { categoryName = rowValue; } categoriesStructValue.enums.Add(categoryName, new string[1] { rowValue }); if (getNames) { item = new SelectString(); item.label = categoryName; item.name = categoryName; categoriesNames.Add(item); } } GeneratedAttribute output = new GeneratedAttribute( categoriesStructValue, includeNullCategoryNameValue, categoriesStructValue.enums.Count, categoriesNames.ToArray()); return output; }
public static Categories Dict2Struct(CategoriesStruct categories) { Categories result = new Categories(); List<Categories.DateTimeCategory> dateTimeCategories = new List<Categories.DateTimeCategory>(); List<Categories.FloatCategory> floatCategories = new List<Categories.FloatCategory>(); List<Categories.LongCategory> longCategories = new List<Categories.LongCategory>(); List<Categories.EnumCategory> enumCategories = new List<Categories.EnumCategory>(); if (categories.dateTimeIntervals != null) foreach (DictionaryEntry category in categories.dateTimeIntervals) { dateTimeCategories.Add(new Categories.DateTimeCategory((string)category.Key, (DateTimeIntervalStruct[])category.Value)); } if (categories.floatIntervals != null) foreach (DictionaryEntry category in categories.floatIntervals) { floatCategories.Add(new Categories.FloatCategory((string)category.Key, (FloatIntervalStruct[])category.Value)); } if (categories.longIntervals != null) foreach (DictionaryEntry category in categories.longIntervals) { /* * System.InvalidCastException: Specified cast is not valid. * at Ferda.Modules.CategoriesTI.Categories.Dict2Struct(CategoriesStruct categories) in e:\Saves\Projekt\svn\src\PropertyTypes\CategoriesTI.cs:line 73 * at Ferda.Modules.CategoriesTI.getValueT() in e:\Saves\Projekt\svn\src\PropertyTypes\CategoriesTI.cs:line 122 * at Ferda.ProjectManager.ProjectManager.SaveProject(Stream stream) in e:\Saves\Projekt\svn\src\ProjectManager\ProjectManager.cs:line 356 * */ longCategories.Add(new Categories.LongCategory((string)category.Key, (LongIntervalStruct[])category.Value)); } if (categories.enums != null) foreach (DictionaryEntry category in categories.enums) { enumCategories.Add(new Categories.EnumCategory((string)category.Key, (string[])category.Value)); } result.DateTimes = dateTimeCategories.ToArray(); result.Floats = floatCategories.ToArray(); result.Longs = longCategories.ToArray(); result.Enums = enumCategories.ToArray(); return result; }
/// <summary> /// Method for counting categories frequences /// </summary> /// <returns></returns> public ArrayList GetCategoriesFrequences(CategoriesStruct categories) { ArrayList returnList = new ArrayList(); bool everything = false; foreach (DictionaryEntry singleEnum in categories.enums) { String[] stringSeq = (String[])singleEnum.Value; CategoryFrequency newEntry = new CategoryFrequency(); if (!everything) { String whereQuery = this.GetWhereClauseForEnum(stringSeq, this.columnSelectExpression); DataTable tempTable = this.GetQueryResultTable(this.GetValueCountQuery(whereQuery)); newEntry.key = singleEnum.Key.ToString(); try { foreach (DataRow row in tempTable.Rows) { newEntry.count += Convert.ToInt64(row[1]); } } catch { newEntry.count = 0; } } else { newEntry.key = singleEnum.Key.ToString(); newEntry.count = 0; } returnList.Add(newEntry); } foreach (DictionaryEntry singleLong in categories.longIntervals) { LongIntervalStruct[] longSeq = (LongIntervalStruct[])singleLong.Value; CategoryFrequency newEntry = new CategoryFrequency(); if (!everything) { String whereQuery = this.GetWhereClauseLong(longSeq, this.columnSelectExpression); if (!whereQuery.Equals("")) { DataTable tempTable = this.GetQueryResultTable(this.GetValueCountQuery(whereQuery)); newEntry.key = singleLong.Key.ToString(); try { foreach (DataRow row in tempTable.Rows) { newEntry.count += Convert.ToInt64(row[1]); } } catch { newEntry.count = 0; } } else { newEntry.key = singleLong.Key.ToString(); newEntry.count = this.rowCount; everything = true; } } else { newEntry.key = singleLong.Key.ToString(); newEntry.count = 0; } returnList.Add(newEntry); } foreach (DictionaryEntry singleFloat in categories.floatIntervals) { FloatIntervalStruct[] floatSeq = (FloatIntervalStruct[])singleFloat.Value; CategoryFrequency newEntry = new CategoryFrequency(); if (!everything) { String whereQuery = this.GetWhereClauseFloat(floatSeq, this.columnSelectExpression); if (!whereQuery.Equals("")) { DataTable tempTable = this.GetQueryResultTable(this.GetValueCountQuery(whereQuery)); newEntry.key = singleFloat.Key.ToString(); try { foreach (DataRow row in tempTable.Rows) { newEntry.count += Convert.ToInt64(row[1]); } } catch { newEntry.count = 0; } } else { newEntry.key = singleFloat.Key.ToString(); newEntry.count = this.rowCount; everything = true; } } else { newEntry.key = singleFloat.Key.ToString(); newEntry.count = 0; } returnList.Add(newEntry); } foreach (DictionaryEntry singleDateTime in categories.dateTimeIntervals) { DateTimeIntervalStruct[] dateTimeSeq = (DateTimeIntervalStruct[])singleDateTime.Value; CategoryFrequency newEntry = new CategoryFrequency(); if (!everything) { String whereQuery = this.GetWhereClauseDateTime(dateTimeSeq, this.columnSelectExpression); if (!whereQuery.Equals("")) { DataTable tempTable = this.GetQueryResultTable(this.GetValueCountQuery(whereQuery)); newEntry.key = singleDateTime.Key.ToString(); try { foreach (DataRow row in tempTable.Rows) { newEntry.count += Convert.ToInt64(row[1]); } } catch { newEntry.count = 0; } } else { newEntry.key = singleDateTime.Key.ToString(); newEntry.count = this.rowCount; everything = true; } } else { newEntry.key = singleDateTime.Key.ToString(); newEntry.count = 0; } returnList.Add(newEntry); } return returnList; }
/// <summary> /// Initializes a new instance of the <see cref="GeneratedAttribute"/> class. /// </summary> /// <param name="categoriesStruct">The categories struct.</param> /// <param name="includeNullCategoryName">Name of the include null category.</param> /// <param name="categoriesCount">The categories count.</param> /// <param name="categoriesNames">The categories names.</param> public GeneratedAttribute(CategoriesStruct categoriesStruct, string includeNullCategoryName, long categoriesCount, SelectString[] categoriesNames) { this.categoriesStruct = categoriesStruct; this.categoriesCount = categoriesCount; this.includeNullCategoryName = includeNullCategoryName; this.categoriesNames = categoriesNames; }
/// <summary> /// Handler of EditCategoriesList disposing; retrieves edited categories. /// </summary> /// <param name="sender">EditCategoriesListView</param> /// <param name="e"></param> private void SetCategories(object sender, EventArgs e) { Ferda.FrontEnd.AddIns.EditCategories.MainListView listView = (Ferda.FrontEnd.AddIns.EditCategories.MainListView)sender; this.categories = listView.GetUpdatedCategories(); }
/// <summary> /// Method which closes the window and returns the modified categories. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveAndQuit_Click(object sender, EventArgs e) { CategoriesStruct categories = new CategoriesStruct(); try { this.returnCategories = this.MyIceRunOut(this.bigDataList); } catch (System.ApplicationException) { MessageBox.Show(resManager.GetString("SameCategoryNames"), resManager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } categories = this.returnCategories; DialogResult = DialogResult.OK; this.Dispose(); }
/// <summary> /// Method to convert SmartDataList to CategoriesStruct structure. /// </summary> /// <param name="dataList"></param> /// <returns></returns> private CategoriesStruct MyIceRunOut(FerdaSmartDataList dataList) { CategoriesStruct myCategoriesStruct = new CategoriesStruct(); myCategoriesStruct.dateTimeIntervals = new DateTimeIntervalCategorySeq(); myCategoriesStruct.enums = new EnumCategorySeq(); myCategoriesStruct.floatIntervals = new FloatIntervalCategorySeq(); myCategoriesStruct.longIntervals = new LongIntervalCategorySeq(); ArrayList tempArray = new ArrayList(); foreach (Category multiSet in dataList.Categories) { switch (multiSet.CatType) { case CategoryType.Interval: foreach (Interval interval in multiSet.GetIntervals()) { if (interval.intervalType == IntervalType.Long) { LongIntervalStruct newLong = new LongIntervalStruct(); newLong.leftBound = interval.lowerBound; newLong.rightBound = interval.upperBound; if (interval.lowerBoundType == IntervalBoundType.Round) { newLong.leftBoundType = BoundaryEnum.Round; } else { if (interval.lowerBoundType == IntervalBoundType.Sharp) { newLong.leftBoundType = BoundaryEnum.Sharp; } else { newLong.leftBoundType = BoundaryEnum.Infinity; } } if (interval.upperBoundType == IntervalBoundType.Round) { newLong.rightBoundType = BoundaryEnum.Round; } else { if (interval.upperBoundType == IntervalBoundType.Sharp) { newLong.rightBoundType = BoundaryEnum.Sharp; } else { newLong.rightBoundType = BoundaryEnum.Infinity; } } tempArray.Add(newLong); } else { if (interval.intervalType == IntervalType.Float) { FloatIntervalStruct newFloat = new FloatIntervalStruct(); newFloat.leftBound = interval.lowerBoundFl; newFloat.rightBound = interval.upperBoundFl; if (interval.lowerBoundType == IntervalBoundType.Round) { newFloat.leftBoundType = BoundaryEnum.Round; } else { if (interval.lowerBoundType == IntervalBoundType.Sharp) { newFloat.leftBoundType = BoundaryEnum.Sharp; } else { newFloat.leftBoundType = BoundaryEnum.Infinity; } } if (interval.upperBoundType == IntervalBoundType.Round) { newFloat.rightBoundType = BoundaryEnum.Round; } else { if (interval.upperBoundType == IntervalBoundType.Sharp) { newFloat.rightBoundType = BoundaryEnum.Sharp; } else { newFloat.rightBoundType = BoundaryEnum.Infinity; } } tempArray.Add(newFloat); } } } if (multiSet.GetIntervalType() == IntervalType.Long) { myCategoriesStruct.longIntervals.Add(multiSet.Name, (LongIntervalStruct[])tempArray.ToArray(typeof(LongIntervalStruct))); tempArray.Clear(); } else { if (multiSet.GetIntervalType() == IntervalType.Float) { myCategoriesStruct.floatIntervals.Add(multiSet.Name, (FloatIntervalStruct[])tempArray.ToArray(typeof(FloatIntervalStruct))); tempArray.Clear(); } } break; case CategoryType.Enumeration: tempArray = multiSet.Set.Values; String[] tempString = new String[tempArray.Count]; for (int i = 0; i < tempArray.Count; i++) { tempString[i] = tempArray[i].ToString(); } try { myCategoriesStruct.enums.Add(multiSet.Name, tempString); } catch (System.ArgumentException) { throw (new System.ApplicationException()); } tempArray.Clear(); break; default: break; } } return myCategoriesStruct; }
/// <summary> /// Contructor which creates editcategories instance and fills in the needed values /// </summary> /// <param name="localePrefs">Current locale</param> /// <param name="categories">Categories to edit</param> /// <param name="distinctValues">Distinct values for enum categories</param> public MainListView(string[] localePrefs, CategoriesStruct categories, string[] distinctValues, IOwnerOfAddIn ownerOfAddin) { //setting the ResManager resource manager and localization string string locale; try { locale = localePrefs[0]; localizationString = locale; locale = "Ferda.FrontEnd.AddIns.EditCategories.Localization_" + locale; resManager = new ResourceManager(locale, Assembly.GetExecutingAssembly()); } catch { this.resManager = new ResourceManager("Ferda.FrontEnd.AddIns.EditCategories.Localization_en-US", Assembly.GetExecutingAssembly()); localizationString = "en-US"; } this.distinctValues = distinctValues; this.ownerOfAdd = ownerOfAddin; this.path = Assembly.GetExecutingAssembly().Location; InitializeComponent(); this.ChangeLocale(this.resManager); bigDataList = this.MyIceRun(categories); FillEditCategoriesListView(CategoriesListView); //adding a handling method for column sorting this.CategoriesListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView1_ColumnClick); this.LoadIcons(); this.InitIcons(); }
/// <summary> /// Tests the categories disjunctivity. /// </summary> /// <param name="categories">The categories.</param> /// <param name="boxIdentity">The box identity.</param> /// <exception cref="T:Ferda.Modules.BadValueError">Thrown iff categories are not disjunctive.</exception> public static void TestCategoriesDisjunctivity(CategoriesStruct categories, string boxIdentity) { //TODO testCategoriesDisjunctivity bool allDisjunkt = true; if (!allDisjunkt) { throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, "Categories are not disjunktive!", null, Ferda.Modules.restrictionTypeEnum.Other); } }
private static GeneratedAttribute generateIntegral(long from, long to, SidesEnum closedFrom, long length, ColumnInfo column) { LongIntervalStruct intervalTemplate = new LongIntervalStruct(); char leftBound, rightBound; switch (closedFrom) { case SidesEnum.Left: intervalTemplate.leftBoundType = BoundaryEnum.Sharp; intervalTemplate.rightBoundType = BoundaryEnum.Round; leftBound = Constants.LeftClosedInterval; rightBound = Constants.RightOpenedInterval; break; case SidesEnum.Right: intervalTemplate.leftBoundType = BoundaryEnum.Round; intervalTemplate.rightBoundType = BoundaryEnum.Sharp; leftBound = Constants.LeftOpenedInterval; rightBound = Constants.RightClosedInterval; break; default: throw Ferda.Modules.Exceptions.SwitchCaseNotImplementedError(closedFrom); } CategoriesStruct result = new CategoriesStruct(); result.longIntervals = new LongIntervalCategorySeq(); long fromTmp = from; long toTmp = ((fromTmp + length) > to) ? to : fromTmp + length; for (; ; ) { LongIntervalStruct interval = intervalTemplate; interval.leftBound = fromTmp; interval.rightBound = toTmp; result.longIntervals.Add( leftBound + fromTmp.ToString() + Constants.SeparatorInterval + toTmp.ToString() + rightBound, new LongIntervalStruct[] { interval }); if (toTmp == to) break; fromTmp = toTmp; toTmp = ((toTmp + length) > to) ? to : toTmp + length; } return new GeneratedAttribute( result, null, result.longIntervals.Count); }
/// <summary> /// Generates the the attribute. /// </summary> /// <param name="domainType">Type of the domain.</param> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <param name="countOfCategories">The count of categories.</param> /// <param name="columnInfo">The column info.</param> /// <param name="boxIdentity">The box identity.</param> /// <returns>Generated attribute.</returns> public static GeneratedAttribute Generate( AttributeDomainEnum domainType, double from, double to, long countOfCategories, Ferda.Modules.Boxes.DataMiningCommon.Column.ColumnInfo columnInfo, string boxIdentity) { Ferda.Modules.Helpers.Data.Column.ValueType simpleColumnType = Ferda.Modules.Helpers.Data.Column.GetColumnValueTypeByValueSubType(columnInfo.columnSubType); if (simpleColumnType != Ferda.Modules.Helpers.Data.Column.ValueType.Integral && simpleColumnType != Ferda.Modules.Helpers.Data.Column.ValueType.Floating) throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType); //dataArray.Add(new Data(currentValue, currentCount)); ArrayList dataArray = new ArrayList(); DataTable frequencies = null; float startValue = Convert.ToSingle(columnInfo.statistics.ValueMin); float endValue = Convert.ToSingle(columnInfo.statistics.ValueMax); switch (domainType) { case AttributeDomainEnum.WholeDomain: frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies( columnInfo.dataMatrix.database.odbcConnectionString, columnInfo.dataMatrix.dataMatrixName, columnInfo.columnSelectExpression, boxIdentity); from = to = 0; break; case AttributeDomainEnum.SubDomainValueBounds: frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies( columnInfo.dataMatrix.database.odbcConnectionString, columnInfo.dataMatrix.dataMatrixName, columnInfo.columnSelectExpression, columnInfo.columnSelectExpression + ">=" + from + " AND " + columnInfo.columnSelectExpression + "<=" + to, boxIdentity); startValue = (float)from; endValue = (float)to; from = to = 0; break; case AttributeDomainEnum.SubDomainNumberOfValuesBounds: frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies( columnInfo.dataMatrix.database.odbcConnectionString, columnInfo.dataMatrix.dataMatrixName, columnInfo.columnSelectExpression, boxIdentity); break; default: throw Ferda.Modules.Exceptions.SwitchCaseNotImplementedError(domainType); } if (from < 0) { throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, null, new string[] { "From" }, restrictionTypeEnum.Minimum); } if (to < 0) { throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, null, new string[] { "To" }, restrictionTypeEnum.Minimum); } int fromUi = (int)from; int toUi = (int)to; int frequenciesCount = frequencies.Rows.Count; if (frequenciesCount <= from + to) return new GeneratedAttribute(); object item; switch (simpleColumnType) { case Ferda.Modules.Helpers.Data.Column.ValueType.Floating: for (int i = fromUi; i < (frequenciesCount - toUi); i++) { item = frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectDistincts]; if (item == System.DBNull.Value) continue; dataArray.Add(new EquifrequencyIntervalGenerator.Data(Convert.ToSingle(item), Convert.ToInt32(frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectFrequency]))); } break; case Ferda.Modules.Helpers.Data.Column.ValueType.Integral: for (int i = fromUi; i < (frequenciesCount - toUi); i++) { item = frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectDistincts]; if (item == System.DBNull.Value) continue; dataArray.Add(new EquifrequencyIntervalGenerator.Data(Convert.ToInt64(item), Convert.ToInt32(frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectFrequency]))); } break; default: throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType); } object[] splitPoints = null; try { splitPoints = EquifrequencyIntervalGenerator.GenerateIntervals((int)countOfCategories, dataArray); } catch (ArgumentOutOfRangeException ex) { if (ex.ParamName == "intervals") { throw Ferda.Modules.Exceptions.BadValueError(ex, boxIdentity, null, new string[] { "CountOfCategories" }, restrictionTypeEnum.Other); } else throw ex; } if (splitPoints == null) return new GeneratedAttribute(); CategoriesStruct categoriesStruct = new CategoriesStruct(); string categoryName; List<SelectString> categoriesNames = new List<SelectString>(); SelectString categoriesNamesItem; bool computeCategoriesNames = (splitPoints.Length + 1 < Ferda.Modules.Boxes.DataMiningCommon.Attributes.AbstractAttributeConstants.MaxLengthOfCategoriesNamesSelectStringArray); switch (simpleColumnType) { case Ferda.Modules.Helpers.Data.Column.ValueType.Floating: categoriesStruct.floatIntervals = new FloatIntervalCategorySeq(); float beginValueFl = startValue; float nextValueFl; FloatIntervalStruct intervalFlTemplate = new FloatIntervalStruct(); intervalFlTemplate.leftBoundType = BoundaryEnum.Sharp; intervalFlTemplate.rightBoundType = BoundaryEnum.Round; FloatIntervalStruct intervalFl; for (int i = 0; i < splitPoints.Length + 1; i++) { if (i == splitPoints.Length) { nextValueFl = endValue; intervalFlTemplate.rightBoundType = BoundaryEnum.Sharp; } else nextValueFl = (float)splitPoints[i]; intervalFl = intervalFlTemplate; intervalFl.leftBound = beginValueFl; intervalFl.rightBound = nextValueFl; categoryName = Constants.LeftClosedInterval + beginValueFl.ToString() + Constants.SeparatorInterval + nextValueFl.ToString(); categoryName += (intervalFl.rightBoundType == BoundaryEnum.Sharp)? Constants.RightClosedInterval : Constants.RightOpenedInterval; if (computeCategoriesNames) { categoriesNamesItem = new SelectString(); categoriesNamesItem.name = categoryName; categoriesNamesItem.label = categoryName; categoriesNames.Add(categoriesNamesItem); } categoriesStruct.floatIntervals.Add( categoryName, new FloatIntervalStruct[] { intervalFl }); beginValueFl = nextValueFl; } return new GeneratedAttribute( categoriesStruct, null, categoriesStruct.floatIntervals.Count, categoriesNames.ToArray()); case Ferda.Modules.Helpers.Data.Column.ValueType.Integral: categoriesStruct.longIntervals = new LongIntervalCategorySeq(); long beginValueLn = (long)startValue; long nextValueLn; LongIntervalStruct intervalLnTemplate = new LongIntervalStruct(); intervalLnTemplate.leftBoundType = BoundaryEnum.Sharp; intervalLnTemplate.rightBoundType = BoundaryEnum.Round; LongIntervalStruct intervalLn; for (int i = 0; i < splitPoints.Length + 1; i++) { if (i == splitPoints.Length) { nextValueLn = (long)endValue; intervalLnTemplate.rightBoundType = BoundaryEnum.Sharp; } else nextValueLn = (long)splitPoints[i]; intervalLn = intervalLnTemplate; intervalLn.leftBound = beginValueLn; intervalLn.rightBound = nextValueLn; categoryName = Constants.LeftClosedInterval + beginValueLn.ToString() + Constants.SeparatorInterval + nextValueLn.ToString(); categoryName += (intervalLn.rightBoundType == BoundaryEnum.Sharp)? Constants.RightClosedInterval : Constants.RightOpenedInterval; if (computeCategoriesNames) { categoriesNamesItem = new SelectString(); categoriesNamesItem.name = categoryName; categoriesNamesItem.label = categoryName; categoriesNames.Add(categoriesNamesItem); } categoriesStruct.longIntervals.Add( categoryName, new LongIntervalStruct[] { intervalLn }); beginValueLn = nextValueLn; } return new GeneratedAttribute( categoriesStruct, null, categoriesStruct.longIntervals.Count, categoriesNames.ToArray()); default: throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType); } }
// ==================== Atribut ================================ public static string fFEAttribute(int index) { string resultString = ""; // vysledny XML string // nacteni DTD do resultStringu try { resultString = XMLHelper.loadDTD(); } catch (Exception e) { MessageBox.Show("Chyba pri nacitani DTD: " + e.Message); return(resultString); } // korenovy element resultString += "<active_list>"; string ErrStr = ""; // zaznam o chybach #region A) nalezeni vsech krabicek Atributu (DataMiningCommon.Attributes.Attribute) IBoxModule[] AttrBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "DataMiningCommon.Attributes.Attribute"); // zpracovani kazde krabicky - ziskani z ni vsechny Atributy foreach (IBoxModule ABox in AttrBoxes) { Rec_attribute rAttr = new Rec_attribute(); // nastaveni ID atributu rAttr.id = "Attr" + ABox.ProjectIdentifier.ToString(); // zjisteni jmena literalu rAttr.attr_name = ABox.GetPropertyString("NameInLiterals"); // nalezeni jmena datoveho zdroje (databaze) IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(ABox, "DataMiningCommon.Database"); if (db_names.GetLength(0) != 1) // byl nalezen pocet datovych zdroju ruzny od jedne { throw new System.Exception("bylo nalezeno " + db_names.GetLength(0).ToString() + " databazi"); } rAttr.db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue; // nalezeni jmena datove matice IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(ABox, "DataMiningCommon.DataMatrix"); if (matrix_names.GetLength(0) != 1) // byl nalezen pocet datovych matic ruzny od jedne { throw new System.Exception("bylo nalezeno " + matrix_names.GetLength(0).ToString() + " datovych matic"); } rAttr.matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue; // nalezeni jmena zdrojoveho sloupce nebo zpusobu odvozeni IBoxModule[] col_names = BoxesHelper.ListDirectAncestBoxesWithID(ABox, "DataMiningCommon.Column"); if (col_names.GetLength(0) != 1 && col_names.GetLength(0) != 0) // byl nalezen chybny pocet zdrojovych sloupcu { throw new System.Exception("bylo nalezeno " + col_names.GetLength(0).ToString() + " zdrojovych sloupcu"); } if (col_names.GetLength(0) == 1) { rAttr.creation = col_names[0].GetPropertyString("Name"); } IBoxModule[] dercol_names = BoxesHelper.ListDirectAncestBoxesWithID(ABox, "DataMiningCommon.DerivedColumn"); if (dercol_names.GetLength(0) != 1 && dercol_names.GetLength(0) != 0) // byl nalezen chybny pocet zdrojovych sloupcu { throw new System.Exception("bylo nalezeno " + dercol_names.GetLength(0).ToString() + " zdrojovych odvozenych sloupcu"); } if (dercol_names.GetLength(0) == 1) { rAttr.creation = dercol_names[0].GetPropertyString("Formula"); } // nalezeni poctu kategorii rAttr.ctgr_count = ABox.GetPropertyLong("CountOfCategories"); // zjisteni kategorie "chybejici hodnota" string nul_cat = ABox.GetPropertyString("IncludeNullCategory"); List <Rec_missing_value> MisVal_list = new List <Rec_missing_value>(); // pole recordu chybejicich hodnot if (!String.IsNullOrEmpty(nul_cat)) { Rec_missing_value MisVal = new Rec_missing_value(); MisVal.name = nul_cat; MisVal_list.Add(MisVal); } // nalezeni nazvu kategorii a jejich frekvenci List <Rec_ctgr> cat_list = new List <Rec_ctgr>(); // seznam kategorii CategoriesStruct cat_str = (ABox.GetPropertyOther("Categories") as CategoriesT).categoriesValue; // long intervals foreach (string key in cat_str.longIntervals.Keys) { Rec_ctgr new_li = new Rec_ctgr(); new_li.freq = "N/A"; // Not Available - TODO (doimplementovat, bude-li mozno) new_li.name = key; cat_list.Add(new_li); } // float intervals foreach (string key in cat_str.floatIntervals.Keys) { Rec_ctgr new_li = new Rec_ctgr(); new_li.freq = "N/A"; // Not Available - TODO (doimplementovat, bude-li mozno) new_li.name = key; cat_list.Add(new_li); } // date time intervals foreach (string key in cat_str.dateTimeIntervals.Keys) { Rec_ctgr new_li = new Rec_ctgr(); new_li.freq = "N/A"; // Not Available - TODO (doimplementovat, bude-li mozno) new_li.name = key; cat_list.Add(new_li); } // enums foreach (string key in cat_str.enums.Keys) { Rec_ctgr new_li = new Rec_ctgr(); new_li.freq = "N/A"; // Not Available - TODO (doimplementovat, bude-li mozno) new_li.name = key; cat_list.Add(new_li); } #region Vypsani jednoho Atributu do XML stringu string oneAttrString = ""; // vypsani hypotezy do XML if (MisVal_list.Count == 0 && cat_list.Count == 0) { oneAttrString += rAttr.ToXML(); } else { oneAttrString += rAttr.ToXML(cat_list, MisVal_list); } resultString += oneAttrString; #endregion } #endregion // korenovy element resultString += "</active_list>"; // Kody - ulozeni vystupu do souboru "XMLAttrExample.xml" v adresari XMLHelper.saveXMLexample(resultString, "../XML/XMLAttrExample.xml"); return(resultString); } // TODO: atributy v krabickach EachValueOneCategory, Equidistant, Equifrequency???
/// <summary> /// Returns XML string with all occurences of Active element "Category". /// </summary> /// <param name="index">index of data source in FEplugin data sources table</param> /// <returns>XML string</returns> public static string getList(int index) { string resultString = ""; // result XML string string ErrStr = ""; // error reports // loading DTD to resultString try { resultString = XMLHelper.loadDTD(); } catch (Exception e) { #if (LADENI) MessageBox.Show("error while loading DTD: " + e.Message); #endif return(resultString); } // root element resultString += "<active_list>"; // processing of each box - searching all category #region searching and processing of each boxes of attributes (DataMiningCommon.Attributes.Attribute) IBoxModule[] AttrBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "DataMiningCommon.Attributes.Attribute"); string db_name = "unknown"; string matrix_name = "unknown"; string attr_name = "unknown"; int cat_id_counter = 0; // processing of each box - searching all category foreach (IBoxModule ABox in AttrBoxes) { try { List <Rec_category> rCats = new List <Rec_category>(); // seznam vsech category of given attribute cat_id_counter = 1; // searching name of attribute (in literal) attr_name = ABox.GetPropertyString("NameInLiterals"); // searching data source name (database) IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(ABox, "DataMiningCommon.Database"); if (db_names.GetLength(0) != 1) // searched more than one data source or neither one { throw new System.Exception("found " + db_names.GetLength(0).ToString() + " databases"); } db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue; // searching data matrix name IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(ABox, "DataMiningCommon.DataMatrix"); if (matrix_names.GetLength(0) != 1) // searched more than one data source or neither one { throw new System.Exception("found " + matrix_names.GetLength(0).ToString() + " data matrixes"); } matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue; // searching list of categories of given attribute List <Rec_ctgr> cat_list = new List <Rec_ctgr>(); // list of categories CategoriesStruct cat_str = (ABox.GetPropertyOther("Categories") as CategoriesT).categoriesValue; #region processing of category type of Interval // long intervals foreach (string key in cat_str.longIntervals.Keys) { Rec_category rCat = new Rec_category(); rCat.id = "cat" + ABox.ProjectIdentifier.ToString() + "_" + cat_id_counter.ToString(); cat_id_counter++; rCat.db_name = db_name; rCat.matrix_name = matrix_name; rCat.attr_name = attr_name; rCat.ctgr_name = key; rCat.ctgr_type = "Interval"; rCat.ctgr_freq = "N/A"; // TODO: if possible rCat.bool_type = "No boolean"; // TODO: What is this? rCat.def_length = cat_str.longIntervals[key].GetLength(0); List <Rec_ctgr_def> ctgr_defs = new List <Rec_ctgr_def>(); foreach (LongIntervalStruct lis in cat_str.longIntervals[key]) { Rec_ctgr_def ctgr_def = new Rec_ctgr_def(); switch (lis.leftBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "(-inf"; break; case BoundaryEnum.Round: ctgr_def.definition += "("; break; case BoundaryEnum.Sharp: ctgr_def.definition += "<"; break; } if (lis.leftBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += lis.leftBound.ToString() + ";"; } if (lis.rightBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += lis.rightBound.ToString(); } switch (lis.rightBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "+inf)"; break; case BoundaryEnum.Round: ctgr_def.definition += ")"; break; case BoundaryEnum.Sharp: ctgr_def.definition += ">"; break; } ctgr_defs.Add(ctgr_def); } // Generating of one category to XML string OneCatString = ""; if (ctgr_defs.Count == 0) { OneCatString += rCat.ToXML(); } else { OneCatString += rCat.ToXML(ctgr_defs); } resultString += OneCatString; } // float intervals foreach (string key in cat_str.floatIntervals.Keys) { Rec_category rCat = new Rec_category(); rCat.id = "cat" + ABox.ProjectIdentifier.ToString() + "_" + cat_id_counter.ToString(); cat_id_counter++; rCat.db_name = db_name; rCat.matrix_name = matrix_name; rCat.attr_name = attr_name; rCat.ctgr_name = key; rCat.ctgr_type = "Interval"; rCat.ctgr_freq = "N/A"; // TODO: if possible rCat.bool_type = "No boolean"; // TODO: What is this? rCat.def_length = cat_str.floatIntervals[key].GetLength(0); List <Rec_ctgr_def> ctgr_defs = new List <Rec_ctgr_def>(); foreach (FloatIntervalStruct fis in cat_str.floatIntervals[key]) { Rec_ctgr_def ctgr_def = new Rec_ctgr_def(); switch (fis.leftBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "(-inf"; break; case BoundaryEnum.Round: ctgr_def.definition += "("; break; case BoundaryEnum.Sharp: ctgr_def.definition += "<"; break; } if (fis.leftBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += fis.leftBound.ToString() + ";"; } if (fis.rightBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += fis.rightBound.ToString(); } switch (fis.rightBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "+inf)"; break; case BoundaryEnum.Round: ctgr_def.definition += ")"; break; case BoundaryEnum.Sharp: ctgr_def.definition += ">"; break; } ctgr_defs.Add(ctgr_def); } // Generating of one category to XML string OneCatString = ""; if (ctgr_defs.Count == 0) { OneCatString += rCat.ToXML(); } else { OneCatString += rCat.ToXML(ctgr_defs); } resultString += OneCatString; } // date time intervals foreach (string key in cat_str.dateTimeIntervals.Keys) { Rec_category rCat = new Rec_category(); rCat.id = "cat" + ABox.ProjectIdentifier.ToString() + "_" + cat_id_counter.ToString(); cat_id_counter++; rCat.db_name = db_name; rCat.matrix_name = matrix_name; rCat.attr_name = attr_name; rCat.ctgr_name = key; rCat.ctgr_type = "Interval"; rCat.ctgr_freq = "N/A"; // TODO: implement if possible rCat.bool_type = "No boolean"; // TODO: what is this? rCat.def_length = cat_str.floatIntervals[key].GetLength(0); List <Rec_ctgr_def> ctgr_defs = new List <Rec_ctgr_def>(); foreach (DateTimeIntervalStruct dis in cat_str.dateTimeIntervals[key]) { Rec_ctgr_def ctgr_def = new Rec_ctgr_def(); switch (dis.leftBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "(-inf"; break; case BoundaryEnum.Round: ctgr_def.definition += "("; break; case BoundaryEnum.Sharp: ctgr_def.definition += "<"; break; } if (dis.leftBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += dis.leftBound.ToString() + ";"; } if (dis.rightBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += dis.rightBound.ToString(); } switch (dis.rightBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "+inf)"; break; case BoundaryEnum.Round: ctgr_def.definition += ")"; break; case BoundaryEnum.Sharp: ctgr_def.definition += ">"; break; } ctgr_defs.Add(ctgr_def); } // Generating of one category to XML string OneCatString = ""; if (ctgr_defs.Count == 0) { OneCatString += rCat.ToXML(); } else { OneCatString += rCat.ToXML(ctgr_defs); } resultString += OneCatString; } #endregion // enums foreach (string key in cat_str.enums.Keys) { Rec_category rCat = new Rec_category(); rCat.id = "cat" + ABox.ProjectIdentifier.ToString() + "_" + cat_id_counter.ToString(); cat_id_counter++; rCat.db_name = db_name; rCat.matrix_name = matrix_name; rCat.attr_name = attr_name; rCat.ctgr_name = key; rCat.ctgr_type = "Enumeration"; rCat.ctgr_freq = "N/A"; // TODO: if possible rCat.bool_type = "No boolean"; // TODO: What is this? rCat.def_length = cat_str.enums[key].GetLength(0); List <Rec_ctgr_def> ctgr_defs = new List <Rec_ctgr_def>(); foreach (string enu in cat_str.enums[key]) { Rec_ctgr_def ctgr_def = new Rec_ctgr_def(); ctgr_def.definition = enu; ctgr_defs.Add(ctgr_def); } // Generating of one category to XML string OneCatString = ""; if (ctgr_defs.Count == 0) { OneCatString += rCat.ToXML(); } else { OneCatString += rCat.ToXML(ctgr_defs); } resultString += OneCatString; } } catch (System.Exception e) { ErrStr += "Box ProjectIdentifier=" + ABox.ProjectIdentifier.ToString() + ": " + e.Message + "\n"; } } #endregion resultString += "</active_list>"; #if (LADENI) // Kody - storing output to file "XMLAttrExample.xml" in directory XMLHelper.saveXMLexample(resultString, "../XML/XMLCatExample.xml"); if (ErrStr != "") // LADICI { MessageBox.Show("Chyby pri generating seznamu Boolskych cedent:\n" + ErrStr); } #endif return(resultString); }
/// <summary> /// Tests if the categories names are in categories if not than /// <see cref="T:Ferda.Modules.BadValueError"/> is thrown. /// </summary> /// <param name="categories">The categories.</param> /// <param name="categoriesNames">The categories names.</param> /// <param name="boxIdentity">The box identity.</param> /// <exception cref="T:Ferda.Modules.BadValueError">Thrown if specified names (<c>categoriesNames</c>) are not in <c>categories</c>.</exception> public static void TestAreCategoriesInCategories(CategoriesStruct categories, string[] categoriesNames, string boxIdentity) { string notFound = String.Empty; foreach (string categoryName in categoriesNames) { if (TryIsCategoryInCategories(categories, categoryName)) continue; else { notFound = (String.IsNullOrEmpty(notFound)) ? categoryName : notFound + ", " + categoryName; } } if (!String.IsNullOrEmpty(notFound)) { throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, "Categories: " + notFound + " is/are not in categories!", new string[0], restrictionTypeEnum.NotInSelectOptions); } }
/// <summary> /// Tries if the <c>categoryName</c> is in categories. /// </summary> /// <param name="categories">The categories.</param> /// <param name="categoryName">Name of the category.</param> /// <returns>True iff <c>categoryName</c> is in categories; otherwise, false.</returns> public static bool TryIsCategoryInCategories(CategoriesStruct categories, string categoryName) { if (String.IsNullOrEmpty(categoryName)) return true; if (categories.dateTimeIntervals != null && categories.dateTimeIntervals.Contains(categoryName)) return true; if (categories.enums != null && categories.enums.Contains(categoryName)) return true; if (categories.floatIntervals != null && categories.floatIntervals.Contains(categoryName)) return true; if (categories.longIntervals != null && categories.longIntervals.Contains(categoryName)) return true; return false; }
/* private static Output generateDateTime(DateTime from, DateTime to, SidesEnum closedFrom, long length, ColumnInfo column) { //TODO Output output = new Output(); return output; } */ private static GeneratedAttribute generateString(string from, string to, long length, DataTable distincts) { CategoriesStruct result = new CategoriesStruct(); result.enums = new EnumCategorySeq(); bool finish = false; string value; long currentLength = 0; string categoryName = null; string includeNullCategoryName = null; bool includeNullCategory = false; String valueName; List<string> currentEnum = new List<string>(); foreach (DataRow row in distincts.Rows) { value = row.ItemArray[0].ToString(); if (String.Compare(from, value) > 0) continue; if (String.Compare(value, to) >= 0) finish = true; currentEnum.Add(value); if (String.IsNullOrEmpty(value)) { valueName = Constants.DbNullCategoryName; includeNullCategory = true; } else { valueName = value; } categoryName = (String.IsNullOrEmpty(categoryName)) ? valueName : categoryName + Constants.SeparatorEnum + valueName; currentLength++; if (finish || currentLength == length) { categoryName = Constants.LeftEnum + categoryName + Constants.RightEnum; result.enums.Add( categoryName, currentEnum.ToArray()); if (includeNullCategory) { includeNullCategory = false; includeNullCategoryName = categoryName; } currentEnum.Clear(); currentLength = 0; categoryName = null; } if (finish) break; } return new GeneratedAttribute( result, includeNullCategoryName, result.enums.Count); }
// ==================== Kategorie ================================ public static string fFECategory(int index) { string resultString = ""; // vysledny XML string // nacteni DTD do resultStringu try { resultString = XMLHelper.loadDTD(); } catch (Exception e) { MessageBox.Show("Chyba pri nacitani DTD: " + e.Message); return(resultString); } // korenovy element resultString += "<active_list>"; // zpracovani kazde krabicky - ziskani z ni vsechny kategorie string ErrStr = ""; // zaznam o chybach #region nalezeni a zpracovani vsech krabicek Atributu (DataMiningCommon.Attributes.Attribute) IBoxModule[] AttrBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "DataMiningCommon.Attributes.Attribute"); string db_name = ""; string matrix_name = ""; string attr_name = ""; int cat_id_counter = 0; // zpracovani kazde krabicky - ziskani z ni vsechny Kategorie foreach (IBoxModule ABox in AttrBoxes) { List <Rec_category> rCats = new List <Rec_category>(); // seznam vsech kategorii daneho atributu cat_id_counter = 1; // zjisteni jmena atributu (v literalu) attr_name = ABox.GetPropertyString("NameInLiterals"); // nalezeni jmena datoveho zdroje (databaze) IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(ABox, "DataMiningCommon.Database"); if (db_names.GetLength(0) != 1) // byl nalezen pocet datovych zdroju ruzny od jedne { throw new System.Exception("bylo nalezeno " + db_names.GetLength(0).ToString() + " databazi"); } db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue; // nalezeni jmena datove matice IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(ABox, "DataMiningCommon.DataMatrix"); if (matrix_names.GetLength(0) != 1) // byl nalezen pocet datovych matic ruzny od jedne { throw new System.Exception("bylo nalezeno " + matrix_names.GetLength(0).ToString() + " datovych matic"); } matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue; // nalezeni seznamu kategorii daneho atributu List <Rec_ctgr> cat_list = new List <Rec_ctgr>(); // seznam kategorii CategoriesStruct cat_str = (ABox.GetPropertyOther("Categories") as CategoriesT).categoriesValue; #region Zpracovani kategorii typu Interval // long intervals foreach (string key in cat_str.longIntervals.Keys) { Rec_category rCat = new Rec_category(); rCat.id = "cat" + ABox.ProjectIdentifier.ToString() + "_" + cat_id_counter.ToString(); cat_id_counter++; rCat.db_name = db_name; rCat.matrix_name = matrix_name; rCat.attr_name = attr_name; rCat.ctgr_name = key; rCat.ctgr_type = "Interval"; rCat.ctgr_freq = "N/A"; // TODO: doimplementovat, pujde-li rCat.bool_type = "No boolean"; // TODO: co to je? Dodelat. rCat.def_length = cat_str.longIntervals[key].GetLength(0); List <Rec_ctgr_def> ctgr_defs = new List <Rec_ctgr_def>(); foreach (LongIntervalStruct lis in cat_str.longIntervals[key]) { Rec_ctgr_def ctgr_def = new Rec_ctgr_def(); switch (lis.leftBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "(-inf"; break; case BoundaryEnum.Round: ctgr_def.definition += "("; break; case BoundaryEnum.Sharp: ctgr_def.definition += "<"; break; } if (lis.leftBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += lis.leftBound.ToString() + ";"; } if (lis.rightBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += lis.rightBound.ToString(); } switch (lis.rightBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "+inf)"; break; case BoundaryEnum.Round: ctgr_def.definition += ")"; break; case BoundaryEnum.Sharp: ctgr_def.definition += ">"; break; } ctgr_defs.Add(ctgr_def); } // vypsani jedne kategorie do XML string OneCatString = ""; if (ctgr_defs.Count == 0) { OneCatString += rCat.ToXML(); } else { OneCatString += rCat.ToXML(ctgr_defs); } resultString += OneCatString; } // float intervals foreach (string key in cat_str.floatIntervals.Keys) { Rec_category rCat = new Rec_category(); rCat.id = "cat" + ABox.ProjectIdentifier.ToString() + "_" + cat_id_counter.ToString(); cat_id_counter++; rCat.db_name = db_name; rCat.matrix_name = matrix_name; rCat.attr_name = attr_name; rCat.ctgr_name = key; rCat.ctgr_type = "Interval"; rCat.ctgr_freq = "N/A"; // TODO: doimplementovat, pujde-li rCat.bool_type = "No boolean"; // TODO: co to je? Dodelat. rCat.def_length = cat_str.floatIntervals[key].GetLength(0); List <Rec_ctgr_def> ctgr_defs = new List <Rec_ctgr_def>(); foreach (FloatIntervalStruct fis in cat_str.floatIntervals[key]) { Rec_ctgr_def ctgr_def = new Rec_ctgr_def(); switch (fis.leftBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "(-inf"; break; case BoundaryEnum.Round: ctgr_def.definition += "("; break; case BoundaryEnum.Sharp: ctgr_def.definition += "<"; break; } if (fis.leftBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += fis.leftBound.ToString() + ";"; } if (fis.rightBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += fis.rightBound.ToString(); } switch (fis.rightBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "+inf)"; break; case BoundaryEnum.Round: ctgr_def.definition += ")"; break; case BoundaryEnum.Sharp: ctgr_def.definition += ">"; break; } ctgr_defs.Add(ctgr_def); } // vypsani jedne kategorie do XML string OneCatString = ""; if (ctgr_defs.Count == 0) { OneCatString += rCat.ToXML(); } else { OneCatString += rCat.ToXML(ctgr_defs); } resultString += OneCatString; } // date time intervals foreach (string key in cat_str.dateTimeIntervals.Keys) { Rec_category rCat = new Rec_category(); rCat.id = "cat" + ABox.ProjectIdentifier.ToString() + "_" + cat_id_counter.ToString(); cat_id_counter++; rCat.db_name = db_name; rCat.matrix_name = matrix_name; rCat.attr_name = attr_name; rCat.ctgr_name = key; rCat.ctgr_type = "Interval"; rCat.ctgr_freq = "N/A"; // TODO: doimplementovat, pujde-li rCat.bool_type = "No boolean"; // TODO: co to je? Dodelat. rCat.def_length = cat_str.floatIntervals[key].GetLength(0); List <Rec_ctgr_def> ctgr_defs = new List <Rec_ctgr_def>(); foreach (DateTimeIntervalStruct dis in cat_str.dateTimeIntervals[key]) { Rec_ctgr_def ctgr_def = new Rec_ctgr_def(); switch (dis.leftBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "(-inf"; break; case BoundaryEnum.Round: ctgr_def.definition += "("; break; case BoundaryEnum.Sharp: ctgr_def.definition += "<"; break; } if (dis.leftBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += dis.leftBound.ToString() + ";"; } if (dis.rightBoundType != BoundaryEnum.Infinity) { ctgr_def.definition += dis.rightBound.ToString(); } switch (dis.rightBoundType) { case BoundaryEnum.Infinity: ctgr_def.definition += "+inf)"; break; case BoundaryEnum.Round: ctgr_def.definition += ")"; break; case BoundaryEnum.Sharp: ctgr_def.definition += ">"; break; } ctgr_defs.Add(ctgr_def); } // vypsani jedne kategorie do XML string OneCatString = ""; if (ctgr_defs.Count == 0) { OneCatString += rCat.ToXML(); } else { OneCatString += rCat.ToXML(ctgr_defs); } resultString += OneCatString; } #endregion // enums foreach (string key in cat_str.enums.Keys) { Rec_category rCat = new Rec_category(); rCat.id = "cat" + ABox.ProjectIdentifier.ToString() + "_" + cat_id_counter.ToString(); cat_id_counter++; rCat.db_name = db_name; rCat.matrix_name = matrix_name; rCat.attr_name = attr_name; rCat.ctgr_name = key; rCat.ctgr_type = "Enumeration"; rCat.ctgr_freq = "N/A"; // TODO: doimplementovat, pujde-li rCat.bool_type = "No boolean"; // TODO: co to je? Dodelat. rCat.def_length = cat_str.enums[key].GetLength(0); List <Rec_ctgr_def> ctgr_defs = new List <Rec_ctgr_def>(); foreach (string enu in cat_str.enums[key]) { Rec_ctgr_def ctgr_def = new Rec_ctgr_def(); ctgr_def.definition = enu; ctgr_defs.Add(ctgr_def); } // vypsani jedne kategorie do XML string OneCatString = ""; if (ctgr_defs.Count == 0) { OneCatString += rCat.ToXML(); } else { OneCatString += rCat.ToXML(ctgr_defs); } resultString += OneCatString; } } #endregion resultString += "</active_list>"; // Kody - ulozeni vystupu do souboru "XMLAttrExample.xml" v adresari XMLHelper.saveXMLexample(resultString, "../XML/XMLCatExample.xml"); return(resultString); }
/// <summary> /// Tests the categories count. If there is no category in specified /// <c>categories</c> than <see cref="T:Ferda.Modules.BadValueError"/> /// is thrown. /// </summary> /// <param name="categories">The categories.</param> /// <param name="boxIdentity">The box identity.</param> /// <exception cref="T:Ferda.Modules.BadValueError">Thrown if there is no category in specified <c>categories</c>.</exception> public static void TestCategoriesCount(CategoriesStruct categories, string boxIdentity) { if (categories.enums != null && categories.enums.Count > 0) return; if (categories.longIntervals != null && categories.longIntervals.Count > 0) return; if (categories.floatIntervals != null && categories.floatIntervals.Count > 0) return; if (categories.dateTimeIntervals != null && categories.dateTimeIntervals.Count > 0) return; throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, "There is no categoryName in attribute!", new string[] { "Categories" }, restrictionTypeEnum.Other); }
public static CategoriesStruct Struct2Dict(Categories categories) { CategoriesStruct result = new CategoriesStruct(); result.dateTimeIntervals = new DateTimeIntervalCategorySeq(); result.floatIntervals = new FloatIntervalCategorySeq(); result.longIntervals = new LongIntervalCategorySeq(); result.enums = new EnumCategorySeq(); foreach (DateTimeCategory category in categories.DateTimes) { result.dateTimeIntervals.Add(category.Name, category.Value); } foreach (FloatCategory category in categories.Floats) { result.floatIntervals.Add(category.Name, category.Value); } foreach (LongCategory category in categories.Longs) { result.longIntervals.Add(category.Name, category.Value); } foreach (EnumCategory category in categories.Enums) { result.enums.Add(category.Name, category.Value); } return result; }
public CategoriesTI(CategoriesStruct categoriesStruct) { this.categoriesValue = categoriesStruct; }
/// <summary> /// Returns XML string with all occurences of Active element "Attribute". /// </summary> /// <param name="index">index of data source in FEplugin data sources table</param> /// <returns>XML string</returns> public static string getList(int index) { string resultString = ""; // result XML string // loading DTD to resultString try { resultString = XMLHelper.loadDTD(); } catch (Exception e) { #if (LADENI) MessageBox.Show("error while loading DTD: " + e.Message); #endif return(resultString); } // root element resultString += "<active_list>"; string ErrStr = ""; // error report #region A) searching all boxes - Attributes (DataMiningCommon.Attributes.Attribute) IBoxModule[] AttrBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "DataMiningCommon.Attributes.Attribute"); // processing of each box - searching all Attributes foreach (IBoxModule ABox in AttrBoxes) { try { Rec_attribute rAttr = new Rec_attribute(); // setting ID attribute rAttr.id = "Attr" + ABox.ProjectIdentifier.ToString(); // searching name of literal rAttr.attr_name = ABox.GetPropertyString("NameInLiterals"); // searching data source name (database) IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(ABox, "DataMiningCommon.Database"); if (db_names.GetLength(0) != 1) // searched more than one data source or neither one { throw new System.Exception("found " + db_names.GetLength(0).ToString() + " databases"); } rAttr.db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue; // searching data matrix name IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(ABox, "DataMiningCommon.DataMatrix"); if (matrix_names.GetLength(0) != 1) // searched more than one data source or neither one { throw new System.Exception("found " + matrix_names.GetLength(0).ToString() + " data matrixes"); } rAttr.matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue; // searching name of source column or manner of derivation IBoxModule[] col_names = BoxesHelper.ListDirectAncestBoxesWithID(ABox, "DataMiningCommon.Column"); if (col_names.GetLength(0) != 1 && col_names.GetLength(0) != 0) // incorrect number of source columns found { throw new System.Exception("found " + col_names.GetLength(0).ToString() + " zdrojovych sloupcu"); } if (col_names.GetLength(0) == 1) { rAttr.creation = col_names[0].GetPropertyString("Name"); } IBoxModule[] dercol_names = BoxesHelper.ListDirectAncestBoxesWithID(ABox, "DataMiningCommon.DerivedColumn"); if (dercol_names.GetLength(0) != 1 && dercol_names.GetLength(0) != 0) // incorrect number of source columns found { throw new System.Exception("found " + dercol_names.GetLength(0).ToString() + " zdrojovych odvozenych sloupcu"); } if (dercol_names.GetLength(0) == 1) { rAttr.creation = dercol_names[0].GetPropertyString("Formula"); } // searching number of categories rAttr.ctgr_count = ABox.GetPropertyLong("CountOfCategories"); // searching the category "missisng value" string nul_cat = ABox.GetPropertyString("IncludeNullCategory"); List <Rec_missing_value> MisVal_list = new List <Rec_missing_value>(); // array of records with missing values if (!String.IsNullOrEmpty(nul_cat)) { Rec_missing_value MisVal = new Rec_missing_value(); MisVal.name = nul_cat; MisVal_list.Add(MisVal); } // searching category names and their frequencies List <Rec_ctgr> cat_list = new List <Rec_ctgr>(); // list of categories CategoriesStruct cat_str = (ABox.GetPropertyOther("Categories") as CategoriesT).categoriesValue; // long intervals foreach (string key in cat_str.longIntervals.Keys) { Rec_ctgr new_li = new Rec_ctgr(); new_li.freq = "N/A"; // Not Available - TODO (if possible) //KODY 27.11.2006 - not possible to gain attribute frequencies directly from Ferda. Can be resolved via creating CF task new_li.name = key; cat_list.Add(new_li); } // float intervals foreach (string key in cat_str.floatIntervals.Keys) { Rec_ctgr new_li = new Rec_ctgr(); new_li.freq = "N/A"; // Not Available - TODO (if possible) new_li.name = key; cat_list.Add(new_li); } // date time intervals foreach (string key in cat_str.dateTimeIntervals.Keys) { Rec_ctgr new_li = new Rec_ctgr(); new_li.freq = "N/A"; // Not Available - TODO (if possible) new_li.name = key; cat_list.Add(new_li); } // enums foreach (string key in cat_str.enums.Keys) { Rec_ctgr new_li = new Rec_ctgr(); new_li.freq = "N/A"; // Not Available - TODO (if possible) new_li.name = key; cat_list.Add(new_li); } #region Generating of one attribute to XML string string oneAttrString = ""; // generating hypotheses to XML if (MisVal_list.Count == 0 && cat_list.Count == 0) { oneAttrString += rAttr.ToXML(); } else { oneAttrString += rAttr.ToXML(cat_list, MisVal_list); } resultString += oneAttrString; #endregion } catch (System.Exception e) { ErrStr += "Box ProjectIdentifier=" + ABox.ProjectIdentifier.ToString() + ": " + e.Message + "\n"; } } #endregion // root element resultString += "</active_list>"; #if (LADENI) // generating of error message: if (!String.IsNullOrEmpty(ErrStr)) { MessageBox.Show("Pri nacitani category doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Kody - storing output to file "XMLAttrExample.xml" in directory XMLHelper.saveXMLexample(resultString, "../XML/XMLAttrExample.xml"); #endif return(resultString); } // TODO: Attributes v krabickach EachValueOneCategory, Equidistant, Equifrequency???
/// <summary> /// Class constructor /// </summary> /// <param name="columnInfo">ColumnInfo</param> /// <param name="categoriesStruct">CategoriesStruct</param> public DBInteraction(ColumnInfo columnInfo, CategoriesStruct categoriesStruct) { this.connectionString = columnInfo.dataMatrix.database.odbcConnectionString; this.columnSelectExpression = columnInfo.columnSelectExpression; this.dataMatrixName = columnInfo.dataMatrix.dataMatrixName; this.rowCount = columnInfo.dataMatrix.recordsCount; this.categoriesStruct = categoriesStruct; this.columnType = columnInfo.columnSubType; this.connection = this.GetConnection(); }