Example #1
0
        public ProbDataType(ProbDataType type)
        {
            this.TypeName     = type.TypeName;
            this.DataType     = type.DataType;
            this.DomainString = type.DomainString;
            Domain            = new List <string>();

            foreach (string item in type.Domain)
            {
                Domain.Add(item);
            }
        }
Example #2
0
 public ProbAttribute()
 {
     this.IDAttribute = -1;
     Type             = new ProbDataType();
 }
Example #3
0
        private bool GetProbIntervalV2(string valueOne, string valueTwo, string operaterStr, double?maxProbOfCon = null, double?minProbOfCon = null)
        {
            double    minProb = 0, maxProb = 0;
            int       indexOne, countTripleOne;
            ProbTuple tuple = this.tuple;

            try
            {
                if (SelectCondition.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.IndexOfAttribute(valueOne);     // vị trí của thuộc tính trong ds các thuộc tính
                    if (indexOne == -1)
                    {
                        return(false);
                    }

                    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(false);
                        }

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


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

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

                    #region ProbDataType
                    ProbDataType dataType = new ProbDataType();
                    dataType.TypeName     = Attributes[indexOne].Type.TypeName;
                    dataType.DataType     = Attributes[indexOne].Type.DataType;
                    dataType.Domain       = Attributes[indexOne].Type.Domain;
                    dataType.DomainString = Attributes[indexOne].Type.DomainString;
                    #endregion

                    if (!dataType.CheckDataTypeOfVariables(valueTwo))
                    {
                        MessageError = String.Format("Conversion failed when converting the varchar value {0} to data type {1}.", valueTwo, dataType.DataType);
                        return(false);
                    }

                    #region ProbDataType
                    countTripleOne = tuple.Triples[indexOne].Value.Count; // số lượng các cặp xác xuất trong thuộc tính
                    var listValue = tuple.Triples[indexOne].Value;
                    var minProbV  = tuple.Triples[indexOne].MinProb;
                    var maxProbV  = tuple.Triples[indexOne].MaxProb;
                    #endregion

                    if (maxProbV == 1 && minProbV == 1 && !maxProbOfCon.HasValue && !minProbOfCon.HasValue)
                    {
                        var kp = listValue.Any(x => CompareTriple(x, valueTwo, operaterStr, dataType.TypeName));
                        return(kp);
                    }
                    else
                    {
                        var count = listValue.Where(x => CompareTriple(x, valueTwo, operaterStr, dataType.TypeName)).Count();
                        if (count > 0)
                        {
                            minProb = (count / (float)countTripleOne) * minProbV;
                            maxProb = (count / (float)countTripleOne) * maxProbV;

                            if (maxProbOfCon.HasValue && minProbOfCon.HasValue)
                            {
                                return(minProbOfCon.Value <= minProb && maxProb <= maxProbOfCon);
                            }
                        }
                        return(false);
                    }
                }
                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;

                    default:
                        MessageError = "Incorrect syntax near 'where'.";
                        break;
                    }
                }
            }
            catch
            {
                MessageError = "Incorrect syntax near 'where'.";
                return(false);
            }
            return(false);
        }
Example #4
0
        private List <double> GetProbIntervalV3(string valueOne, string valueTwo, string operaterStr)
        {
            double    minProb = 0, maxProb = 0;
            int       indexOne, countTripleOne;
            ProbTuple tuple = this.tuple;

            try
            {
                if (SelectCondition.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.IndexOfAttribute(valueOne);     // vị trí của thuộc tính trong ds các thuộc tính
                    if (indexOne == -1)
                    {
                        return(null);
                    }

                    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(null);
                        }

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


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

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

                    #region ProbDataType
                    ProbDataType dataType = new ProbDataType();
                    dataType.TypeName     = Attributes[indexOne].Type.TypeName;
                    dataType.DataType     = Attributes[indexOne].Type.DataType;
                    dataType.Domain       = Attributes[indexOne].Type.Domain;
                    dataType.DomainString = Attributes[indexOne].Type.DomainString;
                    #endregion

                    if (!dataType.CheckDataTypeOfVariables(valueTwo))
                    {
                        MessageError = String.Format("Conversion failed when converting the varchar value {0} to data type {1}.", valueTwo, dataType.DataType);
                        return(null);
                    }

                    #region ProbDataType
                    countTripleOne = tuple.Triples[indexOne].Value.Count; // số lượng các cặp xác xuất trong thuộc tính
                    var listValue = tuple.Triples[indexOne].Value;
                    var minProbV  = tuple.Triples[indexOne].MinProb;
                    var maxProbV  = tuple.Triples[indexOne].MaxProb;
                    #endregion

                    var result = listValue.Where(x => CompareTriple(x, valueTwo, operaterStr, dataType.TypeName)).Count();

                    if (result > 0)
                    {
                        minProb = (result / (float)countTripleOne) * minProbV;
                        maxProb = (result / (float)countTripleOne) * maxProbV;

                        return(new List <double> {
                            minProb, maxProb
                        });
                    }
                    else
                    {
                        return(new List <double> {
                            0, 0
                        });
                    }
                }

                return(null);
            }
            catch
            {
                MessageError = "Incorrect syntax near 'where'.";
                return(null);
            }
        }
Example #5
0
        private string GetProbInterval(string valueOne, string valueTwo, string operaterStr)
        {
            double    minProb = 0, maxProb = 0;
            int       indexOne, indexTwo, countTripleOne, countTripleTwo;
            ProbTuple 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.Triples[indexOne].Value.Count;
                    countTripleTwo = tuple.Triples[indexTwo].Value.Count;
                    typenameOne    = Attributes[indexOne].Type.DataType;
                    typenameTwo    = Attributes[indexTwo].Type.DataType;

                    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++)
                        {
                            if (EQUAL(tuple.Triples[indexOne].Value[i].ToString().Trim(), tuple.Triples[indexTwo].Value[j].ToString().Trim(), typenameOne))
                            {
                                switch (operaterStr)
                                {
                                case "equal_in":
                                    minProb += tuple.Triples[indexOne].MinProb[i] * tuple.Triples[indexTwo].MinProb[j];
                                    maxProb  = Math.Min(1, maxProb + tuple.Triples[indexOne].MaxProb[i] * tuple.Triples[indexTwo].MaxProb[j]);
                                    break;

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

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

                                default: break;
                                }
                            }
                        }
                    }
                }
                else
                if (SelectCondition.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.Triples[indexOne].Value.Count;     // số lượng các cặp xác xuất trong thuộc tính
                    typenameOne    = Attributes[indexOne].Type.DataType;

                    ProbDataType dataType = new ProbDataType();
                    dataType.TypeName     = Attributes[indexOne].Type.TypeName;
                    dataType.DataType     = Attributes[indexOne].Type.DataType;
                    dataType.Domain       = Attributes[indexOne].Type.Domain;
                    dataType.DomainString = Attributes[indexOne].Type.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);
                    }


                    for (int i = 0; i < countTripleOne; i++)
                    {
                        if (this.CompareTriple(tuple.Triples[indexOne].Value[i].ToString().Trim(), valueTwo.Trim(), operaterStr, typenameOne))     // duyệt từng cặp xác xuất và so sánh
                        {
                            minProb += tuple.Triples[indexOne].MinProb[i];
                            maxProb += tuple.Triples[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;

                    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));
        }