public IList <PTuple> getAllTupleByRelationName(string relationName, IList <PAttribute> pAttributes) { relationName = relationName.Trim().ToLower(); var result = new List <PTuple>(); var dtb = ConcreteDb.Instance.getDataTable("Select * From " + relationName); if (dtb is null) { return(null); } foreach (DataRow row in dtb.Rows) { var newRecord = new PTuple(); //id Attr is null var i = 0; foreach (var item in pAttributes) { if (item.AttributeName.Equals(ContantCls.emlementProb)) { newRecord.Ps = new ElemProb(row[i++].ToString()); } else { newRecord.valueSet.Add(String.Format("{0}.{1}", relationName, item.AttributeName), getData(row[i++].ToString(), item.Type, item.primaryKey)); } } result.Add(newRecord); } return(result.Count > 0 ? result : null); }
public PTuple GetTuplebyId(ref PRelation rel, string tupId) { var relid = rel.id; PTuple reVal = null; { var relation = RelationService.Instance().getAllRelation().Where(r => r.id.Equals(relid)).First(); tupId = tupId.Replace("{", ""); tupId = tupId.Replace("}", ""); if (!(relation is null)) { var pri = relation.schema.Attributes.Where(a => a.primaryKey).First(); var atr = String.Format("{0}.{1}", relation.relationName, pri.AttributeName); if (!(pri is null)) { try { reVal = relation.tupes.Where(t => SelectCondition.EQUAL(t.valueSet[atr].First(), tupId.Trim(), pri.Type.TypeName)).First(); } catch //ko tim thay (insert khi id is Empty) { if (String.IsNullOrEmpty(tupId)) { reVal = new PTuple(relation); } } } rel = relation; } } return(reVal); }
public PTuple Update(PTuple pTuple, PRelation pRelation, String key) { try { if (key.Substring(key.IndexOf(".") + 1).Equals(ContantCls.emlementProb, StringComparison.CurrentCultureIgnoreCase)) { var priName = pRelation.schema.Attributes.Where(a => a.primaryKey).Select(p => p.AttributeName).Single().Trim().ToLower(); var standard = key.IndexOf(".") == -1 ? key : key.Substring(key.IndexOf(".") + 1).Trim(); var sql = ""; sql += String.Format("UPDATE {0} SET ", pRelation.relationName.ToLower().Trim()); sql += String.Format("{0} = ", standard); //note sql += "' " + pTuple.Ps.ToString() + " '"; priName = String.Format("{0}.{1}", pRelation.relationName, priName); var priVal = pTuple.valueSet[priName].First().Trim(); sql += String.Format(" WHERE {0} = ", priName); //note sql += "'{ " + priVal + " }'"; //in db ConcreteDb.Instance.Update(sql); //in ram var relation = SystemParam.StaticParams.currentDb.Relations.Where(p => p.id == pRelation.id).First(); var tuple = relation.tupes.Where(t => t.valueSet[priName].First().Equals(pTuple.valueSet[priName].First(), StringComparison.CurrentCultureIgnoreCase)).First(); tuple = pTuple; } else { var priName = pRelation.schema.Attributes.Where(a => a.primaryKey).Select(p => p.AttributeName).Single().Trim().ToLower(); var standard = key.IndexOf(".") == -1 ? key : key.Substring(key.IndexOf(".") + 1).Trim(); var sql = ""; sql += String.Format("UPDATE {0} SET ", pRelation.relationName.ToLower().Trim()); var vals = String.Join(" , ", pTuple.valueSet[key].ToArray()); sql += String.Format("{0} = ", standard); //note sql += "'{ " + vals + " }'"; priName = String.Format("{0}.{1}", pRelation.relationName, priName); var priVal = pTuple.valueSet[priName].First().Trim(); sql += String.Format(" WHERE {0} = ", priName); //note sql += "'{ " + priVal + " }'"; //in db ConcreteDb.Instance.Update(sql); //in ram var relation = SystemParam.StaticParams.currentDb.Relations.Where(p => p.id == pRelation.id).First(); var tuple = relation.tupes.Where(t => t.valueSet[priName].First().Equals(pTuple.valueSet[priName].First(), StringComparison.CurrentCultureIgnoreCase)).First(); tuple = pTuple; } } catch (Exception ex) { return(null); } return(pTuple); }
public void AsyncVoidMethodCanBeSerialized() { var storage = new InMemoryStorageEngine(); var os = ObjectStore.New(storage); var a1 = new CAwaitable(); var a2 = new CAwaitable(); var tuple = new PTuple <CAwaitable, CAwaitable>(a1, a2); var value = new PValue <int>(); AsyncMethodTest(a1, a2, value); os.Entangle(tuple); os.Entangle(value); os.Persist(); os = ObjectStore.Load(storage, true); tuple = os.Resolve <PTuple <CAwaitable, CAwaitable> >(); value = os.Resolve <PValue <int> >(); value.Value.ShouldBe(-1); tuple.First.SignalCompletion(); value.Value.ShouldBe(1); os.Persist(); os = ObjectStore.Load(storage, true); tuple = os.Resolve <PTuple <CAwaitable, CAwaitable> >(); value = os.Resolve <PValue <int> >(); value.Value.ShouldBe(1); tuple.Second.SignalCompletion(); value.Value.ShouldBe(2); os.Persist(); os = ObjectStore.Load(storage, true); tuple = os.Resolve <PTuple <CAwaitable, CAwaitable> >(); value = os.Resolve <PValue <int> >(); value.Value.ShouldBe(2); }
public bool Satisfied(PTuple tuple) { this.tuple = tuple; string conditionStr = this.conditionString; #region int i = 0; int j = 0; while (i < conditionStr.Length - 1) { if (conditionStr[i] == '(') { j = i + 1; while (j < conditionStr.Length) { if (conditionStr[j] == ']') { if (IsSelectionExpression(conditionStr.Substring(i, j - i + 1))) { string expValue = ExpressionValue(conditionStr.Substring(i, j - i + 1)) ? "1" : "0"; conditionStr = conditionStr.Insert(i, expValue); //tao sao ko get ra roi xai replace conditionStr = conditionStr.Remove(i + 1, j - i + 1); break; } if (MessageError != string.Empty) { return(false); } } j++; } } i++; } #endregion conditionStr = conditionStr.Replace(" ", "").ToLower(); conditionStr = conditionStr.Replace("and", "&"); conditionStr = conditionStr.Replace("or", "|"); conditionStr = conditionStr.Replace("not", "!"); List <string> rpn = SC_PostfixNotation(conditionStr); // reverse to postfix notation return(CalculateCondition(rpn)); }
public bool DeleteTupleById(PRelation pRelation, PTuple pTuple) { try { var strPriAtt = pRelation.schema.Attributes.Where(att => att.primaryKey).First().ToString().Trim(); var pri = String.Format("{0}.{1}", pRelation.relationName, strPriAtt); var tupID = pTuple.valueSet[pri].FirstOrDefault().Trim(); //del in db var sql = ""; sql += String.Format("DELETE FROM {0} ", pRelation.relationName.ToUpper()); sql += String.Format("WHERE {0} = '{1}'", strPriAtt, "{ " + tupID + " }"); //del in ram SystemParam.StaticParams.currentDb.Relations.Where(p => p.id == pRelation.id).First().tupes.Remove(pTuple); if (ConcreteDb.Instance.Update(sql) < 0) { throw new Exception(ConcreteDb.Instance.errorMessage); } } catch (Exception ex) { return(false); } return(true); }
public PTuple Insert(PTuple pTuple, PRelation pRelation) { var sql = ""; sql += String.Format("INSERT INTO {0} ", pRelation.relationName.ToLower().Trim()); var atrrs = String.Join(",", pRelation.schema.Attributes.Select(a => a.AttributeName.Trim().ToLower()).ToArray()); sql += String.Format("({0}) VALUES", atrrs); //value list var vallist = new List <String>(); foreach (var key in pTuple.valueSet.Keys) { if (!key.Substring(key.IndexOf(".") + 1).Equals(ContantCls.emlementProb, StringComparison.CurrentCultureIgnoreCase)) { var vals = String.Join(",", pTuple.valueSet[key].ToArray()); vallist.Add("'" + vals + "'"); } } vallist.Add("'" + pTuple.Ps.ToString() + "'"); String strVal = String.Join(",", vallist.ToArray()); sql += $"({strVal})"; try { //in db ConcreteDb.Instance.Update(sql); //in ram SystemParam.StaticParams.currentDb.Relations.Where(p => p.id == pRelation.id).First().tupes.Add(pTuple); } catch (Exception ex) { return(null); } return(pTuple); }
public PTuple Update(PTuple pTuple, PRelation pRelation, String key) { return(PTupleService.Instance().Update(pTuple, pRelation, key)); }
public PTuple Insert(PTuple pTuple, PRelation pRelation) { return(PTupleService.Instance().Insert(pTuple, pRelation)); }
public bool DeleteTupleById(PRelation pRelation, PTuple pTuple) { return(PTupleService.Instance().DeleteTupleById(pRelation, pTuple)); }
private string GetProbInterval(string valueOne, string valueTwo, string operaterStr) { ElemProb prop = null; int indexOne, indexTwo, countValue; PTuple tuple = this.tuple; //string typenameOne; //string typenameTwo; try { // Biểu thức so sánh bằng giữa hai thuộc tính trên cùng một bộ if (operaterStr.Contains("equal_ig") || operaterStr.Contains("equal_in") || operaterStr.Contains("equal_me")) { indexOne = IndexOf(valueOne); indexTwo = IndexOf(valueTwo); if (indexOne == -1 || indexTwo == -1) { return(string.Empty); } if (!Attributes[indexOne].Type.DataType.Equals(Attributes[indexTwo].Type.DataType)) { //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); } var low = 0f; var up = 0f; foreach (var valInAttr1 in tuple.valueSet[(valueOne)]) { foreach (var valInAttr2 in tuple.valueSet[(valueTwo)]) { if (EQUAL(valInAttr1.Trim(), valInAttr2.Trim(), Attributes[indexOne].Type.DataType)) { switch (operaterStr) { case "equal_in": low += tuple.Ps.lowerBound * tuple.Ps.upperBound; up = Math.Min(1, up + tuple.Ps.upperBound * tuple.Ps.upperBound); break; case "equal_ig": low += Math.Min(0, tuple.Ps.lowerBound + tuple.Ps.lowerBound - 1); up = Math.Min(1, up + Math.Min(tuple.Ps.upperBound, tuple.Ps.upperBound)); break; case "equal_me": low = 0; up = Math.Min(1, up + 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 //what is THIS !? 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); } PDataType dataType = new PDataType(); 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, Attributes[indexOne].Type.DataType.ToString()); return(string.Empty); } countValue = tuple.valueSet[(valueOne)].Count; prop = new ElemProb(0, 0); foreach (var value in tuple.valueSet[(valueOne)]) { if (this.Compare(value.ToString().Trim(), valueTwo.ToString(), operaterStr, Attributes[indexOne].Type.DataType.ToString())) //duyet tung value { try { prop.lowerBound += (1 / (float)countValue); prop.upperBound += (1 / (float)countValue); } catch (Exception ex) { MessageError = ex.Message; } //break; } } prop.lowerBound *= tuple.Ps.lowerBound; prop.upperBound *= tuple.Ps.upperBound; } else // Biểu thức kết hợp giữa hai khoảng xác suất { var prop1 = new ElemProb(valueOne); var prop2 = new ElemProb(valueTwo); switch (operaterStr) { case "⊗_ig": prop = new ElemProb(Math.Max(0, prop1.lowerBound + prop2.lowerBound - 1), Math.Min(prop1.upperBound, prop2.upperBound)); break; case "⊗_in": prop = new ElemProb(prop1.lowerBound * prop2.lowerBound, prop1.upperBound * prop2.upperBound); break; case "⊗_me": prop = new ElemProb(0, 0); break; case "⊕_ig": prop = new ElemProb(Math.Max(prop1.lowerBound, prop2.lowerBound), Math.Min(1, prop1.upperBound + prop2.upperBound)); break; case "⊕_in": prop = new ElemProb(prop1.lowerBound + prop2.lowerBound - (prop1.lowerBound * prop2.lowerBound), prop1.upperBound + prop2.upperBound - (prop1.upperBound * prop2.upperBound)); break; case "⊕_me": prop = new ElemProb(Math.Min(1, prop1.lowerBound + prop2.lowerBound), Math.Min(1, prop1.upperBound + prop2.upperBound)); break; default: MessageError = "Incorrect syntax near 'where'."; break; } } } catch (Exception ex) { MessageError = "Incorrect syntax near 'where'."; return(string.Empty); } //maxProb = 1 > maxProb ? maxProb : 1; // check maxProb if (prop is null) { return(String.Empty); } return(String.Format("[{0},{1}]", prop.lowerBound, prop.upperBound)); }