Example #1
0
        /// <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);
        }
        // ==================== 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???
        // ==================== 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);
        }
        // ==================== 4ft-hypoteza ================================

        public static string fFE4fthyp(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 PropName = "Hypotheses";  // nazev Property, ktera obsahuje seznam hypotez

            // nalezeni vsech krabicek 4FT-uloh
            IBoxModule[] FFTTaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.FFTTask");

            // zpracovani kazde krabicky - ziskani z ni vsechny 4ft-hypotezy
            string ErrStr = "";      // zaznam o chybach

            string matrix_name = ""; // jmeno analyzovane matice
            string db_name     = ""; // jmeno analyzovane databaze
            string task_name   = ""; // jmeno ulohy - dano uzivatelskym nazvem krabicky FFTTast

            #region Cyklus - zpracovani vsech 4ft-Tasku z pole FFTTaskBoxes

            foreach (IBoxModule box in FFTTaskBoxes)
            {
                try
                {
                    // nalezeni jmena datoveho zdroje (databaze)
                    IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(box, "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(box, "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 jmena ulohy
                    task_name = box.UserName;

                    // nalezeni seznamu vsech hypotez v tomto Tasku
                    HypothesesT        HypT    = box.GetPropertyOther(PropName) as HypothesesT;
                    HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[];

                    // recordy pro ukladani vysledku
                    Rec_hyp_4ft   rHyp = new Rec_hyp_4ft();    // hypoteza
                    Rec_ti_cedent rAnt = new Rec_ti_cedent();  // antecedent
                    Rec_ti_cedent rSuc = new Rec_ti_cedent();  // succedent
                    Rec_ti_cedent rCon = new Rec_ti_cedent();  // condition

                    #region Cyklus - zpracovani vsech hypotez jedne krabicky FFTTask
                    // cyklus pres vsechny hypotezy
                    for (int i = 0; i < HypList.GetLength(0); i++)
                    {
                        #region element hyp_4ft

                        rHyp.id          = "hyp4ft" + box.ProjectIdentifier.ToString() + "_" + i.ToString();
                        rHyp.db_name     = db_name;
                        rHyp.matrix_name = matrix_name;
                        rHyp.task_name   = task_name;
                        rHyp.antecedent  = "ant" + rHyp.id;
                        rHyp.succedent   = "suc" + rHyp.id;
                        rHyp.condition   = "con" + rHyp.id;
                        FourFoldContingencyTable FFT = new FourFoldContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows);
                        rHyp.a = FFT.A;
                        rHyp.b = FFT.B;
                        rHyp.c = FFT.C;
                        rHyp.d = FFT.D;
                        // hodnoty kvantifikatoru
                        rHyp.conf     = FourFoldContingencyTable.FoundedImplicationValue(FFT);          // Founded implication (a/a+b)
                        rHyp.d_conf   = FourFoldContingencyTable.DoubleFoundedImplicationValue(FFT);    // Double Founded implication (a/a+b+c)
                        rHyp.e_conf   = FourFoldContingencyTable.FoundedEquivalenceValue(FFT);          // Founded Equivalence (a+d)/(a+b+c+d)  ??? BUG ve Ferdovi
                        rHyp.support  = FourFoldContingencyTable.BaseCeilValue(FFT);                    //???  Support (a/a+b+c+d)
                        rHyp.avg_diff = FourFoldContingencyTable.AboveAverageImplicationValue(FFT) - 1; // Averafe difference ((a*(a+b+c+d))/((a+b)*(a+c)) -1)
                        // tyto hodnoty se vypocitavaji (mozna zbytecne?)
                        rHyp.fisher = FFT.FisherValue();
                        rHyp.chi_sq = FFT.ChiSquareValue();

                        #endregion
                        // TODO - dodelat vypocty, ostatni ciselne polozky (hodnoty nekterych kvantifikatoru atd.)

                        #region element ti_cedent (Antecedent)

                        rAnt.id   = "ant" + rHyp.id;
                        rAnt.type = "Antecedent";
                        // literaly
                        int       litCounter = 0; // pocitadlo literalu teto hypotezy
                        ArrayList ARLit_a    = new ArrayList();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Antecedent)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant = lit.literalName;
                                foreach (string s in lit.categoriesNames)
                                {
                                    l.value += s;
                                }
                                ARLit_a.Add(l);
                            }
                        }
                        Rec_ti_literal[] ALit_a = (Rec_ti_literal[])ARLit_a.ToArray(typeof(Rec_ti_literal)); // pole literalu daneho cedentu
                        #endregion

                        #region element ti_cedent (Succedent)

                        rSuc.id   = "suc" + rHyp.id;
                        rSuc.type = "Succedent";
                        // literaly
                        ArrayList ARLit_s = new ArrayList();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Succedent)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant = lit.literalName;
                                foreach (string s in lit.categoriesNames)
                                {
                                    l.value += s;
                                }
                                ARLit_s.Add(l);
                            }
                        }
                        Rec_ti_literal[] ALit_s = (Rec_ti_literal[])ARLit_s.ToArray(typeof(Rec_ti_literal)); // pole literalu daneho cedentu
                        #endregion

                        #region element ti_cedent (Condition)

                        rCon.id   = "con" + rHyp.id;
                        rCon.type = "Condition";
                        // literaly
                        ArrayList ARLit_c = new ArrayList();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Condition)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant = lit.literalName;
                                foreach (string s in lit.categoriesNames)
                                {
                                    l.value += s;
                                }
                                ARLit_s.Add(l);
                            }
                        }
                        Rec_ti_literal[] ALit_c = (Rec_ti_literal[])ARLit_c.ToArray(typeof(Rec_ti_literal)); // pole literalu daneho cedentu
                        #endregion

                        #region Vypsani jedne hypotezy do XML stringu

                        string oneHypString = "";
                        // vypsani hypotezy do XML
                        oneHypString += rHyp.ToXML();
                        // vypsani Antecedentu do XML
                        oneHypString += rAnt.ToXML(ALit_a);
                        // vypsani Succedentu do XML
                        oneHypString += rSuc.ToXML(ALit_s);
                        // vypsani Condition do XML
                        oneHypString += rCon.ToXML(ALit_c);

                        resultString += oneHypString;

                        #endregion
                    }
                    #endregion
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                }
            }
            #endregion

            // vypsani pripadne chybove hlasky:
            if (!String.IsNullOrEmpty(ErrStr))
            {
                MessageBox.Show("Pri nacitani hypotez doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // korenovy element
            resultString += "</active_list>";

            // Kody - ulozeni vystupu do souboru "XML4fthypExample.xml" v adresari
            XMLHelper.saveXMLexample(resultString, "../XML/XML4fthypExample.xml");

            return(resultString);
        }
Example #5
0
        /// <summary>
        /// Returns XML string with all occurences of Active element "KL hypothesis".
        /// </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 PropName = "Hypotheses";  // name of property which contain a list of hypotheses
            // searching all boxes KL-uloh
            IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.KLTask");

            // processing of each box - searching all KL-hypotheses
            string ErrStr = "";             // error report

            string matrix_name = "unknown"; // analyzed data matrix name
            string db_name     = "unknown"; // analyzed database name
            string task_name   = "unknown"; // task name - given with user name of box FFTTast


            #region Loop - processing of each KL-Task from array TaskBoxes

            foreach (IBoxModule box in TaskBoxes)
            {
                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");
                    }
                    db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue;

                    // 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");
                    }
                    matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue;

                    // searching task name
                    task_name = box.UserName;

                    // searching the list of all hypotheses in this task
                    HypothesesT        HypT    = box.GetPropertyOther(PropName) as HypothesesT;
                    HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[];

                    // records for storing the results
                    Rec_hyp_KL       rHyp = new Rec_hyp_KL();       // KL hypothesis
                    Rec_ti_attribute rAnt = new Rec_ti_attribute(); // Antecedent (Row attributes)
                    Rec_ti_attribute rSuc = new Rec_ti_attribute(); // Succedent (Column attributes)
                    Rec_ti_cedent    rCon = new Rec_ti_cedent();    // condition


                    #region Loop - processing of each hypotheses jedne krabicky KLTask
                    // Loop over all hypotheses
                    for (int i = 0; i < HypList.GetLength(0); i++)
                    {
                        #region element hyp_KL

                        rHyp.id                = "hypKL" + box.ProjectIdentifier.ToString() + "_" + i.ToString();
                        rHyp.db_name           = db_name;
                        rHyp.matrix_name       = matrix_name;
                        rHyp.task_name         = task_name;
                        rHyp.row_attributes    = "r_attr" + rHyp.id;
                        rHyp.column_attributes = "c_attr" + rHyp.id;
                        rHyp.condition         = "con" + rHyp.id;
                        TwoDimensionalContingencyTable CT = new TwoDimensionalContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows); // Contingency Table
                        rHyp.Tab = HypList[i].quantifierSetting.firstContingencyTableRows;


                        // values of quantifiers - first set
                        try
                        {
                            rHyp.sum    = CT.SumOfValues.ToString();
                            rHyp.min    = CT.MinValue.ToString();
                            rHyp.max    = CT.MaxValue.ToString();
                            rHyp.chi_sq = TwoDimensionalContingencyTable.ChiSquare(CT).ToString();
                            rHyp.fnc_s  = TwoDimensionalContingencyTable.SumOfRowMaximumsValue(CT).ToString();
                            rHyp.fnc_r  = TwoDimensionalContingencyTable.MinOfRowMaximumsValue(CT).ToString();
                            rHyp.h_c    = CT.MarginalColumnEntropy.ToString();
                            rHyp.h_r    = CT.MarginalRowEntropy.ToString();
                            rHyp.h_c_r  = TwoDimensionalContingencyTable.ConditionalCREntropyValue(CT).ToString();
                            rHyp.mi     = CT.MutualInformation.ToString();
                            //rHyp.aic = CT.???;  TODO
                            rHyp.kend = TwoDimensionalContingencyTable.KendalValue(CT).ToString();
                        }
                        catch (System.Exception e) // There are some errors in Ferda quantifier values!
                        {
                            ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": chyba pri vypoctu kvantifikatoru: " + e.Message + "\n";
                        }



                        #endregion

                        #region element ti_attribute Row attributes (Antecedent)

                        rAnt.id    = rHyp.row_attributes;
                        rAnt.type  = "Row attributes";
                        rAnt.quant = "";   // deleting previous value
                        // category
                        List <Rec_ti_category> Cat_a = new List <Rec_ti_category>();
                        foreach (LiteralStruct lit in HypList[i].literals)
                        {
                            if (lit.cedentType == CedentEnum.Antecedent)
                            {
                                rAnt.quant += lit.literalName;
                                foreach (string s in lit.categoriesNames)
                                {
                                    Rec_ti_category C = new Rec_ti_category();
                                    C.value = s;
                                    Cat_a.Add(C);
                                }
                                // ??? k cemu je polozka LitralStruct.categoriesValues ?
                            }
                        }

                        #endregion

                        #region element ti_attribute Column attributes (Succedent)

                        rSuc.id    = rHyp.column_attributes;
                        rSuc.type  = "Column attributes";
                        rSuc.quant = "";   // deleting previous value
                        // category
                        List <Rec_ti_category> Cat_s = new List <Rec_ti_category>();
                        foreach (LiteralStruct lit in HypList[i].literals)
                        {
                            if (lit.cedentType == CedentEnum.Succedent)
                            {
                                rSuc.quant += lit.literalName;
                                foreach (string s in lit.categoriesNames)
                                {
                                    Rec_ti_category C = new Rec_ti_category();
                                    C.value = s;
                                    Cat_s.Add(C);
                                }
                                // ??? k cemu je polozka LitralStruct.categoriesValues ?
                            }
                        }

                        #endregion

                        #region element ti_cedent (Condition)

                        rCon.id   = "con" + rHyp.id;
                        rCon.type = "Condition";
                        // literals
                        int litCounter = 0;  // counter of literals of this hypotheses
                        List <Rec_ti_literal> Lit_c = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Condition)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_c.Add(l);
                            }
                        }

                        #endregion


                        #region Generating of one hypotheses to XML string

                        string oneHypString = "";
                        // generating hypotheses to XML
                        oneHypString += rHyp.ToXML();
                        // generating Row attributes (Antecedent) to XML
                        oneHypString += rAnt.ToXML(Cat_a);
                        // generating Column attributes (Succedent) to XML
                        oneHypString += rSuc.ToXML(Cat_s);
                        // generating Condition to XML
                        oneHypString += rCon.ToXML(Lit_c);



                        resultString += oneHypString;

                        #endregion
                    }
                    #endregion
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                }
            }
            #endregion


            // root element
            resultString += "</active_list>";

#if (LADENI)
            // generating of error message:
            if (!String.IsNullOrEmpty(ErrStr))  // LADICI
            {
                MessageBox.Show("Pri nacitani KL hypotheses doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // LADICI - Kody - storing output to file "XMLsd4fthypExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLKLhypExample.xml");
#endif

            return(resultString);
        }
        /// <summary>
        /// Returns XML string with all occurences of Active element "KL 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>";

            string[] BoxTypes = { "LISpMinerTasks.KLTask", "LISpMinerTasks.SDKLTask" }; // types of boxes (tasks) for which are searched KL cedents

            // searching all boxes of tasks
            IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, BoxTypes);

            #region Loop - processing of each tasks found

            foreach (IBoxModule box in TaskBoxes)
            {
                Rec_KL_cedent rKLCedent = new Rec_KL_cedent();
                counterID = 0;

                try
                {
                    // setting ID
                    rKLCedent.id = "klcdnt" + box.ProjectIdentifier.ToString() + "_";

                    // 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");
                    }
                    rKLCedent.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");
                    }
                    rKLCedent.matrix_name = matrix_names[0].GetPropertyString("Name");

                    // searching task name
                    rKLCedent.task_name = box.UserName;

                    // processing of several Task types
                    string id = rKLCedent.id;
                    switch (box.MadeInCreator.Identifier) // all available task types
                    {
                    case "LISpMinerTasks.KLTask":
                        rKLCedent.task_type = "KL Task";

                        // Antecedent
                        rKLCedent.id = id + counterID.ToString();
                        counterID++;
                        rKLCedent.cedent_type = "Row attributes";
                        resultString         += getOneItemXML(box, rKLCedent, "AntecedentSetting");

                        // Succedent
                        rKLCedent.id = id + counterID.ToString();
                        counterID++;
                        rKLCedent.cedent_type = "Column attributes";
                        resultString         += getOneItemXML(box, rKLCedent, "SuccedentSetting");
                        break;

                    case "LISpMinerTasks.SDKLTask":
                        rKLCedent.task_type = "SD-KL Task";

                        // Anecedent
                        rKLCedent.id = id + counterID.ToString();
                        counterID++;
                        //rKLCedent.cedent_type = CedentEnum.Antecedent.ToString();
                        rKLCedent.cedent_type = "Row attributes";
                        resultString         += getOneItemXML(box, rKLCedent, "AntecedentSetting");

                        // Succedent
                        rKLCedent.id = id + counterID.ToString();
                        counterID++;
                        rKLCedent.cedent_type = "Column attributes";
                        //rKLCedent.cedent_type = CedentEnum.Succedent.ToString();
                        resultString += getOneItemXML(box, rKLCedent, "SuccedentSetting");
                        break;
                    }
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                }
            }

            #endregion

            // root element
            resultString += "</active_list>";

#if (LADENI)
            // Kody - storing output to file "XMLKL_cedentExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLKL_cedentExample.xml");

            if (ErrStr != "") // LADICI
            {
                MessageBox.Show("Chyby pri generating seznamu KL cedent:\n" + ErrStr);
            }
#endif

            return(resultString);
        }
Example #7
0
        /// <summary>
        /// Returns XML string with all occurences of Active element "Task" (all types of tasks).
        /// </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>();
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.FFTTask", "4FT Task"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDFFTTask", "SD-4FT Task"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.KLTask", "KL Task"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDKLTask", "SD-KL Task"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.CFTask", "CF Task"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDCFTask", "SD-CF Task"));

            #region Loop over all Task types

            foreach (TaskTypeStruct TTS in TypyTask)
            {
                // searching all boxes Task with given type
                IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, TTS.TaskBoxType);

                #region Loop - processing of each Task with given type

                foreach (IBoxModule box in TaskBoxes)
                {
                    // record of Task
                    Rec_task rTask = new Rec_task();

                    try
                    {
                        // setting ID
                        rTask.id = "task" + box.ProjectIdentifier.ToString();

                        // searching data source name (database) - not mandatory!
                        IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.Database");
                        if (db_names.GetLength(0) == 1)  // searched more than one data source or neither one
                        {
                            rTask.db_name = db_names[0].GetPropertyString("DatabaseName");
                        }

                        // searching data matrix name - not mandatory!
                        IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.DataMatrix");
                        if (matrix_names.GetLength(0) == 1)  // searched more than one data source or neither one
                        {
                            rTask.matrix_name = matrix_names[0].GetPropertyString("Name");
                        }

                        // searching task name
                        rTask.task_name = box.UserName;

                        // filling the "task_type"
                        rTask.task_type = TTS.TypeString;

                        // filling the "gen_state"
                        rTask.gen_state = box.GetPropertyString("GenerationState");

                        // filling the "gen_total_time"
                        rTask.gen_total_time = box.GetPropertyTime("GenerationTotalTime").ToString();

                        // filling the "gen_start_time"
                        rTask.gen_start_time = box.GetPropertyDateTime("GenerationStartTime").ToString();

                        // filling the "num_hyp"
                        rTask.num_hyp = box.GetPropertyLong("GenerationNrOfHypotheses");

                        // filling the "num_tests"
                        rTask.num_tests = box.GetPropertyLong("GenerationNrOfTests");

                        // adding Task to XML
                        resultString += rTask.ToXML();
                    }
                    catch (System.Exception e)
                    {
                        ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                    }
                }

                #endregion
            }

            #endregion

            // root element
            resultString += "</active_list>";

#if (LADENI)
            // generating of error message:
            if (!String.IsNullOrEmpty(ErrStr))  // LADICI
            {
                MessageBox.Show("Pri nacitani Task doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Kody - storing output to file "XMLTaskExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLTaskExample.xml");
#endif

            return(resultString);
        }
        /// <summary>
        /// Returns XML string with all occurences of Active element "Column".
        /// </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 Column

            #region   searching a processing of each boxes Column (DataMiningCommon.Column)

            IBoxModule[] AttrBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "DataMiningCommon.Column");


            // processing of each box Column
            foreach (IBoxModule ABox in AttrBoxes)
            {
                try
                {
                    Rec_column rColumn = new Rec_column(); // zaznam o novem sloupci

                    // searching ID
                    rColumn.id = "column" + ABox.ProjectIdentifier.ToString();

                    // 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");
                    }
                    rColumn.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");
                    }
                    rColumn.matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue;

                    // searching name of column
                    rColumn.column_name = ABox.GetPropertyString("Name");

                    // searching type of values
                    rColumn.value_type = ABox.GetPropertyString("ValueSubType");

                    // searching Min
                    rColumn.min = ABox.GetPropertyString("ValueMin");

                    // searching Max
                    rColumn.max = ABox.GetPropertyString("ValueMax");

                    // searching Avg
                    rColumn.avg = ABox.GetPropertyString("ValueAverage");

                    // adding item to XML
                    resultString += rColumn.ToXML();
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + ABox.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                }
            }

            #endregion


            resultString += "</active_list>";

#if (LADENI)
            // Kody - storing output to file "XMLColumnExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLColumnExample.xml");

            if (ErrStr != "")
            {
                MessageBox.Show("Chyby pri generating seznamu Boolskych cedent:\n" + ErrStr);
            }
#endif

            return(resultString);
        }
Example #9
0
        /// <summary>
        /// Returns XML string with all occurences of Active element "SD-KL hypothesis".
        /// </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 PropName = "Hypotheses";  // name of property which contain a list of hypotheses
            // searching all boxes SD-KL-tasks
            IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.SDKLTask");

            // processing of each box -  searching all KL-hypotheses
            string ErrStr = "";             // error report

            string matrix_name = "unknown"; // analyzed data matrix name
            string db_name     = "unknown"; // analyzed database name
            string task_name   = "unknown"; // task name - given with user name of box FFTTast

            // creatind delegates for functions of quantifiers
            // "sum of values"
            ContingencyTable.QuantifierValue <TwoDimensionalContingencyTable> sum_delegat = new ContingencyTable.QuantifierValue <TwoDimensionalContingencyTable>(TwoDimensionalContingencyTable.GetSumOfValues);
            // "min value"
            ContingencyTable.QuantifierValue <TwoDimensionalContingencyTable> min_delegat = new ContingencyTable.QuantifierValue <TwoDimensionalContingencyTable>(TwoDimensionalContingencyTable.GetMinValue);
            // "max value"
            ContingencyTable.QuantifierValue <TwoDimensionalContingencyTable> max_delegat = new ContingencyTable.QuantifierValue <TwoDimensionalContingencyTable>(TwoDimensionalContingencyTable.GetMaxValue);



            #region Loop - processing of each KL-Task from array TaskBoxes

            foreach (IBoxModule box in TaskBoxes)
            {
                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");
                    }
                    db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue;

                    // 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");
                    }
                    matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue;

                    // searching task name
                    task_name = box.UserName;

                    // searching the list of all hypotheses in this task
                    HypothesesT        HypT    = box.GetPropertyOther(PropName) as HypothesesT;
                    HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[];

                    // records for storing the results
                    Rec_hyp_SDKL     rHyp  = new Rec_hyp_SDKL();     // SD-KL hypothesis
                    Rec_ti_attribute rAnt  = new Rec_ti_attribute(); // Antecedent (Row attributes)
                    Rec_ti_attribute rSuc  = new Rec_ti_attribute(); // Succedent (Column attributes)
                    Rec_ti_cedent    rCon  = new Rec_ti_cedent();    // condition
                    Rec_ti_cedent    rSet1 = new Rec_ti_cedent();    // set 1
                    Rec_ti_cedent    rSet2 = new Rec_ti_cedent();    // set 2


                    #region Loop - processing of each hypotheses jedne krabicky SDKLTask
                    // Loop over all hypotheses
                    for (int i = 0; i < HypList.GetLength(0); i++)
                    {
                        #region element hyp_SDKL

                        rHyp.id                = "hypSDKL" + box.ProjectIdentifier.ToString() + "_" + i.ToString();
                        rHyp.db_name           = db_name;
                        rHyp.matrix_name       = matrix_name;
                        rHyp.task_name         = task_name;
                        rHyp.row_attributes    = "r_attr" + rHyp.id;
                        rHyp.column_attributes = "c_attr" + rHyp.id;
                        rHyp.condition         = "con" + rHyp.id;
                        rHyp.set1              = "set1" + rHyp.id;
                        rHyp.set2              = "set2" + rHyp.id;
                        TwoDimensionalContingencyTable CT1 = new TwoDimensionalContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows);  // Contingency Table 1
                        TwoDimensionalContingencyTable CT2 = new TwoDimensionalContingencyTable(HypList[i].quantifierSetting.secondContingencyTableRows); // Contingency Table 2
                        rHyp.Tab1 = HypList[i].quantifierSetting.firstContingencyTableRows;
                        rHyp.Tab2 = HypList[i].quantifierSetting.secondContingencyTableRows;


                        // values of quantifiers - set1
                        try
                        {
                            rHyp.sum1    = CT1.SumOfValues.ToString();
                            rHyp.min1    = CT1.MinValue.ToString();
                            rHyp.max1    = CT1.MaxValue.ToString();
                            rHyp.chi_sq1 = TwoDimensionalContingencyTable.ChiSquare(CT1).ToString();
                            rHyp.fnc_s1  = TwoDimensionalContingencyTable.SumOfRowMaximumsValue(CT1).ToString();
                            rHyp.fnc_r1  = TwoDimensionalContingencyTable.MinOfRowMaximumsValue(CT1).ToString();
                            rHyp.h_c1    = CT1.MarginalColumnEntropy.ToString();
                            rHyp.h_r1    = CT1.MarginalRowEntropy.ToString();
                            rHyp.h_c_r1  = TwoDimensionalContingencyTable.ConditionalCREntropyValue(CT1).ToString();
                            rHyp.mi1     = CT1.MutualInformation.ToString();
                            //rHyp.aic = CT.???;  TODO
                            rHyp.kend1 = TwoDimensionalContingencyTable.KendalValue(CT1).ToString();
                        }
                        catch (System.Exception e) // TODO: Ferda ma chyby ve vypoctech -> opravit!
                        {
                            ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": chyba pri vypoctu quantifier: " + e.Message + "\n";
                        }
                        // values of quantifiers - set2
                        try
                        {
                            rHyp.sum2    = CT2.SumOfValues.ToString();
                            rHyp.min2    = CT2.MinValue.ToString();
                            rHyp.max2    = CT2.MaxValue.ToString();
                            rHyp.chi_sq2 = TwoDimensionalContingencyTable.ChiSquare(CT2).ToString();
                            rHyp.fnc_s2  = TwoDimensionalContingencyTable.SumOfRowMaximumsValue(CT2).ToString();
                            rHyp.fnc_r2  = TwoDimensionalContingencyTable.MinOfRowMaximumsValue(CT2).ToString();
                            rHyp.h_c2    = CT2.MarginalColumnEntropy.ToString();
                            rHyp.h_r2    = CT2.MarginalRowEntropy.ToString();
                            rHyp.h_c_r2  = TwoDimensionalContingencyTable.ConditionalCREntropyValue(CT2).ToString();
                            rHyp.mi2     = CT2.MutualInformation.ToString();
                            //rHyp.aic = CT.???;  TODO
                            rHyp.kend2 = TwoDimensionalContingencyTable.KendalValue(CT2).ToString();
                        }
                        catch (System.Exception e) // Ferda ma chyby ve vypoctech!
                        {
                            ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": chyba pri vypoctu quantifier: " + e.Message + "\n";
                        }
                        // values of quantifiers - diffrent of set1 a set2
                        try
                        {
                            rHyp.da_sum = TwoDimensionalContingencyTable.Value <TwoDimensionalContingencyTable>(sum_delegat, CT1, CT2, OperationModeEnum.DifferencesOfAbsoluteFrequencies).ToString();
                            rHyp.da_min = TwoDimensionalContingencyTable.Value <TwoDimensionalContingencyTable>(min_delegat, CT1, CT2, OperationModeEnum.DifferencesOfAbsoluteFrequencies).ToString();
                            rHyp.da_max = TwoDimensionalContingencyTable.Value <TwoDimensionalContingencyTable>(max_delegat, CT1, CT2, OperationModeEnum.DifferencesOfAbsoluteFrequencies).ToString();
                            rHyp.dr_sum = TwoDimensionalContingencyTable.Value <TwoDimensionalContingencyTable>(sum_delegat, CT1, CT2, OperationModeEnum.DifferencesOfRelativeFrequencies).ToString();
                            rHyp.dr_min = TwoDimensionalContingencyTable.Value <TwoDimensionalContingencyTable>(min_delegat, CT1, CT2, OperationModeEnum.DifferencesOfRelativeFrequencies).ToString();
                            rHyp.dr_max = TwoDimensionalContingencyTable.Value <TwoDimensionalContingencyTable>(max_delegat, CT1, CT2, OperationModeEnum.DifferencesOfRelativeFrequencies).ToString();
                        }
                        catch (System.Exception e) // Ferda ma chyby ve vypoctech!
                        {
                            ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": chyba pri vypoctu quantifier: " + e.Message + "\n";
                        }



                        #endregion

                        #region element ti_attribute Row attributes (Antecedent)

                        rAnt.id    = rHyp.row_attributes;
                        rAnt.type  = "Row attributes";
                        rAnt.quant = "";   // deleting previous value
                        // category
                        List <Rec_ti_category> Cat_a = new List <Rec_ti_category>();
                        foreach (LiteralStruct lit in HypList[i].literals)
                        {
                            if (lit.cedentType == CedentEnum.Antecedent)
                            {
                                rAnt.quant += lit.literalName;
                                foreach (string s in lit.categoriesNames)
                                {
                                    Rec_ti_category C = new Rec_ti_category();
                                    C.value = s;
                                    Cat_a.Add(C);
                                }
                            }
                        }

                        #endregion

                        #region element ti_attribute Column attributes (Succedent)

                        rSuc.id    = rHyp.column_attributes;
                        rSuc.type  = "Column attributes";
                        rSuc.quant = "";   // deleting previous value
                        // category
                        List <Rec_ti_category> Cat_s = new List <Rec_ti_category>();
                        foreach (LiteralStruct lit in HypList[i].literals)
                        {
                            if (lit.cedentType == CedentEnum.Succedent)
                            {
                                rSuc.quant += lit.literalName;
                                foreach (string s in lit.categoriesNames)
                                {
                                    Rec_ti_category C = new Rec_ti_category();
                                    C.value = s;
                                    Cat_s.Add(C);
                                }
                            }
                        }

                        #endregion

                        #region element ti_cedent (Condition)

                        rCon.id   = "con" + rHyp.id;
                        rCon.type = "Condition";
                        // literals
                        int litCounter = 0;  // counter of literals of this hypothesis
                        List <Rec_ti_literal> Lit_c = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Condition)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_c.Add(l);
                            }
                        }

                        #endregion

                        #region element ti_cedent (Set1)

                        rSet1.id   = rHyp.set1;
                        rSet1.type = "First Set";
                        // literals
                        List <Rec_ti_literal> Lit_s1 = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.FirstSet)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_s1.Add(l);
                            }
                        }

                        #endregion

                        #region element ti_cedent (Set2)

                        rSet2.id   = rHyp.set2;
                        rSet2.type = "Second Set";
                        // literals
                        List <Rec_ti_literal> Lit_s2 = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.SecondSet)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_s2.Add(l);
                            }
                        }

                        #endregion


                        #region Generating of one hypothesis to XML string

                        string oneHypString = "";
                        // generating hypotheses to XML
                        oneHypString += rHyp.ToXML();
                        // generating Row attributes (Antecedent) to XML
                        oneHypString += rAnt.ToXML(Cat_a);
                        // generating Column attributes (Succedent) to XML
                        oneHypString += rSuc.ToXML(Cat_s);
                        // generating Condition to XML
                        oneHypString += rCon.ToXML(Lit_c);
                        // generating Set1 to XML
                        oneHypString += rSet1.ToXML(Lit_s1);
                        // generating Set2 to XML
                        oneHypString += rSet2.ToXML(Lit_s2);



                        resultString += oneHypString;

                        #endregion
                    }
                    #endregion
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                }
            }
            #endregion


            // root element
            resultString += "</active_list>";

#if (LADENI)
            // generating of error message:
            if (!String.IsNullOrEmpty(ErrStr))  // LADICI
            {
                MessageBox.Show("Pri nacitani SD-KL hypotheses doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // LADICI - Kody - storing output to file "XMLsd4fthypExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLsdKLhypExample.xml");
#endif

            return(resultString);
        }
Example #10
0
        /// <summary>
        /// Implementation of Active element "CF hypothesis"
        /// </summary>
        /// <param name="index">index of data source in data sources tab </param>
        /// <returns>Returns XML string with all occurences of Active element type "CF hypothesis" from data source with given index</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 PropName = "Hypotheses";  // name of property which contain a list of hypotheses
            // searching all boxes CF-task
            IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.CFTask");

            // processing of each box - searching all CF-hypotheses
            string ErrStr = "";             // error report

            string matrix_name = "unknown"; // analyzed data matrix name
            string db_name     = "unknown"; // analyzed database name
            string task_name   = "unknown"; // task name - given by user name of box FFTTast


            #region Loop - processing of each CF-Tasku from array TaskBoxes

            foreach (IBoxModule box in TaskBoxes)
            {
                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");
                    }
                    db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue;

                    // 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");
                    }
                    matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue;

                    // searching task name
                    task_name = box.UserName;

                    // searching the list of all hypotheses in this task
                    HypothesesT        HypT    = box.GetPropertyOther(PropName) as HypothesesT;
                    HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[];

                    // records for storing the results
                    Rec_hyp_cf       rHyp = new Rec_hyp_cf();       // CF hypothesis
                    Rec_ti_attribute rAnt = new Rec_ti_attribute(); // Antecedent (Attributes)
                    Rec_ti_cedent    rCon = new Rec_ti_cedent();    // condition


                    #region Loop - processing of each hypotheses jedne krabicky CFTask
                    // Loop over all hypotheses
                    for (int i = 0; i < HypList.GetLength(0); i++)
                    {
                        #region element hyp_cf

                        rHyp.id          = "hypcf" + box.ProjectIdentifier.ToString() + "_" + i.ToString();
                        rHyp.db_name     = db_name;
                        rHyp.matrix_name = matrix_name;
                        rHyp.task_name   = task_name;
                        rHyp.attributes  = "attr" + rHyp.id;
                        rHyp.condition   = "con" + rHyp.id;
                        OneDimensionalContingencyTable CT = new OneDimensionalContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows); // Contingency Table
                        rHyp.Tab = HypList[i].quantifierSetting.firstContingencyTableRows[0];


                        // values of quantifiers
                        try
                        {
                            rHyp.sum     = CT.SumOfValues.ToString();
                            rHyp.min     = CT.MinValue.ToString();
                            rHyp.max     = CT.MaxValue.ToString();
                            rHyp.v       = CT.VariationRatio.ToString();
                            rHyp.nom_var = CT.NominalVariation.ToString();
                            rHyp.dor_var = CT.DiscreteOrdinaryVariation.ToString();
                            rHyp.avg_a   = CT.ArithmeticAverage.ToString();
                            rHyp.avg_g   = CT.GeometricAverage.ToString();
                            rHyp.var     = CT.Variance.ToString();
                            rHyp.st_dev  = CT.StandardDeviation.ToString();
                            rHyp.skew    = CT.Skewness.ToString();
                            rHyp.asym    = CT.Asymentry.ToString();
                        }
                        catch (System.Exception e) // !!There are some errors in Ferda quantifier values! !
                        {
                            ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": chyba pri vypoctu kvantifikatoru: " + e.Message + "\n";
                        }


                        #endregion

                        #region element ti_attribute  Attributes (Antecedent)

                        rAnt.id    = rHyp.attributes;
                        rAnt.type  = "Attributes";
                        rAnt.quant = "";   // deleting previous value
                        // category
                        List <Rec_ti_category> Cat_a = new List <Rec_ti_category>();
                        foreach (LiteralStruct lit in HypList[i].literals)
                        {
                            if (lit.cedentType == CedentEnum.Antecedent)
                            {
                                rAnt.quant += lit.literalName;
                                foreach (string s in lit.categoriesNames)
                                {
                                    Rec_ti_category C = new Rec_ti_category();
                                    C.value = s;
                                    Cat_a.Add(C);
                                }
                            }
                        }

                        #endregion

                        #region element ti_cedent (Condition)
                        int litCounter = 0;  // counter of literals of this cedent
                        rCon.id   = "con" + rHyp.id;
                        rCon.type = "Condition";
                        // literals
                        List <Rec_ti_literal> Lit_c = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Condition)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_c.Add(l);
                            }
                        }

                        #endregion

                        #region Generating of one hypotheses to XML string

                        string oneHypString = "";
                        // generating hypotheses to XML
                        oneHypString += rHyp.ToXML();
                        // generating Attributes (Antecedent) to XML
                        oneHypString += rAnt.ToXML(Cat_a);
                        // generating Condition to XML
                        oneHypString += rCon.ToXML(Lit_c);

                        resultString += oneHypString;

                        #endregion
                    }
                    #endregion
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                }
            }
            #endregion

            // root element
            resultString += "</active_list>";

#if (LADENI)
            // generating of error message:
            if (!String.IsNullOrEmpty(ErrStr))  // LADICI
            {
                MessageBox.Show("Pri nacitani CF hypotheses doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // LADICI - Kody - storing output to file "XMLsd4fthypExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLcfhypExample.xml");
#endif

            return(resultString);
        }
        /// <summary>
        /// Returns XML string with all occurences of Active element "4FT hypothesis".
        /// </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 PropName = "Hypotheses";  // name of Property, which contain list of hypotheses

            // searching all boxes with type "4FT-task"
            IBoxModule[] FFTTaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.FFTTask");



            // loop over all boxes - getting all hypotheses

            string ErrStr = "";             // error report

            string matrix_name = "unknown"; // analyzed data matrix name
            string db_name     = "unknown"; // analyzed database name
            string task_name   = "unknown"; // task name - given with user name of box FFTTast

            #region Loop - processing of each 4ft-Task from array FFTTaskBoxes

            foreach (IBoxModule box in FFTTaskBoxes)
            {
                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");
                    }
                    db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue;

                    // 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");
                    }
                    matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue;

                    // searching task name
                    task_name = box.UserName;

                    // searching the list of all hypotheses in this task
                    HypothesesT        HypT    = box.GetPropertyOther(PropName) as HypothesesT;
                    HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[];

                    // records for storing the results
                    Rec_hyp_4ft   rHyp = new Rec_hyp_4ft();    // hypothesis
                    Rec_ti_cedent rAnt = new Rec_ti_cedent();  // antecedent
                    Rec_ti_cedent rSuc = new Rec_ti_cedent();  // succedent
                    Rec_ti_cedent rCon = new Rec_ti_cedent();  // condition

                    #region Loop - processing of each hypotez jedne krabicky FFTTask
                    // Loop over all hypotheses
                    for (int i = 0; i < HypList.GetLength(0); i++)
                    {
                        #region element hyp_4ft

                        rHyp.id          = "hyp4ft" + box.ProjectIdentifier.ToString() + "_" + i.ToString();
                        rHyp.db_name     = db_name;
                        rHyp.matrix_name = matrix_name;
                        rHyp.task_name   = task_name;
                        rHyp.antecedent  = "ant" + rHyp.id;
                        rHyp.succedent   = "suc" + rHyp.id;
                        rHyp.condition   = "con" + rHyp.id;
                        FourFoldContingencyTable FFT = new FourFoldContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows);
                        rHyp.a = FFT.A.ToString();
                        rHyp.b = FFT.B.ToString();
                        rHyp.c = FFT.C.ToString();
                        rHyp.d = FFT.D.ToString();
                        // values of quantifiers
                        rHyp.conf    = FourFoldContingencyTable.FoundedImplicationValue(FFT).ToString();       // Founded implication (a/a+b)
                        rHyp.d_conf  = FourFoldContingencyTable.DoubleFoundedImplicationValue(FFT).ToString(); // Double Founded implication (a/a+b+c)
                        rHyp.e_conf  = FourFoldContingencyTable.FoundedEquivalenceValue(FFT).ToString();       // Founded Equivalence (a+d)/(a+b+c+d)  ??? BUG ve Ferdovi
                        rHyp.support = FourFoldContingencyTable.BaseCeilValue(FFT).ToString();                 //???  Support (a/a+b+c+d)
                        // helping variable
                        double avg_diff = FourFoldContingencyTable.AboveAverageImplicationValue(FFT) - 1;      // Averafe difference ((a*(a+b+c+d))/((a+b)*(a+c)) -1)
                        rHyp.avg_diff = avg_diff.ToString();

                        rHyp.fisher = FFT.FisherValue().ToString();
                        rHyp.chi_sq = FFT.ChiSquareValue().ToString();

                        #endregion


                        #region element ti_cedent (Antecedent)

                        rAnt.id   = "ant" + rHyp.id;
                        rAnt.type = "Antecedent";
                        // literals
                        int litCounter = 0;  // counter of literals of this hypotheses
                        List <Rec_ti_literal> Lit_a = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Antecedent)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_a.Add(l);
                            }
                        }

                        #endregion

                        #region element ti_cedent (Succedent)

                        rSuc.id   = "suc" + rHyp.id;
                        rSuc.type = "Succedent";
                        // literals
                        List <Rec_ti_literal> Lit_s = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Succedent)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_s.Add(l);
                            }
                        }

                        #endregion

                        #region element ti_cedent (Condition)

                        rCon.id   = "con" + rHyp.id;
                        rCon.type = "Condition";
                        // literals
                        List <Rec_ti_literal> Lit_c = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Condition)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_c.Add(l);
                            }
                        }

                        #endregion

                        #region Generating of one hypotheses to XML string

                        string oneHypString = "";
                        // generating hypotheses to XML
                        oneHypString += rHyp.ToXML();
                        // generating Antecedent to XML
                        oneHypString += rAnt.ToXML(Lit_a);
                        // generating Succedent to XML
                        oneHypString += rSuc.ToXML(Lit_s);
                        // generating Condition to XML
                        oneHypString += rCon.ToXML(Lit_c);

                        resultString += oneHypString;

                        #endregion
                    }
                    #endregion
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + box.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 hypotez doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Kody - storing output to file "XML4fthypExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XML4fthypExample.xml");
#endif
            return(resultString);
        }
        /// <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);
        }
Example #13
0
        /// <summary>
        /// Returns XML string with all occurences of Active element "Quantifier".
        /// </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 report

            // 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>();
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.FFTTask", "FFTQuantifier", "4FT"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDFFTTask", "SDFFTQuantifier", "SD-4FT"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.KLTask", "KLQuantifier", "KL"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDKLTask", "SDKLQuantifier", "SD-KL"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.CFTask", "CFQuantifier", "CF"));
            TypyTask.Add(new TaskTypeStruct("LISpMinerTasks.SDCFTask", "SDCFQuantifier", "SD-CF"));

            #region Loop over all Task types

            foreach (TaskTypeStruct TTS in TypyTask)
            {
                // searching all Task boxes with given type
                IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, TTS.TaskBoxType);
                #region Loop - processing of each Task with given type

                foreach (IBoxModule box in TaskBoxes)
                {
                    // record of basic quantifier
                    Rec_quantifier rQuant = new Rec_quantifier();

                    // fillinf ID of quantifier
                    string id = "quant" + box.ProjectIdentifier;

                    try
                    {
                        // searching data source name (database) - not mandatory!
                        IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.Database");
                        if (db_names.GetLength(0) == 1)  // searched more than one data source or neither one
                        {
                            rQuant.db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue;
                        }

                        // searching data matrix name - not mandatory!
                        IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.DataMatrix");
                        if (matrix_names.GetLength(0) == 1)  // searched more than one data source or neither one
                        {
                            rQuant.matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue;
                        }

                        // searching task name
                        rQuant.task_name = box.UserName;

                        // filling the type of quantifier (task)
                        rQuant.task_type = TTS.TypeString;

                        // searching all boxes - basic quantifiers of given Task
                        IBoxModule[] BasicQuantsBoxes = box.GetConnections(TTS.QuantSocketName);

                        #region Loop - over all basic quantifiers

                        int bq_num = 0;  // helping variable - due to generating ID
                        foreach (IBoxModule BQB in BasicQuantsBoxes)
                        {
                            Rec_quantifier rQuant1 = rQuant;

                            // setting ID
                            rQuant1.id = id + "_" + bq_num.ToString();
                            bq_num++;

                            // filling the item "name"
                            rQuant1.name = BQB.UserName;

                            // filling the item "type"
                            if (BQB.MadeInCreator.Identifier.IndexOf("Functional") != -1)
                            {
                                rQuant1.type = "Functional";
                            }
                            else if (BQB.MadeInCreator.Identifier.IndexOf("Aggregation") != -1)
                            {
                                rQuant1.type = "Aggregation";
                            }

                            // searching all items of basic quantifier and its values
                            List <Rec_quant_item> QItems = new List <Rec_quant_item>();

                            PropertyInfo[] PI = BQB.MadeInCreator.Properties;
                            foreach (PropertyInfo pi in PI)
                            {
                                // new item setting
                                Rec_quant_item item = new Rec_quant_item();
                                // filling the items
                                item.name = pi.name; // "name"


                                if (pi.typeClassIceId.IndexOf("Double") != -1)
                                {
                                    item.value = BQB.GetPropertyDouble(pi.name).ToString();
                                }
                                else if (pi.typeClassIceId.IndexOf("String") != -1)
                                {
                                    item.value = BQB.GetPropertyString(pi.name);
                                }
                                else if (pi.typeClassIceId.IndexOf("Float") != -1)
                                {
                                    item.value = BQB.GetPropertyFloat(pi.name).ToString();
                                }
                                else if (pi.typeClassIceId.IndexOf("Int") != -1)
                                {
                                    item.value = BQB.GetPropertyInt(pi.name).ToString();
                                }
                                else if (pi.typeClassIceId.IndexOf("Long") != -1)
                                {
                                    item.value = BQB.GetPropertyLong(pi.name).ToString();
                                }
                                else if (pi.typeClassIceId.IndexOf("Date") != -1)
                                {
                                    item.value = BQB.GetPropertyDate(pi.name).ToString();
                                }
                                else if (pi.typeClassIceId.IndexOf("Time") != -1)
                                {
                                    item.value = BQB.GetPropertyTime(pi.name).ToString();
                                }
                                else if (pi.typeClassIceId.IndexOf("Bool") != -1)
                                {
                                    item.value = BQB.GetPropertyBool(pi.name).ToString();
                                }

                                QItems.Add(item);
                            }

                            #endregion


                            // adding quantifier to XML
                            resultString += rQuant1.ToXML(QItems);
                        }
                    }
                    catch (System.Exception e)
                    {
                        ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                    }
                }
                #endregion
            }

            #endregion

            // root element
            resultString += "</active_list>";

#if (LADENI)
            // generating of error message:
            if (!String.IsNullOrEmpty(ErrStr))  // LADICI
            {
                MessageBox.Show("Pri nacitani quantifier doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Kody - storing output to file "XMLQuantExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLQuantExample.xml");
#endif

            return(resultString);
        }
        /// <summary>
        /// Returns XML string with all occurences of Active element "SD-4FFT hypothesis".
        /// </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 PropName = "Hypotheses";  // name of property which contain a list of hypotheses
            // searching all boxes SD-4FT-uloh
            IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.SDFFTTask");

            // processing of each box - searching all 4ft-hypotheses
            string ErrStr = "";             // error report

            string matrix_name = "unknown"; // analyzed data matrix name
            string db_name     = "unknown"; // analyzed database name
            string task_name   = "unknown"; // task name - given with user name of box FFTTast

            // creating delegate of quantifier function - "sum of value"
            ContingencyTable.QuantifierValue <FourFoldContingencyTable> sum_delegat = new ContingencyTable.QuantifierValue <FourFoldContingencyTable>(FourFoldContingencyTable.GetSumOfValues);



            #region Loop - processing of each SD-4ft-Task from array TaskBoxes

            foreach (IBoxModule box in TaskBoxes)
            {
                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");
                    }
                    db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue;

                    // 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");
                    }
                    matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue;

                    // searching task name
                    task_name = box.UserName;

                    // searching the list of all hypotheses in this task
                    HypothesesT        HypT    = box.GetPropertyOther(PropName) as HypothesesT;
                    HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[];

                    // records for storing the results
                    Rec_hyp_sd4ft rHyp  = new Rec_hyp_sd4ft(); // hypothesis
                    Rec_ti_cedent rAnt  = new Rec_ti_cedent(); // antecedent
                    Rec_ti_cedent rSuc  = new Rec_ti_cedent(); // succedent
                    Rec_ti_cedent rCon  = new Rec_ti_cedent(); // condition
                    Rec_ti_cedent rSet1 = new Rec_ti_cedent(); // set 1
                    Rec_ti_cedent rSet2 = new Rec_ti_cedent(); // set 2

                    #region Loop - processing of each hypotheses of one SDFFTTask box
                    // Loop over all hypotheses
                    for (int i = 0; i < HypList.GetLength(0); i++)
                    {
                        #region element hyp_sd4ft

                        rHyp.id          = "hypsd4ft" + box.ProjectIdentifier.ToString() + "_" + i.ToString();
                        rHyp.db_name     = db_name;
                        rHyp.matrix_name = matrix_name;
                        rHyp.task_name   = task_name;
                        rHyp.antecedent  = "ant" + rHyp.id;
                        rHyp.succedent   = "suc" + rHyp.id;
                        rHyp.condition   = "con" + rHyp.id;
                        rHyp.set1        = "set1" + rHyp.id;
                        rHyp.set2        = "set2" + rHyp.id;
                        FourFoldContingencyTable FFT1 = new FourFoldContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows);
                        FourFoldContingencyTable FFT2 = new FourFoldContingencyTable(HypList[i].quantifierSetting.secondContingencyTableRows);
                        rHyp.a = FFT1.A.ToString();
                        rHyp.b = FFT1.B.ToString();
                        rHyp.c = FFT1.C.ToString();
                        rHyp.d = FFT1.D.ToString();
                        rHyp.e = FFT2.A.ToString();
                        rHyp.f = FFT2.B.ToString();
                        rHyp.g = FFT2.C.ToString();
                        rHyp.h = FFT2.D.ToString();

                        // values of quantifiers - first set
                        double conf1 = FourFoldContingencyTable.FoundedImplicationValue(FFT1);              // Founded implication (a/a+b)
                        rHyp.conf1 = conf1.ToString();
                        double d_conf1 = FourFoldContingencyTable.DoubleFoundedImplicationValue(FFT1);      // Double Founded implication (a/a+b+c)
                        rHyp.d_conf1 = d_conf1.ToString();
                        double e_conf1 = FourFoldContingencyTable.FoundedEquivalenceValue(FFT1);            // Founded Equivalence (a+d)/(a+b+c+d)  ??? BUG ve Ferdovi
                        rHyp.e_conf1  = e_conf1.ToString();
                        rHyp.support1 = FourFoldContingencyTable.BaseCeilValue(FFT1).ToString();            //???  Support (a/a+b+c+d)
                        // helping variable
                        double avg_diff1 = FourFoldContingencyTable.AboveAverageImplicationValue(FFT1) - 1; // Averafe difference ((a*(a+b+c+d))/((a+b)*(a+c)) -1)
                        rHyp.avg_diff1 = avg_diff1.ToString();
                        rHyp.fisher1   = FFT1.FisherValue().ToString();
                        rHyp.chi_sq1   = FFT1.ChiSquareValue().ToString();

                        // values of quantifiers - second set
                        double conf2 = FourFoldContingencyTable.FoundedImplicationValue(FFT2);              // Founded implication (a/a+b)
                        rHyp.conf2 = conf2.ToString();
                        double d_conf2 = FourFoldContingencyTable.DoubleFoundedImplicationValue(FFT2);      // Double Founded implication (a/a+b+c)
                        rHyp.d_conf2 = d_conf2.ToString();
                        double e_conf2 = FourFoldContingencyTable.FoundedEquivalenceValue(FFT2);            // Founded Equivalence (a+d)/(a+b+c+d)  ??? BUG ve Ferdovi
                        rHyp.e_conf2  = e_conf2.ToString();
                        rHyp.support2 = FourFoldContingencyTable.BaseCeilValue(FFT2).ToString();            //???  Support (a/a+b+c+d)
                        // helping variable
                        double avg_diff2 = FourFoldContingencyTable.AboveAverageImplicationValue(FFT2) - 1; // Averafe difference ((a*(a+b+c+d))/((a+b)*(a+c)) -1)
                        rHyp.avg_diff2 = avg_diff2.ToString();
                        rHyp.fisher2   = FFT2.FisherValue().ToString();
                        rHyp.chi_sq2   = FFT2.ChiSquareValue().ToString();

                        // values of quantifiers - diffrent of first and second set
                        rHyp.dr_sum = FourFoldContingencyTable.Value <FourFoldContingencyTable>(sum_delegat, FFT1, FFT2, OperationModeEnum.DifferencesOfRelativeFrequencies).ToString();
                        double df_conf = FourFoldContingencyTable.Combine(conf1, conf2, OperationModeEnum.DifferenceOfQuantifierValues);
                        rHyp.df_conf = df_conf.ToString();
                        double df_dfui = FourFoldContingencyTable.Combine(d_conf1, d_conf2, OperationModeEnum.DifferenceOfQuantifierValues);
                        rHyp.df_dfui = df_dfui.ToString();
                        double df_fue = FourFoldContingencyTable.Combine(e_conf1, e_conf2, OperationModeEnum.DifferenceOfQuantifierValues);
                        rHyp.df_fue = df_fue.ToString();
                        double df_avg = FourFoldContingencyTable.Combine(avg_diff1, avg_diff2, OperationModeEnum.DifferenceOfQuantifierValues);
                        rHyp.df_avg = df_avg.ToString();

                        #endregion

                        #region element ti_cedent (Antecedent)

                        rAnt.id   = rHyp.antecedent;
                        rAnt.type = "Antecedent";
                        // literals
                        int litCounter = 0;  // counter of literals of this hypotheses
                        List <Rec_ti_literal> Lit_a = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Antecedent)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_a.Add(l);
                            }
                        }

                        #endregion

                        #region element ti_cedent (Succedent)

                        rSuc.id   = rHyp.succedent;
                        rSuc.type = "Succedent";
                        // literals
                        List <Rec_ti_literal> Lit_s = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Succedent)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_s.Add(l);
                            }
                        }

                        #endregion

                        #region element ti_cedent (Condition)

                        rCon.id   = rHyp.condition;
                        rCon.type = "Condition";
                        // literals
                        List <Rec_ti_literal> Lit_c = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.Condition)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_c.Add(l);
                            }
                        }

                        #endregion

                        #region element ti_cedent (First Set)

                        rSet1.id   = rHyp.set1;
                        rSet1.type = "First Set";
                        // literals
                        List <Rec_ti_literal> Lit_s1 = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.FirstSet)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_s1.Add(l);
                            }
                        }

                        #endregion

                        #region element ti_cedent (Second Set)

                        rSet2.id   = rHyp.set2;
                        rSet2.type = "Second Set";
                        // literals
                        List <Rec_ti_literal> Lit_s2 = new List <Rec_ti_literal>();
                        foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals)
                        {
                            if (lit.cedentType == CedentEnum.SecondSet)
                            {
                                Rec_ti_literal l = new Rec_ti_literal();
                                l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString();
                                litCounter++;
                                if (lit.negation)
                                {
                                    l.quant = "¬";
                                }
                                l.quant += lit.literalName;
                                int counter = 0;
                                foreach (string s in lit.categoriesNames)
                                {
                                    if (counter > 0)
                                    {
                                        l.value += ",";
                                    }
                                    l.value += s;
                                    counter++;
                                }
                                Lit_s2.Add(l);
                            }
                        }

                        #endregion

                        #region Generating of one hypotheses to XML string

                        string oneHypString = "";
                        // generating hypotheses to XML
                        oneHypString += rHyp.ToXML();
                        // generating Antecedent to XML
                        oneHypString += rAnt.ToXML(Lit_a);
                        // generating Succedent to XML
                        oneHypString += rSuc.ToXML(Lit_s);
                        // generating Condition to XML
                        oneHypString += rCon.ToXML(Lit_c);
                        // generating First Set to XML
                        oneHypString += rSet1.ToXML(Lit_s1);
                        // generating Second Set to XML
                        oneHypString += rSet2.ToXML(Lit_s2);


                        resultString += oneHypString;

                        #endregion
                    }
                    #endregion
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                }
            }
            #endregion

            // root element
            resultString += "</active_list>";

#if (LADENI)
            // generating of error message:
            if (!String.IsNullOrEmpty(ErrStr))  // LADICI
            {
                MessageBox.Show("Pri nacitani SD4FT hypotheses doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // LADICI - Kody - storing output to file "XMLsd4fthypExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLsd4fthypExample.xml");
#endif

            return(resultString);
        }
Example #15
0
        /// <summary>
        /// Returns XML string with all occurences of Active element "Data matrix".
        /// </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 "Data matrix"

            #region   searching a processing of each boxes Column (DataMiningCommon.DataMatrix)

            IBoxModule[] MatrBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "DataMiningCommon.DataMatrix");


            // processing of each box Column
            foreach (IBoxModule MBox in MatrBoxes)
            {
                try
                {
                    Rec_data_matrix rMatrix = new Rec_data_matrix(); // zaznam o datove matici

                    // searching ID
                    rMatrix.id = "matrix" + MBox.ProjectIdentifier.ToString();

                    // searching data source name (database)
                    IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(MBox, "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");
                    }
                    rMatrix.db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue;

                    // searching data matrix name
                    rMatrix.matrix_name = MBox.GetPropertyString("Name");

                    // searching records count
                    rMatrix.record_count = MBox.GetPropertyLong("RecordCount").ToString();

                    // adding item to XML
                    resultString += rMatrix.ToXML();
                }
                catch (System.Exception e)
                {
                    ErrStr += "Box ProjectIdentifier=" + MBox.ProjectIdentifier.ToString() + ": " + e.Message + "\n";
                }
            }

            #endregion


            resultString += "</active_list>";

#if (LADENI)
            // Kody - storing output to file "XMLData_matrixExample.xml" in directory
            XMLHelper.saveXMLexample(resultString, "../XML/XMLData_matrixExample.xml");

            if (ErrStr != "")
            {
                MessageBox.Show("Chyby pri generating seznamu Boolskych cedent:\n" + ErrStr);
            }
#endif

            return(resultString);
        }
        /// <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>
        /// 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);
        }