Exemple #1
0
 public FProbAttributeBLL(FProbAttributeBLL attr)
 {
     this.primaryKey    = attr.primaryKey;
     this.idAttribute   = attr.idAttribute;
     this.attributeName = attr.attributeName;
     this.fproDataType  = attr.fproDataType;
     this.description   = attr.description;
     this.fproSchema    = attr.fproSchema;
 }
Exemple #2
0
 public FProbAttributeBLL()
 {
     this.primaryKey    = false;
     this.idAttribute   = -1;
     this.attributeName = string.Empty;
     this.fproDataType  = new FProDataTypeBLL();
     this.description   = string.Empty;
     this.fproSchema    = new FProbSchemaBLL();
 }
        public FProDataTypeBLL(FProDataTypeBLL fproDataType)
        {
            this.typeName     = fproDataType.typeName;
            this.dataType     = fproDataType.dataType;
            this.domainString = fproDataType.domainString;
            this.domainValues = new List <string>();

            foreach (string item in fproDataType.domainValues)
            {
                this.domainValues.Add(item);
            }
        }
Exemple #4
0
        /// <summary>
        /// Important! Calculate prob query expression, prob data from database
        /// </summary>
        /// <param name="valueOne"></param>
        /// <param name="valueTwo"></param>
        /// <param name="operaterStr"></param>
        /// <returns></returns>
        private string GetProbInterval(string valueOne, string valueTwo, string operaterStr)
        {
            double        minProb = 0, maxProb = 0;
            int           indexOne, indexTwo, countTripleOne, countTripleTwo;
            FProbTupleBLL tuple = this.tuple;
            string        typenameOne;
            string        typenameTwo;

            try
            {
                if (operaterStr.Contains("equal_ig") || operaterStr.Contains("equal_in") || operaterStr.Contains("equal_me"))         // Biểu thức so sánh bằng giữa hai thuộc tính trên cùng một bộ
                {
                    indexOne = IndexOf(valueOne);
                    indexTwo = IndexOf(valueTwo);
                    if (indexOne == -1 || indexTwo == -1)
                    {
                        return(string.Empty);
                    }

                    countTripleOne = tuple.FproTriples[indexOne].Value.Count;
                    countTripleTwo = tuple.FproTriples[indexTwo].Value.Count;
                    typenameOne    = Attributes[indexOne].FproDataType.TypeName;
                    typenameTwo    = Attributes[indexTwo].FproDataType.TypeName;

                    if (typenameOne != typenameTwo)
                    {
                        //Attribute value does not match the data type !
                        MessageError = String.Format("Error :{0} and {1} must  the same data type", valueOne, valueTwo);
                        return(string.Empty);
                    }

                    for (int i = 0; i < countTripleOne; i++)
                    {
                        for (int j = 0; j < countTripleTwo; j++)
                        {
                            double pro = 0.0;
                            pro = this.CompareTriple(tuple.FproTriples[indexOne].Value[i].ToString().Trim(), tuple.FproTriples[indexTwo].Value[j].ToString().Trim(), "_=", typenameOne);
                            //pro = EQUALTRIPPLE(tuple.Triples[indexOne].Value[i].ToString().Trim(), tuple.Triples[indexTwo].Value[j].ToString().Trim(), typenameOne);
                            if (((typenameOne == "ContinuousFuzzySet" || typenameOne == "DiscreteFuzzySet") && pro != -1) || ((typenameOne != "ContinuousFuzzySet" || typenameOne != "DiscreteFuzzySet") && pro != 0))
                            {
                                switch (operaterStr)
                                {
                                case "equal_in":
                                    minProb += pro * tuple.FproTriples[indexOne].MinProb[i] * tuple.FproTriples[indexTwo].MinProb[j];
                                    maxProb  = Math.Min(1, maxProb + (tuple.FproTriples[indexOne].MaxProb[i] * tuple.FproTriples[indexTwo].MaxProb[j] * pro));
                                    break;

                                case "equal_ig":
                                    minProb += Math.Max(0, tuple.FproTriples[indexOne].MinProb[i] + tuple.FproTriples[indexTwo].MinProb[j] - 1) * pro;
                                    maxProb  = Math.Min(1, maxProb + (Math.Min(tuple.FproTriples[indexOne].MaxProb[i], tuple.FproTriples[indexTwo].MaxProb[j])) * pro);
                                    break;

                                case "equal_me":
                                    minProb = 0;
                                    maxProb = Math.Min(1, maxProb + 0);
                                    break;

                                default: break;
                                }
                            }
                        }
                    }
                }
                else
                if (SelectConditionBLL.isCompareOperator(operaterStr)) // Biểu thức so sánh giữa một thuộc tính với một giá trị
                {
                    indexOne = this.IndexOf(valueOne);                 // vị trí của thuộc tính trong ds các thuộc tính
                    if (indexOne == -1)
                    {
                        return(string.Empty);
                    }

                    if (valueTwo.Contains("'"))
                    {
                        int count = valueTwo.Split(new char[] { '\'' }).Length - 1;

                        if (valueTwo.Substring(0, 1) != "'")
                        {
                            MessageError = "Unclosed quotation mark before the character string " + valueTwo;
                            return(string.Empty);
                        }

                        if (valueTwo.Substring(valueTwo.Length - 1, 1) != "'")
                        {
                            MessageError = "Unclosed quotation mark after the character string " + valueTwo;
                            return(string.Empty);
                        }

                        if (count != 2)
                        {
                            MessageError = "Unclosed quotation mark at the character string " + valueTwo;
                            return(string.Empty);
                        }

                        valueTwo = valueTwo.Remove(0, 1);
                        valueTwo = valueTwo.Remove(valueTwo.Length - 1, 1);
                    }

                    countTripleOne = tuple.FproTriples[indexOne].Value.Count;     // số lượng các cặp xác xuất trong thuộc tính
                    typenameOne    = Attributes[indexOne].FproDataType.TypeName;

                    FProDataTypeBLL dataType = new FProDataTypeBLL();
                    dataType.TypeName     = Attributes[indexOne].FproDataType.TypeName;
                    dataType.DataType     = Attributes[indexOne].FproDataType.DataType;
                    dataType.DomainValues = Attributes[indexOne].FproDataType.DomainValues;
                    dataType.DomainString = Attributes[indexOne].FproDataType.DomainString;

                    if (!dataType.CheckDataTypeOfVariables(valueTwo))
                    {
                        MessageError = String.Format("Conversion failed when converting the varchar value {0} to data type {1}.", valueTwo, typenameOne);
                        return(string.Empty);
                    }
                    else
                    {
                        if (dataType.TypeName == "ContinuousFuzzySet" || dataType.TypeName == "DiscreteFuzzySet")
                        {
                            for (int i = 0; i < countTripleOne; i++)
                            {
                                //calculate prob(A-->B)
                                double pro = this.CompareTriple(tuple.FproTriples[indexOne].Value[i].ToString().Trim(), valueTwo.Trim(), operaterStr, dataType.TypeName);
                                if (pro != -1.0)     // duyệt từng cặp xác xuất và so sánh
                                {
                                    minProb += pro * tuple.FproTriples[indexOne].MinProb[i];
                                    maxProb += pro * tuple.FproTriples[indexOne].MaxProb[i];
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < countTripleOne; i++)
                            {
                                double pro = this.CompareTriple(tuple.FproTriples[indexOne].Value[i].ToString().Trim(), valueTwo.Trim(), operaterStr, dataType.TypeName);
                                if (pro == 1.0)     // duyệt từng cặp xác xuất và so sánh
                                {
                                    minProb += tuple.FproTriples[indexOne].MinProb[i];
                                    maxProb += tuple.FproTriples[indexOne].MaxProb[i];
                                }
                            }
                        }
                    }
                }
                else                         // Biểu thức kết hợp giữa hai khoảng xác suất
                {
                    double   minProbOne, minProbTwo, maxProbOne, maxProbTwo;
                    string[] StrProb;

                    valueOne = valueOne.Replace("[", "");      // [L,U]
                    valueOne = valueOne.Replace("]", "");

                    StrProb    = valueOne.Split(',');
                    minProbOne = Convert.ToDouble(StrProb[0]);
                    maxProbOne = Convert.ToDouble(StrProb[1]);

                    valueTwo = valueTwo.Replace("[", "");      // [L,U]
                    valueTwo = valueTwo.Replace("]", "");

                    StrProb    = valueTwo.Split(',');
                    minProbTwo = Convert.ToDouble(StrProb[0]);
                    maxProbTwo = Convert.ToDouble(StrProb[1]);

                    switch (operaterStr)
                    {
                    case "⊗_ig": minProb = Math.Max(0, minProbOne + minProbTwo - 1); maxProb = Math.Min(maxProbOne, maxProbTwo); break;

                    case "⊗_in": minProb = minProbOne * minProbTwo; maxProb = maxProbOne * maxProbTwo; break;

                    case "⊗_me": minProb = 0; maxProb = 0; break;

                    case "⊕_ig": minProb = Math.Max(minProbOne, minProbTwo); maxProb = Math.Min(1, maxProbOne + maxProbTwo); break;

                    case "⊕_in": minProb = minProbOne + minProbTwo - (minProbOne * minProbTwo); maxProb = maxProbOne + maxProbTwo - (maxProbOne * maxProbTwo); break;

                    case "⊕_me": minProb = Math.Min(1, minProbOne + minProbTwo); maxProb = Math.Min(1, maxProbOne + maxProbTwo); break;

                    case "⊖_ig": minProb = Math.Max(0, minProbOne - maxProbTwo); maxProb = Math.Min(maxProbOne, 1 - minProbTwo); break;

                    case "⊖_in": minProb = minProbOne * (1 - maxProbTwo); maxProb = maxProbOne * (1 - minProbTwo); break;

                    case "⊖_me": minProb = minProbOne; maxProb = Math.Min(maxProbOne, 1 - minProbTwo); break;

                    default: MessageError = "Incorrect syntax near 'where'.";
                        break;
                    }
                }
            }
            catch
            {
                MessageError = "Incorrect syntax near 'where'.";
                return(string.Empty);
            }

            maxProb = 1 > maxProb ? maxProb : 1; // check maxProb
            return(String.Format("[{0},{1}]", minProb, maxProb));
        }