本文整理汇总了C#中Creshendo.Util.Rete.Rete类的典型用法代码示例。如果您正苦于以下问题:C# Rete类的具体用法?C# Rete怎么用?C# Rete使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rete类属于Creshendo.Util.Rete命名空间,在下文中一共展示了Rete类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BasicObjectBindingTest1
public void BasicObjectBindingTest1()
{
long ts = DateTime.Now.Ticks;
int fired = 0;
int activations = 0;
Basic basic = new Basic("one", 1);
using (TextWriter writer = Console.Out)
{
Rete engine = new Rete();
engine.Watch = WatchType.WATCH_ALL;
engine.addPrintWriter("Console", writer);
engine.declareObject(typeof (Basic), "Basic");
engine.loadRuleset(getRule3());
foreach (Defrule rule in engine.CurrentFocus.AllRules)
{
Console.WriteLine(rule.toPPString());
}
engine.assertObject(basic, "Basic", false, false);
activations = engine.CurrentFocus.ActivationCount;
fired = engine.fire();
engine.printWorkingMemory(true, false);
double endTime = DateTime.Now.Ticks - ts;
Console.WriteLine(String.Format("BasicObjectBindingTest1 completed in {0} seconds.", (endTime/10000000).ToString("0.000000")));
writer.Flush();
writer.Close();
engine.close();
}
Assert.IsTrue(fired == 1);
Assert.IsTrue(activations == 1);
//AppDomain.Unload(AppDomain.CurrentDomain);
}
示例2: addSuccessorNode
/// <summary> NotJoin has to have a special addSuccessorNode since it needs
/// to just propogate the left facts if it has zero matches.
/// </summary>
public override void addSuccessorNode(TerminalNode node, Rete engine, IWorkingMemory mem)
{
if (addNode(node))
{
// first, we Get the memory for this node
IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this);
// now we iterate over the entry set
IEnumerator itr = leftmem.Values.GetEnumerator();
while (itr.MoveNext())
{
Object omem = itr.Current;
if (omem is IBetaMemory)
{
IBetaMemory bmem = (IBetaMemory) omem;
EqHashIndex inx = new EqHashIndex(NodeUtils.getLeftValues(binds, bmem.LeftFacts));
HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl) mem.getBetaRightMemory(this);
// we don't bother adding the right fact to the left, since
// the right side is already Hashed
if (rightmem.count(inx) == 0)
{
node.assertFacts(bmem.Index, engine, mem);
}
}
}
}
}
示例3: executeFunction
public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
{
bool bound = false;
if (params_Renamed.Length == 2)
{
String name = params_Renamed[0].StringValue;
Object val = null;
if (params_Renamed[1] is ValueParam)
{
val = params_Renamed[1].Value;
}
else if (params_Renamed[1] is FunctionParam2)
{
FunctionParam2 fp2 = (FunctionParam2) params_Renamed[1];
fp2.Engine = engine;
fp2.lookUpFunction();
DefaultReturnVector drv = (DefaultReturnVector) fp2.Value;
val = drv.firstReturnValue().Value;
}
engine.setBindingValue(name, val);
bound = true;
}
DefaultReturnVector ret = new DefaultReturnVector();
DefaultReturnValue rv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, bound);
ret.addReturnValue(rv);
return ret;
}
示例4: generateDeffact
/// <summary>
/// </summary>
/// <param name="">cond
/// </param>
/// <param name="">templ
/// </param>
/// <param name="">engine
/// </param>
/// <returns>
///
/// </returns>
public static IFact generateDeffact(ObjectCondition cond, Deftemplate templ, Rete.Rete engine)
{
List<object> list = new List<Object>();
IConstraint[] cnstr = cond.Constraints;
for (int idx = 0; idx < cnstr.Length; idx++)
{
IConstraint cn = cnstr[idx];
if (cn is LiteralConstraint)
{
Slot s = new Slot(cn.Name, cn.Value);
list.Add(s);
}
else if (cn is PredicateConstraint)
{
PredicateConstraint pc = (PredicateConstraint) cn;
Object val = generatePredicateValue(pc);
Slot s = new Slot(cn.Name, val);
list.Add(s);
}
else if (cn is BoundConstraint)
{
// for now we do the simple thing and just set
// any bound slots to 1
Slot s = new Slot(cn.Name, 1);
list.Add(s);
}
}
IFact f = templ.createFact(list, engine.nextFactId());
return f;
}
示例5: ObjectBindingTest1
public void ObjectBindingTest1()
{
long ts = DateTime.Now.Ticks;
int fired = 0;
int activations = 0;
using (TextWriter writer = Console.Out)
{
Rete engine = new Rete();
engine.Watch = WatchType.WATCH_ALL;
engine.addPrintWriter("Console", writer);
engine.declareObject(typeof (Account), "Account");
engine.loadRuleset(getRule1());
engine.assertObject(GetAcct0(), "Account", false, false);
activations = engine.CurrentFocus.ActivationCount;
fired = engine.fire();
engine.printWorkingMemory(true, false);
double endTime = DateTime.Now.Ticks - ts;
Console.WriteLine(String.Format("ObjectBindingTest1 completed in {0} seconds.", (endTime/10000000).ToString("0.000000")));
writer.Flush();
writer.Close();
engine.close();
}
Assert.IsTrue(fired == 1);
Assert.IsTrue(activations == 1);
//AppDomain.Unload(AppDomain.CurrentDomain);
}
示例6: DefaultRuleCompiler
/*
static DefaultRuleCompiler()
{
FUNCTION_NOT_FOUND = Messages.getString("CompilerProperties_function_not_found");
INVALID_FUNCTION = Messages.getString("CompilerProperties_invalid_function");
ASSERT_ON_PROPOGATE = Messages.getString("CompilerProperties_assert_on_Add");
}
*/
public DefaultRuleCompiler(Rete engine, IGenericMap<object, object> inputNodes)
{
InitBlock();
this.engine = engine;
this.inputnodes = inputNodes;
tval = new TemplateValidation(engine);
}
示例7: assertRight
/// <summary> Assert from the right side is always going to be from an Alpha node.
///
/// </summary>
/// <param name="">factInstance
/// </param>
/// <param name="">engine
///
/// </param>
public override void assertRight(IFact rfact, Rete engine, IWorkingMemory mem)
{
// Get the memory for the node
HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory) mem.getBetaRightMemory(this);
NotEqHashIndex inx = new NotEqHashIndex(NodeUtils.getRightBindValues(binds, rfact));
rightmem.addPartialMatch(inx, rfact);
bool zm = rightmem.zeroMatch(inx);
IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this);
IEnumerator itr = leftmem.Values.GetEnumerator();
while (itr.MoveNext())
{
Index linx = (Index) itr.Current;
if (evaluate(linx.Facts, rfact))
{
if (!zm)
{
try
{
propogateRetract(linx, engine, mem);
}
catch (RetractException e)
{
throw new AssertException("NotJion - " + e.Message);
}
}
}
}
}
示例8: testFiveRules
public void testFiveRules()
{
int objCount = 25000;
Random ran = new Random();
ArrayList facts = new ArrayList();
// loop and create account and transaction objects
for (int idx = 0; idx < objCount; idx++)
{
Account4 acc = new Account4();
acc.AccountId = "acc" + idx;
acc.AccountType = Convert.ToString(ran.Next(100000));
acc.First = Convert.ToString(ran.Next(100000));
acc.Last = Convert.ToString(ran.Next(100000));
acc.Middle = Convert.ToString(ran.Next(100000));
acc.Status = Convert.ToString(ran.Next(100000));
acc.Title = Convert.ToString(ran.Next(100000));
acc.Username = Convert.ToString(ran.Next(100000));
acc.CountryCode = "US";
acc.Cash = 1298.00;
facts.Add(acc);
Transaction tx = new Transaction();
tx.AccountId = "acc" + idx;
tx.Total = 1200000;
facts.Add(tx);
}
Console.WriteLine("created " + objCount + " Accounts and Transactions");
Rete engine = new Rete();
engine.declareObject(typeof (Account4));
engine.declareObject(typeof (Transaction));
Console.WriteLine("delcare the objects");
engine.close();
}
示例9: assertLeft
public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem)
{
long time = RightTime;
IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this);
leftmem.Put(linx, linx);
EqHashIndex inx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts));
TemporalHashedAlphaMem rightmem = (TemporalHashedAlphaMem) mem.getBetaRightMemory(this);
IEnumerator itr = rightmem.iterator(inx);
if (itr != null)
{
try
{
while (itr.MoveNext())
{
IFact vl = (IFact) itr.Current;
if (vl != null)
{
if (vl.timeStamp() > time)
{
propogateAssert(linx.add(vl), engine, mem);
}
else
{
rightmem.removePartialMatch(inx, vl);
propogateRetract(linx.add(vl), engine, mem);
}
}
}
}
catch (RetractException e)
{
// there shouldn't be any retract exceptions
}
}
}
示例10: loadFunctions
public virtual void loadFunctions(Rete engine)
{
StringCompareFunction compare = new StringCompareFunction();
engine.declareFunction(compare);
funcs.Add(compare);
StringIndexFunction indx = new StringIndexFunction();
engine.declareFunction(indx);
funcs.Add(indx);
StringLengthFunction strlen = new StringLengthFunction();
engine.declareFunction(strlen);
funcs.Add(strlen);
StringLowerFunction lower = new StringLowerFunction();
engine.declareFunction(lower);
funcs.Add(lower);
StringReplaceFunction strrepl = new StringReplaceFunction();
engine.declareFunction(strrepl);
funcs.Add(strrepl);
StringUpperFunction upper = new StringUpperFunction();
engine.declareFunction(upper);
funcs.Add(upper);
SubStringFunction sub = new SubStringFunction();
engine.declareFunction(sub);
funcs.Add(sub);
StringTrimFunction trim = new StringTrimFunction();
engine.declareFunction(trim);
funcs.Add(trim);
}
示例11: testAssertWithInterface
public void testAssertWithInterface()
{
Console.WriteLine("-----------------------------");
Console.WriteLine("start testAssertWithInterface");
Rete engine = new Rete();
engine.declareObject(typeof (IAccount), "account");
Assert.IsNotNull(engine);
Account acc1 = new Account();
acc1.AccountId = "1234";
acc1.AccountType = "new";
acc1.First = "fName";
acc1.Last = "lName";
acc1.Middle = "m";
acc1.OfficeCode = "MA";
acc1.RegionCode = "NE";
acc1.Status = "active";
acc1.Title = "MR";
acc1.Username = "user1";
try
{
engine.assertObject(acc1, "account", false, true);
Assert.IsTrue(true);
Assert.AreEqual(1, engine.ObjectCount);
Console.WriteLine("Number of facts: " + engine.ObjectCount);
engine.printWorkingMemory(true, true);
}
catch (AssertException e)
{
Console.WriteLine(e.Message);
}
engine.close();
}
示例12: MessageRouter
/// <summary>
/// The constructor for a message router.
/// </summary>
/// <param name="engine">The engine.</param>
public MessageRouter(Rete.Rete engine)
{
InitBlock();
this.engine = engine;
interpreter = new CLIPSInterpreter(engine);
commandThread = new CommandThread(this);
commandThread.Start();
}