예제 #1
0
        public void Add(Fact fact, Atom matchingAtom)
        {
            if (!factTable.ContainsKey(fact.GetLongHashCode())) factTable.Add(fact.GetLongHashCode(), fact);

            Fact resolved = Fact.Resolve(false, fact, matchingAtom);

            for (int i=0; i<resolved.Members.Length; i++) {
                object predicateValue = resolved.GetPredicateValue(i);
                AddFactForPredicateValue(fact, i, predicateValue);

                // if we are not strictly enforcing typing and if the predicate value is not a string, then also store it as a string
                if ((!StrictTyping) && (!(predicateValue is string))) AddFactForPredicateValue(fact, i, predicateValue.ToString());
            }
        }
예제 #2
0
        public void Remove(Fact fact)
        {
            factTable.Remove(fact.GetLongHashCode());

            // if facttable is empty, then we re-initialize the predicate storage
            if (factTable.Count == 0) InitializePredicateStorage();
        }
예제 #3
0
        private void AddFactForPredicateValue(Fact fact, int position, object predicateValue)
        {
            ArrayList matchingHashCodes = (ArrayList)predicateTables[position].Get(predicateValue);

            if (matchingHashCodes == null) {
                matchingHashCodes = new ArrayList();
                predicateTables[position].Add(predicateValue, matchingHashCodes);
            }

            // we do not check for duplicates before adding as post processing filters duplicates anyway
            matchingHashCodes.Add(fact.GetLongHashCode());
        }
예제 #4
0
파일: FactBase.cs 프로젝트: Ghasan/NxBRE
        /// <summary>
        /// Retracts (removes) a Fact from the FactBase.
        /// </summary>
        /// <param name="fact">The Fact to remove.</param>
        /// <returns>True if the Fact has been retracted from the FactBase, otherwise False.</returns>
        public bool Retract(Fact fact)
        {
            if (Exists(fact)) {
                factList.Remove(fact.GetLongHashCode());
                GetMatchingFactStorageTable(fact).Remove(fact);

                // the fact existing and removed from the factbase, return true
                if (!ModifiedFlag) ModifiedFlag = true;
                return true;
            }
            return false;
        }
예제 #5
0
파일: FactBase.cs 프로젝트: Ghasan/NxBRE
 /// <summary>
 /// Checks if the FactBase contains a certain Fact.
 /// </summary>
 /// <param name="fact">The Fact to check.</param>
 /// <returns>True if the Fact is already present in the FactBase, otherwise False.</returns>
 public bool Exists(Fact fact)
 {
     return factList.ContainsKey(fact.GetLongHashCode());
 }
예제 #6
0
파일: FactBase.cs 프로젝트: Ghasan/NxBRE
        ///<remarks>As Facts labels are basically ignored (no retrieval nor any operation based
        /// on it, the FactBase does not bother check if we have different facts with same labels.</remarks>
        public bool Assert(Fact fact)
        {
            if (!fact.IsFact)
                throw new BREException("Can not add non-facts to the fact base: "+fact.ToString());

            if (!Exists(fact)) {
                factList.Add(fact.GetLongHashCode(), fact);

                // check if the new fact matches any of the registered atoms
                // and if yes, then reference this fact in the list of matching ones
                foreach(Atom atom in atomList.Values)
                    if (atom.Matches(fact))
                        GetMatchingFactStorageTable(atom).Add(fact, atom);

                // the fact was new and added to the factbase, return true
                if (!ModifiedFlag) ModifiedFlag = true;
                return true;
            }
            else
                // else return false
                return false;
        }
예제 #7
0
		private void RemoveFactFromDataTable(Fact fact) {
			DataTable table = GetDataTable(fact);
			foreach(DataRow row in table.Select("hashcode='" + fact.GetLongHashCode().ToString() + "'"))
				table.Rows.Remove(row);
		}
예제 #8
0
		private DataRow BuildDataRow(DataTable table, Fact fact, Atom atom) {
			DataRow row = table.NewRow();
			row["hashcode"] = fact.GetLongHashCode().ToString();
     	row["fact"] = fact;
     	if (atom != null) {
	     	int i=0;
	     	foreach(object predicateValue in Fact.Resolve(fact, atom).PredicateValues) {
	     		row["predicate" + i] = (predicateValue is String)?predicateValue:predicateValue.GetHashCode().ToString();
	     		i++;
	     	}
     	}
    	return row;
		}