示例#1
0
 public InternalActionLiteral(Atom ns, Structure p, Agent ag) : base(ns, p)
 {
     if (ag != null)
     {
         ia = ag.GetIA(GetFunctor());
     }
 }
示例#2
0
 public InternalAction GetIA(Agent ag)
 {
     if (ia == null && ag != null)
     {
         ia = ag.GetIA(GetFunctor());
     }
     return(ia);
 }
示例#3
0
        public static JasonityException CreateWrongArgumentNb(InternalAction ia)
        {
            string msg;

            if (ia.GetMinArgs() == ia.GetMaxArgs())
            {
                if (ia.GetMinArgs() == 1)
                {
                    msg = " One argument is expected.";
                }
                else
                {
                    msg = " " + ia.GetMinArgs() + " arguments are expected.";
                }
            }
            else
            {
                msg = " From " + ia.GetMinArgs() + " to " + ia.GetMaxArgs() + " arguments are expected.";
            }
            return(new JasonityException("The internal action '" + ia.GetMaxArgs() + " arguments are expected."));
        }
示例#4
0
 public IEnumerator <Unifier> LogicalConsecuence(Agent ag, Unifier un)
 {
     if (ag == null || ag.GetReasoner().GetUserAgArch().IsRunning())
     {
         try
         {
             InternalAction ia = GetIA(ag);
             if (!ia.CanBeUsedInContext())
             {
                 Debug.Log(GetErrorMsg() + ": internal action" + GetFunctor() + " cannot be used in context or rules");
                 return(LogExpr.EMPTY_UNIF_LIST.GetEnumerator());
             }
             //calls IA's execute method
             object oresult = ia.Execute(ag.GetReasoner(), un, ia.PrepareArguments(this, un));
             if (oresult.GetType() == typeof(bool) && (bool)oresult)
             {
                 return(LogExpr.CreateUnifEnumerator(un));
             }
             else if (oresult.GetType() == typeof(IEnumerator <>))
             {
                 return((IEnumerator <Unifier>)oresult);
             }
         }
         catch (Exception e)
         {
             Debug.Log("*-*-*" + GetFunctor() + " concurrent exception - try later" + e.ToString());
             try
             {
                 Thread.Sleep(2000);
             }
             catch (Exception e1)
             {
                 return(LogicalConsecuence(ag, un));
             }
         }
     }
     return(LogExpr.EMPTY_UNIF_LIST.GetEnumerator());
 }
示例#5
0
 public void SetIA(string iaName, InternalAction ia)
 {
     internalActions.Add(iaName, ia);
 }
示例#6
0
 public static JasonityException CreateWrongArgument(InternalAction ia, string reason)
 {
     return(new JasonityException("Wrong argument for internal action '" + ia.GetType().Name + "': " + reason, WRONG_ARGS));
 }
示例#7
0
 //used by cloneNS
 private InternalActionLiteral(Atom ns, InternalActionLiteral l) : base(ns, (Structure)l)
 {
     this.ia = l.ia;
 }
示例#8
0
 //used by capply
 private InternalActionLiteral(InternalActionLiteral l, Unifier u) : base((Structure)l, u)
 {
     this.ia = l.ia;
 }
示例#9
0
 //used by clone
 public InternalActionLiteral(InternalActionLiteral l) : base(l.GetNS(), (Structure)l)
 {
     this.ia = l.ia;
 }
示例#10
0
 public void SetIA(InternalAction ia)
 {
     this.ia = ia;
 }