示例#1
0
 /** computes the value for this arithmetic function (as defined in the NumberTerm interface) */
 public override ITerm CApply(Unifier u)
 {
     if (function == null)
     {
         Debug.Log(GetErrorMsg() + " -- the function cannot be evaluated, it has no function assigned to it!");
     }
     else
     {
         ITerm v = base.CApply(u);
         if (function.AllowUngroundTerms() || v.IsGround())
         {
             try
             {
                 value = new NumberTermImpl(function.Evaluate((agent == null ? null : agent.GetReasoner()), ((Literal)v).GetTermsArray()));
                 return(value);
             }
             catch (Exception e)
             {
                 Debug.Log(GetErrorMsg() + " -- error in evaluated!");
             }
             finally
             {
                 //Ignore and return this
             }
         }
     }
     return((ITerm)Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear...
 }
示例#2
0
        public void ParserNumberTest()
        {
            INumberTerm nti       = new NumberTermImpl(12.5);
            INumberTerm resultado = AsSyntax.ParseNumber("12,5");

            Assert.AreEqual(nti.ToString(), resultado.ToString());
        }
示例#3
0
 public ArithExpr(INumberTerm t1, ArithmeticOp oper, INumberTerm t2) : base(oper.ToString(), 2)
 {
     AddTerm(t1);
     AddTerm(t2);
     op = oper;
     if (t1.GetSrcInfo() != null)
     {
         srcInfo = t1.GetSrcInfo();
     }
     else
     {
         srcInfo = t2.GetSrcInfo();
     }
 }
示例#4
0
        public override bool Equals(object o)
        {
            if (o == this)
            {
                return(true);
            }

            if (o != null && (o.GetType() == typeof(ITerm)) && (((ITerm)o).IsNumeric() && ((ITerm)o).IsArithExpr()))
            {
                INumberTerm st = o as INumberTerm;
                try
                {
                    return(Solve() == st.Solve());
                }
                catch (Exception e) { }
            }
            return(false);
        }
示例#5
0
        override public object Execute(Reasoner ts, Unifier un, ITerm[] args)
        {
            CheckArguments(args);

            long            timeout     = -1;
            Trigger         te          = null;
            ILogicalFormula f           = null;
            ITerm           elapsedTime = null;

            if (args[0].IsNumeric())
            {
                // time in milliseconds
                INumberTerm time = (INumberTerm)args[0];
                timeout = (long)time.Solve();
            }
            else
            {
                te = Trigger.TryToGetTrigger(args[0]);   // wait for event
                if (te == null && args[0].GetType() == typeof(ILogicalFormula))
                {
                    // wait for an expression to become true
                    f = (ILogicalFormula)args[0];
                    if (ts.GetAgent().Believes(f, un))
                    {
                        // if the agent already believes f
                        // place current intention back in I, since .wait usually does not do that
                        Intention si = ts.GetCircumstance().GetSelectedIntention();
                        si.Peek().RemoveCurrentStep();
                        ts.GetCircumstance().AddRunningIntention(si);
                        return(true);
                    }
                }
                if (args.Length >= 2)
                {
                    timeout = (long)((INumberTerm)args[1]).Solve();
                }
                if (args.Length == 3)
                {
                    elapsedTime = args[2];
                }
            }
            new WaitEvent(te, f, un, ts, timeout, elapsedTime);
            return(true);
        }
示例#6
0
        public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args)
        {
            CheckArguments(args);
            ITerm l1 = args[0];
            ITerm l2 = args[1];

            INumberTerm size = null;

            if (l1.IsList())
            {
                IListTerm lt = (IListTerm)l1;
                size = new NumberTermImpl(lt.Size());
            }
            else if (l1.IsString())
            {
                IStringTerm st = (IStringTerm)l1;
                size = new NumberTermImpl(st.GetString().Length);
            }
            if (size != null)
            {
                return(un.Unifies(l2, size));
            }
            return(false);
        }
示例#7
0
 public static object TermToObject(ITerm t)
 {
     if (t.IsAtom())
     {
         Atom t2 = (Atom)t;
         if (t2.Equals(Literal.LTrue))
         {
             return(true); //?? Boolean.TRUE
         }
         else if (t2.Equals(Literal.LFalse))
         {
             return(false); //?? Boolean.FALSE
         }
         else
         {
             return(t2.ToString());
         }
     }
     else if (t.IsNumeric())
     {
         INumberTerm nt = (INumberTerm)t;
         double      d  = 0;
         try
         {
             d = nt.Solve();
         }
         catch (NoValueException e)
         {
             //e.printStackTrace();
         }
         if (((byte)d) == d)
         {
             return((byte)d);
         }
         else if (((int)d) == d)
         {
             return((int)d);
         }
         else if (((float)d) == d)
         {
             return((float)d);
         }
         else if (((long)d) == d)
         {
             return((long)d);
         }
         else
         {
             return(d);
         }
     }
     else if (t.IsString())
     {
         return(((IStringTerm)t).GetString());
     }
     else if (t.IsList())
     {
         List <object> list = new List <object>();
         foreach (ITerm t1 in (IListTerm)t)
         {
             list.Add(TermToObject(t1));
         }
         return(list);
     }
     else if (t.GetType() == typeof(IObjectTerm))
     {
         return(((IObjectTerm)t).GetObject());
     }
     else
     {
         return(t.ToString());
     }
 }
示例#8
0
 public ArithExpr(ArithmeticOp oper, INumberTerm t1) : base(oper.ToString(), 1)
 {
     AddTerm(t1);
     op      = oper;
     srcInfo = t1.GetSrcInfo();
 }