Ejemplo n.º 1
0
 public ProbAttribute(ProbAttribute attr)
 {
     this.IDAttribute   = attr.IDAttribute;
     this.Type          = new ProbDataType(attr.Type);
     this.Description   = attr.Description;
     this.PrimaryKey    = attr.PrimaryKey;
     this.AttributeName = attr.AttributeName;
     this.probScheme    = attr.probScheme;
 }
Ejemplo n.º 2
0
        public ProbScheme(int IDScheme, string schemename, List <ProbAttribute> Attributes)
        {
            this.IDScheme   = IDScheme;
            this.SchemeName = schemename;
            this.Attributes = new List <ProbAttribute>();

            foreach (ProbAttribute item in Attributes)
            {
                ProbAttribute attr = new ProbAttribute();
                attr.AttributeName = item.AttributeName;
                attr.Description   = item.Description;
                attr.DomainString  = item.DomainString;
                attr.IDAttribute   = item.IDAttribute;
                attr.PrimaryKey    = item.PrimaryKey;
                attr.Type          = new ProbDataType(item.Type);
                this.Attributes.Add(attr);
            }
        }
Ejemplo n.º 3
0
        private List <ProbAttribute> GetAttribute(string valueString)
        {
            List <ProbAttribute> listProbAttribute = new List <ProbAttribute>();
            //////////////////////// Get Attributes //////////////////////
            int posOne, posTwo;


            // * là chọn tất cả các thuộc tính
            if (valueString.Contains("*"))
            {
                posOne = valueString.IndexOf("*");                                                  // start postion of attributes
                posTwo = valueString.IndexOf("from ") - 1;

                if (posOne > posTwo)
                {
                    MessageError = "Incorrect syntax near 'from'.";
                    return(null);
                }


                if (posOne < valueString.IndexOf("select"))
                {
                    MessageError = "Incorrect syntax near 'select'.";
                    return(null);
                }

                if (valueString.Contains("where") && posOne > valueString.IndexOf("where"))
                {
                    MessageError = "Incorrect syntax near 'where'.";
                    return(null);
                }

                if (posOne != valueString.LastIndexOf("*"))
                {
                    MessageError = "Incorrect syntax near 'select'.";
                    return(null);
                }

                // end postion of attributes
                string attributes = valueString.Substring(posOne, posTwo - posOne + 1);

                // Nếu như phia sau dấu * có bất kì kí tự nào thì sẽ thông báo lỗi
                if (attributes.Trim().Length > 1)
                {
                    MessageError = "Incorrect syntax near 'select'.";
                    return(null);
                }

                // thực hiện sao chép toàn bộ thuộc tính của các quan hệ vào danh sách thuộc tính chọn
                for (int i = 0; i < this.selectedRelations.Count; i++)
                {
                    foreach (ProbAttribute attr in this.selectedRelations[i].Scheme.Attributes)
                    {
                        attr.AttributeName = String.Format("{0}.{1}", this.selectedRelations[i].RelationName, attr.AttributeName);
                        listProbAttribute.Add(attr);
                    }
                }

                return(listProbAttribute);
            }
            else // ngược lại là xuất theo thuộc tính chỉ định
            {
                posOne = valueString.IndexOf("select") + 6;                                                  // start postion of attributes
                posTwo = valueString.IndexOf("from ") - 1;                                                   // end postion of attributes


                string attributes = valueString.Substring(posOne, posTwo - posOne + 1);

                //kiểm tra cú pháp của chuổi thuộc tính
                if (!QueryExecution.CheckStringAttribute(attributes))
                {
                    MessageError = "Incorrect syntax near 'select'.";
                    return(null);
                }
                else
                {
                    string[] seperator = { "," };
                    string[] attribute = attributes.Split(seperator, StringSplitOptions.RemoveEmptyEntries); // split thành mảng các thuộc tính

                    foreach (string str in attribute)
                    {
                        if (!str.Contains("."))
                        {
                            string attributeName      = str.Trim();
                            int    countOne           = 0;
                            int    countSameAttribute = 0;
                            foreach (ProbRelation relation in this.selectedRelations)
                            {
                                List <string> listOfAttributeName = relation.Scheme.ListOfAttributeNameToLower();
                                if (listOfAttributeName.Contains(attributeName.ToLower()))
                                {
                                    ProbAttribute attr = new ProbAttribute(relation.Scheme.Attributes[listOfAttributeName.IndexOf(attributeName)]);
                                    attr.AttributeName = String.Format("{0}.{1}", relation.RelationName, attr.AttributeName);
                                    listProbAttribute.Add(attr);
                                    countSameAttribute++;
                                }
                                else
                                {
                                    countOne++;
                                }
                            }

                            if (countOne == this.selectedRelations.Count)
                            {
                                MessageError = String.Format(" Invalid attribute name '{0}'.", attributeName);
                                return(null);
                            }

                            if (countSameAttribute == this.selectedRelations.Count && this.selectedRelations.Count >= 2)
                            {
                                MessageError = String.Format(" Ambiguous attribute name '{0}'.", attributeName);
                                return(null);
                            }
                        }
                        else
                        {
                            string[] array = str.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                            if (array.Length != 2)
                            {
                                MessageError = "Incorrect syntax near the keyword 'select'.";
                                return(null);
                            }

                            ProbRelation relation = this.selectedRelations.SingleOrDefault(c => c.RelationName.Trim() == array[0].Trim());

                            if (relation == null)
                            {
                                MessageError = String.Format("The multi-part identifier '{0}' could not be bound.", str);
                                return(null);
                            }

                            ProbAttribute attr = new ProbAttribute(relation.Scheme.Attributes.SingleOrDefault(c => c.AttributeName.Trim().ToLower() == array[1].Trim()));
                            attr.AttributeName = String.Format("{0}.{1}", relation.RelationName, attr.AttributeName);

                            if (attr == null)
                            {
                                MessageError = "Invalid attribute name '" + array[1] + "'.";
                                return(null);
                            }


                            listProbAttribute.Add(attr);
                        }
                    }

                    return(listProbAttribute);
                }
            }
        }
Ejemplo n.º 4
0
        private static ProbTriple JoinTwoTriple(ProbTriple tripleOne, ProbTriple tripleTwo, ProbAttribute attribute, string OperationNaturalJoin)
        {
            ProbTriple triple = new ProbTriple();

            for (int i = 0; i < tripleOne.Value.Count; i++)
            {
                for (int j = 0; j < tripleTwo.Value.Count; j++)
                {
                    if (SelectCondition.EQUAL(tripleOne.Value[i].ToString().Trim(), tripleTwo.Value[j].ToString().Trim(), attribute.Type.DataType))
                    {
                        switch (OperationNaturalJoin)
                        {
                        case "in":
                            triple.Value.Add(tripleOne.Value[i]);
                            triple.MinProb.Add(tripleOne.MinProb[i] * tripleTwo.MinProb[j]);
                            triple.MaxProb.Add(tripleOne.MaxProb[i] * tripleTwo.MaxProb[j]);

                            break;

                        case "ig":

                            triple.Value.Add(tripleOne.Value[i]);
                            triple.MinProb.Add(Math.Max(0, tripleOne.MinProb[i] + tripleTwo.MinProb[j] - 1));
                            triple.MaxProb.Add(Math.Min(tripleOne.MaxProb[i], tripleTwo.MaxProb[j]));
                            break;

                        case "me":

                            triple.Value.Add(tripleOne.Value[i]);
                            triple.MinProb.Add(0);
                            triple.MaxProb.Add(0);
                            break;

                        default: break;
                        }
                    }
                }
            }


            return(triple.Value.Count <= 0 ? null : triple);
        }