private void InsertAttributeValue(SqlInsertQuery query, List <Object> attributes, int randomVariable) { underlineDatabase.InsertValueIntoAttributeTable(query.TableName + "_0", randomVariable, 1, "TupleExistence", query.TupleP); for (int i = 1; i <= attributes.Count; i++) { string attributeTableName = query.TableName + "_" + i; var value = attributes[i - 1] as DeterministicAttribute; if (value != null) { DeterministicAttribute attribute = value; double prob = 0; prob = 100; underlineDatabase.InsertValueIntoAttributeTable(attributeTableName, randomVariable, 1, attribute.AttributeValue1, prob); } else { var probabilisticAttribute = attributes[i - 1] as ProbabilisticSingleAttribute; if (probabilisticAttribute != null) { var attribute = probabilisticAttribute; List <String> v = attribute.Values; List <double> p = attribute.Probs; for (int j = 0; j < v.Count; j++) { // attribute value starting from 1 upto number of possible values, // because 0 is system reserve for null state. underlineDatabase.InsertValueIntoAttributeTable(attributeTableName, randomVariable, j + 1, v[j], p[j]); } } } } }
private void processValueClause(string valueClause) { // pattern here is value or PROBABLY value 50% and repeat for any length string sPattern = @"[(,]\s*(PROBABLY(?<pValue>[\[\]\w%\.\s/]+)|(?<value>.*?))\s*(?=(,|\)))"; MatchCollection matchs = Regex.Matches(valueClause, sPattern, RegexOptions.IgnoreCase); if (matchs.Count == 0) { throw new Exception("regex matching fail to return any results"); } for (int i = 0; i < matchs.Count; i++) { String value = matchs[i].Groups["value"].Value; String probabilisticValues = matchs[i].Groups["pValue"].Value; if (!String.IsNullOrEmpty(value) && String.IsNullOrEmpty(probabilisticValues)) { DeterministicAttribute pAttribute = new DeterministicAttribute(value); _attributes.Add(pAttribute); } else { if (!String.IsNullOrEmpty(value) || String.IsNullOrEmpty(probabilisticValues)) { throw new Exception("PROBABLY clause contain no values at all !"); } ProbabilisticAttribute probabilisticAttribute = processProbabilisticValueClause(probabilisticValues); _attributes.Add(probabilisticAttribute); } } }