/// <summary> /// Displays the engine's results of the interview session. /// </summary> private static void DisplayResults(Facts.Fact goal) { Console.WriteLine("\n"); // Indent and format results string tline = "\t" + goal.ValueAsString().Replace("\n", "\n\t"); // For eternal values, only show value if (goal.Value().IsEternal) { tline = tline.Replace("DawnOfTime ", ""); } // Concatenate question and answer string result = "\t" + goal.QuestionText() + "\n\n" + tline + "\n"; // Add result to test case Tvar testResult = goal.GetFunction().Invoke(); AkkTest.CloseUnitTest(testResult, goal.Relationship); Console.WriteLine(result); }
/// <summary> /// Takes an income packet and instantiates a Hammurabi session. /// </summary> public Packet Assess(Packet request) { // Start timer DateTime startTime = DateTime.Now; // Pre-evaluate each goal to enable look-ahead short circuiting. // See Hammurabi | Core | Engine.cs, line ~81, for an explanation. foreach (Factoid g in request.Goals) { Facts.Fact gb = new Facts.Fact(g.Relationship, g.Arg1, g.Arg2, g.Arg3); gb.Value(); } // Start a fresh session // Facts.Clear(); Facts.GetUnknowns = true; Facts.Unknowns.Clear(); bool allDone = true; request.PercentageComplete = 100; // Assert facts into a Hammurabi session foreach (Factoid f in request.AssertedFacts) { AssertFact(f); } // Iterate through each goal foreach (Factoid g in request.Goals) { Facts.Fact gb = new Facts.Fact(g.Relationship, g.Arg1, g.Arg2, g.Arg3); // Assign to a variable so it's only evaluated once Tvar gbVal = gb.Value(); // Convert Tvar to timeline object g.Timeline = TvarToTimeline(gbVal); // All goals resolved? if (!gbVal.HasBeenDetermined) { allDone = false; } } // Stop looking for unknown facts Facts.GetUnknowns = false; // Determine the next fact and the percent complete if (!allDone) { // Factoid neededFact = new Factoid("Tnum","USC.Tit26.Sec151.ThresholdAmount","Jim","",""); // Facts.Fact f = new Facts.Fact("USC.Tit26.Sec151.ThresholdAmount", null, null, null); // Factoid neededFact = new Factoid(f); Factoid neededFact = new Factoid(Facts.Unknowns[0]); request.NeededFacts = new List <Factoid>() { neededFact }; request.PercentageComplete = Interactive.Engine.ProgressPercentage(Facts.Count(), Facts.Unknowns.Count); } // Add elapsed time to response object request.ResponseTimeInMs = Convert.ToInt32((DateTime.Now - startTime).TotalMilliseconds); return(request); }