示例#1
0
        /// <summary>
        /// Scans the assumption table, looking for assumptions to add to the Facts.Unknowns list.
        /// </summary>
        public static void AskAssumedFacts(string rel, Thing e1, Thing e2, Thing e3)
        {
            foreach (Pair p in Pairs)
            {
                // If A, then B
                if (p.LeftHandPoint.Relationship == rel)
                {
                    // For each rightPoint.Arg number, get the corresponding Thing
                    Thing[] args = new Thing[3]{e1,e2,e3};

                    int a1 = p.RightHandPoint.Arg1 - 1;  // -1 b/c array is base-zero
                    int a2 = p.RightHandPoint.Arg2 - 1;
                    int a3 = p.RightHandPoint.Arg3 - 1;

                    Thing t1 = a1 >= 0 ? args[a1] : null;
                    Thing t2 = a2 >= 0 ? args[a2] : null;
                    Thing t3 = a3 >= 0 ? args[a3] : null;

                    // Investigates all assumptions
                    // TODO: Does not short circuit
                    Facts.Fact f = new Facts.Fact(p.RightHandPoint.Relationship, t1.Id, t2.Id, t3.Id);
                    f.Value();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Adds a thing to the ThingBase, if it's not already there.  Returns the Thing itself.
        /// </summary>
        public static Thing AddThing(Thing thing)
        {
            // If a Thing with that name exists, return it
            foreach (Thing t in ThingBase)
            {
                if (IsAddable(thing) && t.Id == thing.Id)
                {
                    return thing;
                }
            }

            // Else (if thing does not exist), add and return it
            if (IsAddable(thing))
            {
                ThingBase.Add(thing);
            }
            return thing;
        }
示例#3
0
        /// <summary>
        /// Adds a thing to the ThingBase, based on the uniqueness of its name.  Returns the Thing itself.
        /// </summary>
        public static new Thing AddThing(string thingName)
        {
            Thing thing = new Thing(thingName);

            // If a Thing with that name exists, return it
            foreach (Thing t in ThingBase)
            {
                if (IsAddable(thing) && t.Id == thingName)
                {
                    return t;
                }
            }

            // Else, if thing does not exist, create and assert a new one

            if (IsAddable(thing))
            {
                ThingBase.Add(thing);
            }
            return thing;
        }
示例#4
0
 /// <summary>
 /// Returns the set of all Things in the session, except two specific Things.
 /// </summary>
 public static Tset peopleBut(Thing p1, Thing p2)
 {
     return Facts.AllKnownPeople() - p1 - p2;
 }
示例#5
0
 /// <summary>
 /// Returns the set of all Things in the session, except a specific Thing.
 /// </summary>
 public static Tset peopleBut(Thing p1)
 {
     return Facts.AllKnownPeople() - p1;
 }
示例#6
0
 /// <summary>
 /// Returns a set of all known people except a given person.
 /// </summary>
 public static Tset EveryoneExcept(Thing p)
 {
     return AllKnownPeople() - p;
 }
示例#7
0
 /// <summary>
 /// Returns true when the Tset contains a given legal entity. 
 /// </summary>
 public Tbool Contains(Thing e)
 {
     return ApplyFcnToTimeline<Tbool>(x => CoreSubset(x), new Tset(e), this);
 }
示例#8
0
 /// <summary>
 /// Sets the Tset to eternally have a given member. 
 /// </summary>
 public void SetEternally(Thing val)
 {
     TimeLine.Add(Time.DawnOf, new Hval(val));    
 }
示例#9
0
        /// <summary>
        /// Scans the assumption table, looking for forward-chaining inferences.
        /// </summary>
        public static void TriggerInferences(string rel, Thing e1, Thing e2, Thing e3, Tvar val)
        {
            foreach (Pair p in Pairs)
            {
                // If A, then B
                if (p.LeftHandPoint.Relationship == rel)
                {
                    // TODO: Currently only handles expressions that are eternally true
                    if (Tvar.EqualTo(p.LeftHandPoint.Value, val))
                    {
                        // For each rightPoint.Arg number, get the corresponding Thing
                        Thing[] args = new Thing[3]{e1,e2,e3};

                        int a1 = p.RightHandPoint.Arg1 - 1;  // -1 b/c array is base-zero
                        int a2 = p.RightHandPoint.Arg2 - 1;
                        int a3 = p.RightHandPoint.Arg3 - 1;

                        Thing t1 = a1 >= 0 ? args[a1] : null;
                        Thing t2 = a2 >= 0 ? args[a2] : null;
                        Thing t3 = a3 >= 0 ? args[a3] : null;

                        Facts.Assert(t1, p.RightHandPoint.Relationship, t2, t3, p.RightHandPoint.Value);
                    }
                }

                // If -B, then -A
                else if (p.RightHandPoint.Relationship == rel)
                {
                    // If right-hand expression is always false...
                    if (Tvar.EqualTo(p.RightHandPoint.Value, val).IsFalse)
                    {
                        // If the left-hand side is a boolean (non-booleans can't be negated)...
                        if (Tvar.EqualTo(p.LeftHandPoint.Value, new Tbool(true)) ||
                            Tvar.EqualTo(p.LeftHandPoint.Value, new Tbool(false)))
                        {
                            // For each leftPoint.Arg number, get the corresponding Thing
                            int r1 = p.RightHandPoint.Arg1;
                            int r2 = p.RightHandPoint.Arg2;
                            int r3 = p.RightHandPoint.Arg3;

                            // I hope no one sees how ugly this is
                            Thing t1, t2, t3;
                            if (r1 == 1)      t1 = e1;
                            else if (r2 == 1) t1 = e2;
                            else              t1 = e3;

                            if (r1 == 2)      t2 = e1;
                            else if (r2 == 2) t2 = e2;
                            else              t2 = e3;

                            if (r1 == 3)      t3 = e1;
                            else if (r2 == 3) t3 = e2;
                            else              t3 = e3;

                            // Assert -A
                            Tbool leftVal = (Tbool)p.LeftHandPoint.Value;
                            Facts.Assert(t1, p.LeftHandPoint.Relationship, t2, t3, !leftVal);
                        }
                    }
                }
            }
        }
示例#10
0
 /// <summary>
 /// Only known Things can be added.
 /// </summary>
 private static bool IsAddable(Thing t)
 {
     if (t == null) return false;
     if (t.Id == "") return false;
     return true;
 }