/// <summary> /// Generates one CF cedent to XML string. /// </summary> /// <param name="subcedents">boxes with parcial cedents</param> /// <returns>XML string</returns> private static string getOneCedentXML(IBoxModule[] subcedents) { string XML = ""; #region Loop - processing of each parcial cedent foreach (IBoxModule box in subcedents) // must be boxes with ID = "DataMiningCommon.CategorialPartialCedentSetting" { Rec_sub_CF_cedent rSCFC = new Rec_sub_CF_cedent(); // setting attribute "name" rSCFC.name = box.UserName; // setting attribute "length" rSCFC.length = box.GetPropertyLong("MinLen").ToString() + " - " + box.GetPropertyLong("MaxLen").ToString(); // searching each CF literal (= attribute!) string[] AttrIDs = { "DataMiningCommon.Attributes.Attribute", "DataMiningCommon.Attributes.EquifrequencyIntervalsAttribute", "DataMiningCommon.Attributes.EquidistantIntervalsAttribute", "DataMiningCommon.Attributes.EachValueOneCategoryAttribute" }; IBoxModule[] attributes = BoxesHelper.ListDirectAncestBoxesWithID(box, AttrIDs); // setting attribute "literal_cnt" (literals count) rSCFC.literal_cnt = attributes.Length; List <Rec_CF_literal> rLiterals = new List <Rec_CF_literal>(); #region Loop - processing of each CF-literal (attribute) foreach (IBoxModule attrBox in attributes) { Rec_CF_literal rLiteral = new Rec_CF_literal(); // setting attribute "underlying_attribute" rLiteral.underlying_attribute = attrBox.GetPropertyString("NameInLiterals"); // setting attribute "category_cnt" rLiteral.category_cnt = attrBox.GetPropertyLong("CountOfCategories"); rLiterals.Add(rLiteral); } #endregion // adding parcial cedent (and its literals) to result XML string XML += rSCFC.ToXML(rLiterals); } #endregion return(XML); }
/// <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???
// ==================== 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 "Boolean cedent". /// </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 int counterID = 0; // 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>"; List <TaskTypeStruct> TypyTask = new List <TaskTypeStruct>(); CedentTypeStruct[] Typycedent4FT = { new CedentTypeStruct("Antecedent", "AntecedentSetting"), new CedentTypeStruct("Succedent", "SuccedentSetting"), new CedentTypeStruct("Condition", "ConditionSetting") }; CedentTypeStruct[] TypycedentSD4FT = { new CedentTypeStruct("Antecedent", "AntecedentSetting"), new CedentTypeStruct("Succedent", "SuccedentSetting"), new CedentTypeStruct("Condition", "ConditionSetting"), new CedentTypeStruct("FirstSet", "Cedent1"), new CedentTypeStruct("SecondSet", "Cedent2") }; CedentTypeStruct[] TypycedentKL = { new CedentTypeStruct("Condition", "ConditionSetting") }; CedentTypeStruct[] TypycedentSDKL = { new CedentTypeStruct("Condition", "ConditionSetting"), new CedentTypeStruct("FirstSet", "Cedent1"), new CedentTypeStruct("SecondSet", "Cedent2") }; CedentTypeStruct[] TypycedentCF = { new CedentTypeStruct("Condition", "ConditionSetting") }; CedentTypeStruct[] TypycedentSDCF = { new CedentTypeStruct("Condition", "ConditionSetting"), new CedentTypeStruct("FirstSet", "Cedent1"), new CedentTypeStruct("SecondSet", "Cedent2") }; TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.FFTTask", "4FT Task", Typycedent4FT)); TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDFFTTask", "SD-4FT Task", TypycedentSD4FT)); TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.KLTask", "KL Task", TypycedentKL)); TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDKLTask", "SD-KL Task", TypycedentSDKL)); TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.CFTask", "CF Task", TypycedentCF)); TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDCFTask", "SD-CF Task", TypycedentSDCF)); #region Loop - processing of each type of Task foreach (TaskTypeStruct TT in TypyTask) { // searching all boxes of tasks IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, TT.TaskTypeID); #region Loop - processing of each found Task foreach (IBoxModule box in TaskBoxes) { #region Loop - processing of each type of cedent of given Task counterID = 0; foreach (CedentTypeStruct Typcedent in TT.Cedents) { Rec_bool_cedent rBoolCedent = new Rec_bool_cedent(); // setting ID string id = "cdnt" + box.ProjectIdentifier.ToString() + "_"; try { // searching data source name (database) IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(box, "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"); } rBoolCedent.db_name = db_names[0].GetPropertyString("DatabaseName"); // searching data matrix name IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(box, "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"); } rBoolCedent.matrix_name = matrix_names[0].GetPropertyString("Name"); // searching task name rBoolCedent.task_name = box.UserName; // filling the "task_type" rBoolCedent.task_type = TT.TaskTypeLabel; // filling the "cedent_type" rBoolCedent.cedent_type = Typcedent.CedentTypeLabel; // searching all parcial cedent IBoxModule[] Subcedents = box.GetConnections(Typcedent.CedentTypeID); foreach (IBoxModule Subcedent in Subcedents) { Rec_bool_cedent rBoolCedent1 = rBoolCedent; // filling the ID rBoolCedent1.id = id + counterID.ToString(); counterID++; // setting "name" rBoolCedent1.name = Subcedent.UserName; // setting "length" rBoolCedent1.length = Subcedent.GetPropertyLong("MinLen").ToString() + " - " + Subcedent.GetPropertyLong("MaxLen").ToString(); // searching all literals IBoxModule[] literals = BoxesHelper.ListDirectAncestBoxesWithID(Subcedent, "DataMiningCommon.LiteralSetting"); // setting attribute "literal_cnt" (count of literals of parcial cedent) rBoolCedent1.literal_cnt = literals.Length; List <Rec_literal> rLiterals = new List <Rec_literal>(); #region Loop - processing of each literal of parcial cedent foreach (IBoxModule litBox in literals) { Rec_literal rLiteral = new Rec_literal(); // setting attribute "literal_type" {Basic/Remaining} rLiteral.literal_type = litBox.GetPropertyString("LiteralType"); // setting attribute "gace" {Positive/Negative/Both} rLiteral.gace = litBox.GetPropertyString("GaceType"); // searching atom IBoxModule[] atoms = BoxesHelper.ListDirectAncestBoxesWithID(litBox, "DataMiningCommon.AtomSetting"); if (atoms.Length != 1) // just one atom should be found { ErrStr += "Literal ID=" + litBox.ProjectIdentifier.ToString() + " : nalezeno " + atoms.Length.ToString() + " atom\n"; continue; // processing of next literal } IBoxModule atomBox = atoms[0].Clone(); // setting attribute "coefficient_type" {Interval/Subset/Cut/....} rLiteral.coefficient_type = atomBox.GetPropertyString("CoefficientType"); // setting attribute "length" rLiteral.length = atomBox.GetPropertyLong("MinLen").ToString() + " - " + atomBox.GetPropertyLong("MaxLen").ToString(); // searching attribute string[] AttrIDs = { "DataMiningCommon.Attributes.Attribute", "DataMiningCommon.Attributes.EquifrequencyIntervalsAttribute", "DataMiningCommon.Attributes.EquidistantIntervalsAttribute", "DataMiningCommon.Attributes.EachValueOneCategoryAttribute" }; IBoxModule[] attributes = BoxesHelper.ListDirectAncestBoxesWithID(atomBox, AttrIDs); if (attributes.Length != 1) //just one attribute should be found { ErrStr += "Literal ID=" + litBox.ProjectIdentifier.ToString() + " : nalezeno " + attributes.Length.ToString() + " attribute\n"; continue; // processing of next literal } IBoxModule attrBox = attributes[0].Clone(); // setting attribute "underlying_attribute" rLiteral.underlying_attribute = attrBox.GetPropertyString("NameInLiterals"); // setting attribute "category_cnt" rLiteral.category_cnt = attrBox.GetPropertyLong("CountOfCategories"); // setting attribute "missing_type" rLiteral.missing_type = attrBox.GetPropertyString("IncludeNullCategory"); // adding literal to list rLiterals.Add(rLiteral); } #endregion // generating boolean cedent to XML resultString += rBoolCedent1.ToXML(rLiterals); } } catch (System.Exception e) { ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n"; } } #endregion } #endregion } #endregion // root element resultString += "</active_list>"; #if (LADENI) // Kody - storing output to file "XMLBool_cedentExample.xml" in directory XMLHelper.saveXMLexample(resultString, "../XML/XMLBool_cedentExample.xml"); if (ErrStr != "") // LADICI { MessageBox.Show("Chyby pri generating seznamu Boolskych cedent:\n" + ErrStr); } #endif return(resultString); }