// Chuyen chuoi ket luan thanh KB public static _KB ConclusionToKB(String str) { // Chua kiem tra tinh hop le cua chuoi str _KB result = new _KB(); str = str.Replace("|", ","); String[] strClause = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); // Phan tich thanh cac chuoi menh de result.mArrClause = new _Clause[strClause.Length]; // Them cac menh de vao KB for (int i = 0; i < strClause.Length; ++i) { _Clause clause = new _Clause(); // Tu cac chuoi menh de, phan tich thanh cac chuoi bien menh de String[] strLiteral = strClause[i].Split(new String[] { "&" }, StringSplitOptions.RemoveEmptyEntries); // Them cac bien menh de vao menh de clause for (int j = 0; j < strLiteral.Length; ++j) { _Literal literal = new _Literal(strLiteral[j]); clause.AddLiteral(!literal); } result.mArrClause[i] = clause; } return(result); }
// Phu dinh bien menh de public _Literal Negative() { _Literal result = new _Literal(mName); result.mNot = !mNot; return(result); }
public _Clause(String str) { // Chua kiem tra tinh hop le cua chuoi str String[] temp = str.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); mArrLiteral = new _Literal[temp.Length]; for (int i = 0; i < temp.Length; ++i) { mArrLiteral[i] = new _Literal(temp[i]); } }
// Kiem tra 2 bien menh de co doi ngau nhau khong // true : doi ngau nhau // false : khong doi ngau nhau public static Boolean Antithesis(_Literal p, _Literal q) { Boolean result = false; if (p.mName == null || q.mName == null) { return(result); } result = ((p.mName == q.mName) && (p.mNot != q.mNot)); return(result); }
// Ham tao sao chep public _Literal(_Literal p) { if (p == null) { mName = null; mNot = false; return; } mName = String.Copy(p.mName); mNot = p.mNot; }
// Ham tao sao chep public _Clause(_Clause p) { if (p == null) { mArrLiteral = null; return; } mArrLiteral = new _Literal[p.mArrLiteral.Length]; for (int i = 0; i < mArrLiteral.Length; ++i) { mArrLiteral[i] = new _Literal(p.mArrLiteral[i]); } }
// Them bien menh de vao menh de public void AddLiteral(_Literal p) { if (p == null) { return; } if (mArrLiteral == null) { mArrLiteral = new _Literal[1]; } else { Array.Resize(ref mArrLiteral, mArrLiteral.Length + 1); } mArrLiteral[mArrLiteral.Length - 1] = new _Literal(p); }