Пример #1
0
            public static List <PossibleKey> Find_PossibleKeys(AErgTupel _Ret)
            {
                LogHelper.LogApp($"{MethodBase.GetCurrentMethod().Name}");

                //Possible key list
                List <PossibleKey> _pkl = new List <PossibleKey>();
                //Functional dependency count
                Dictionary <string, int> _fdc = new Dictionary <string, int>();

                foreach (string _attr in _Ret.FunctionalDependencyGrid.Keys)
                {
                    _fdc.Add(_attr, _Ret.FunctionalDependencyGrid[_attr].Count(e => e.Value.HasValue && e.Value.Value));
                }

                //Turn dictionary to List for sorting
                List <KeyValuePair <string, int> > _fdc_list = _fdc.ToList();

                //Sort by Amount DESC
                _fdc_list.Sort((a, b) => b.Value.CompareTo(a.Value));
                //Find metric for best
                int max_fd = _fdc.First().Value;

                //Remove leser than best
                _fdc_list.RemoveAll(a => a.Value != max_fd);
                //Order by Amount of Attributes ASC
                _fdc_list.Sort((a, b) => a.Key.Count(c => c == ',').CompareTo(b.Key.Count(d => d == ',')));
                //Find metric for least Attributes
                int least_attr = _fdc_list.First().Key.Count(a => a == ',') + 1;

                //Remove lesser that best
                _fdc_list.RemoveAll(a => a.Key.Count(b => b == ',') + 1 != least_attr);
                //Convert back to Dictionary
                _fdc = _fdc_list.ToDictionary(a => a.Key, a => a.Value);

                if (_fdc.Count > 0)
                {
                    List <string> _loc_attrb = null;
                    foreach (string _str_attrb in _fdc.Keys)
                    {
                        string _str_clean = _str_attrb.Replace("[", "").Replace("]", "");
                        _loc_attrb = new List <string>(_str_clean.Split(','));

                        _pkl.Add(new PossibleKey(_Ret.Relation)
                        {
                            Attributes = _loc_attrb, Coverage = (double)max_fd / (double)(_Ret.FunctionalDependencyGrid.First().Value.Count - least_attr)
                        });
                    }
                }

                return(_pkl);
            }
Пример #2
0
        public static AErgTupel Analysis(string Database, string Relation)
        {
            AErgTupel _Ret = new AErgTupel(Database, Relation, DPAnalysis.AttributAnalyse_Results[Relation].First().Count_Rows.Value);

            _Ret.DocumentedKey = DPTupel_Helper.Get_DocumentedKey(Relation);

            _Ret.DocumentedDpenedencies = DPTupel_Helper.Get_DocumentedDependencies(Relation);

            if (DPAnalysis.AttributAnalyse_Results_Sort[Relation].First().Value.Count_Rows > 0)
            {
                _Ret.FunctionalDependencyGrid = DPTupel_Helper.CreateDependencyMatrixA(_Ret.Relation);
            }

            if (_Ret.FunctionalDependencyGrid != null && _Ret.DocumentedKey == null)
            {
                _Ret.PossibleKeys = DPTupel_Helper.Find_PossibleKeys(_Ret);
            }

            return(_Ret);
        }