private ProbRelation NaturalJoin(ProbRelation relationResult, ProbRelation relationInput, string operationRa) { ProbRelation relation = Descartes(relationResult, relationInput); List <int> indexsRemove = new List <int>(); var totalAttributesOne = relation.Scheme.Attributes.Count - relationInput.Scheme.Attributes.Count; for (int i = 0; i < totalAttributesOne; i++) { for (int j = totalAttributesOne; j < relation.Scheme.Attributes.Count; j++) { if (i != j && relation.Scheme.Attributes[i].Type.DataType == relation.Scheme.Attributes[j].Type.DataType) { string attributeOne = relation.Scheme.Attributes[i].AttributeName.Substring(relation.Scheme.Attributes[i].AttributeName.IndexOf(".") + 1); string attributeTwo = relation.Scheme.Attributes[j].AttributeName.Substring(relation.Scheme.Attributes[j].AttributeName.IndexOf(".") + 1); if (attributeOne.Equals(attributeTwo, StringComparison.CurrentCultureIgnoreCase)) { indexsRemove.Add(j); for (int k = relation.tuples.Count - 1; k >= 0; k--) { ProbTriple triple = JoinTwoTriple(relation.tuples[k].Triples[i], relation.tuples[k].Triples[j], relation.Scheme.Attributes[i], operationRa); if (triple != null) { relation.tuples[k].Triples[i] = triple; relation.tuples[k].Triples[j] = triple; } else { relation.tuples.RemoveAt(k); } } } } } } var check = relation.Scheme.Attributes.Count() == this.selectedAttributes.Count(); if (check) { for (int i = 0; i < indexsRemove.Count; i++) { foreach (ProbTuple tuple in relation.tuples) { tuple.Triples.RemoveAt(indexsRemove[i]); } relation.Scheme.Attributes.RemoveAt(indexsRemove[i]); this.selectedAttributes.RemoveAt(indexsRemove[i]); } } //OperationNaturalJoin = string.Empty; flagNaturalJoin = false; return(relation); }
public ProbTuple(ProbTuple tuple) { // TODO: Complete member initialization this.Triples = new List <ProbTriple>(); foreach (ProbTriple item in tuple.Triples) { ProbTriple triple = new ProbTriple(item); this.Triples.Add(triple); } }
private ProbRelation NaturalJoin() { ProbRelation relation = Descartes(); List <int> indexsRemove = new List <int>(); for (int i = 0; i < relation.Scheme.Attributes.Count - this.selectedRelations[1].Scheme.Attributes.Count; i++) { for (int j = this.selectedRelations[1].Scheme.Attributes.Count; j < relation.Scheme.Attributes.Count; j++) { if (i != j && relation.Scheme.Attributes[i].Type.DataType == relation.Scheme.Attributes[j].Type.DataType) //cung kieu du lien { string attributeOne = relation.Scheme.Attributes[i].AttributeName.Substring(relation.Scheme.Attributes[i].AttributeName.IndexOf(".") + 1); string attributeTwo = relation.Scheme.Attributes[j].AttributeName.Substring(relation.Scheme.Attributes[j].AttributeName.IndexOf(".") + 1); if (attributeOne.Equals(attributeTwo, StringComparison.CurrentCultureIgnoreCase)) //cung ten attr (!= bang) { indexsRemove.Add(j); //j danh dau truong chung de bo ra for (int k = relation.tuples.Count - 1; k >= 0; k--) { ProbTriple triple = JoinTwoTriple(relation.tuples[k].Triples[i], relation.tuples[k].Triples[j], relation.Scheme.Attributes[i], this.OperationNaturalJoin); if (triple != null) { relation.tuples[k].Triples[i] = triple; relation.tuples[k].Triples[j] = triple; } else { //value is not equal relation.tuples.RemoveAt(k); } } } } } } for (int i = 0; i < indexsRemove.Count; i++) { foreach (ProbTuple tuple in relation.tuples) { tuple.Triples.RemoveAt(indexsRemove[i]); } relation.Scheme.Attributes.RemoveAt(indexsRemove[i]); this.selectedAttributes.RemoveAt(indexsRemove[i]); } OperationNaturalJoin = string.Empty; flagNaturalJoin = false; return(relation); }
public ProbTriple(ProbTriple triple) { // TODO: Complete member initialization this.Value = new List <string>(); this.MinProb = triple.MinProb; this.MaxProb = triple.MaxProb; foreach (var item in triple.Value) { this.Value.Add(item); } }
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); }
public ProbTriple(ProbTriple triple) { // TODO: Complete member initialization this.Value = new List <object>(); this.MinProb = new List <double>(); this.MaxProb = new List <double>(); foreach (var item in triple.Value) { this.Value.Add(item); } foreach (double item in triple.MinProb) { this.MinProb.Add(item); } foreach (double item in triple.MaxProb) { this.MaxProb.Add(item); } }