Class ArgumentBasedContext

java.lang.Object
edu.tufts.hrilab.action.execution.Context
edu.tufts.hrilab.action.execution.ArgumentBasedContext
Direct Known Subclasses:
AsynchronousContext, CatchContext, DatabaseEntryContext, ExitContext, ForContext, ForeachContext, GoalContext, JoinContext, ObservationContext, TradeServiceContext

public abstract class ArgumentBasedContext extends Context
  • Field Details

  • Constructor Details

  • Method Details

    • setupArguments

      protected abstract void setupArguments(List<? extends Object> inputArgs, List<? extends Object> returnArgs)
    • getSignatureInPredicateForm

      public Predicate getSignatureInPredicateForm()
      Create predicate from the context cmd and arguments: "cmd(arg0, arg1, ...)".
      Overrides:
      getSignatureInPredicateForm in class Context
      Returns:
    • getArguments

      public List<ActionBinding> getArguments()
      Get list of copied and evaluated arguments in order. ?actor role is alwyas first.
      Overrides:
      getArguments in class Context
      Returns:
    • hasLocalArgument

      public boolean hasLocalArgument(String bname)
      Check if this context explicitly has the specified argument. This does not search the entire action scope.
      Parameters:
      bname - argument name
      Returns:
      true if argument exists
    • hasArgumentInScope

      public boolean hasArgumentInScope(String bname)
      Check if the specified argument exists in action scope. Scope in the context tree is defined as within an ActionContext (i.e., will not search outside of the containing ActionContextzs).
      Parameters:
      bname -
      Returns:
    • getArgumentValue

      public Object getArgumentValue(String bname)
      Retrieve the (deep) value of an argument, evaluating any unevaluated arguments in the process. Recurses up the caller tree to find argument, if it exists.
      Overrides:
      getArgumentValue in class Context
      Parameters:
      bname - the argument's name
      Returns:
      the deep binding associated with that name in the current context
    • getEvaluatedArgument

      protected ActionBinding getEvaluatedArgument(String bname)
      Return an ActionBinding with the (deep) value of an argument. This will attempt to evaluate any unevaluated arguments (e.g., strings containing free variables), and return them in a (potentially cloned) ActionBinding instance. Recurses up the caller tree to find argument, if it does not exist in this context.
      Overrides:
      getEvaluatedArgument in class Context
      Parameters:
      bname - the argument's name
      Returns:
      an (potentially cloned) ActionBinding associated with the bname in the current context
    • getArgumentType

      public Class<?> getArgumentType(String bname)
      Retrieve the type of an argument
      Overrides:
      getArgumentType in class Context
      Parameters:
      bname - the argument's name
      Returns:
      the type associated with that name in the current context
    • getArgument

      protected ActionBinding getArgument(String bname)
      Finds the ActionBinding in this or parent contexts. Returns null if no binding with that name exists. Similar to getEvaluatedArgument but does not attempt to evaluate or modify the ActionBinding in an way.
      Overrides:
      getArgument in class Context
      Parameters:
      bname - Binding name
      Returns:
      the closest binding with that name in the context tree
    • getArgumentSilent

      protected ActionBinding getArgumentSilent(String bname)
      Description copied from class: Context
      Same as getArgument method but does not generate a log statement in the case the argument is not found. This is useful for method like hasArgumentInScope(bname) so that confusing log error statements aren't made.
      Overrides:
      getArgumentSilent in class Context
      Returns:
    • getLocalArgument

      protected ActionBinding getLocalArgument(String bname)
      Description copied from class: Context
      Get a local argument without recursing up the context tree. Only classes that extend ArgumentBasedContext will have local arguments, so this return null by default.
      Overrides:
      getLocalArgument in class Context
      Returns:
    • copyArguments

      protected void copyArguments(LinkedHashMap<String,ActionBinding> argumentsToCopy)
      Copy arguments into this Context. This is currently only used to copy a Context. This first clears any existing arguments and then performs a deep copy on the passed in arguments.
      Parameters:
      argumentsToCopy -
    • addArgument

      protected boolean addArgument(String bName, Class<?> javaType, Object bValue, boolean bLocal, boolean bReturn)
      Adds a new argument to the current context. This is convenience method to the more general addArgument. This method sets the following values for fields that are not exposed: semanticType : null isVarArgs : false defaultValue : null
      Parameters:
      bName - the name of the argument
      javaType - the java type of the argument
      bValue - the value of the argument
      bLocal - whether the argument is a local script variable or not
      bReturn - whether the argument is a return variable or not
      Returns:
      true if argument was added to context, false if it conflicts with existing argument with same name
    • addArgument

      protected boolean addArgument(String bName, Class<?> javaType, String semanticType, Object bValue, String bDefault, boolean bLocal, boolean bReturn, boolean bIsVarArg)
      Adds a new argument to the current context
      Parameters:
      bName - the name of the argument
      javaType - the java type of the argument
      semanticType - the semantic type of the argument
      bValue - the value of the argument
      bDefault - the default value of the argument
      bLocal - whether the argument is a local script variable or not
      bReturn - whether the argument is a return variable or not
      bIsVarArg - whether the argument is a varArg argument ()
      Returns:
      true if argument was added to context, false if it conflicts with existing argument with same name
    • setArgument

      protected void setArgument(String bname, Object val)
      Specify the (deep) value of an argument
      Parameters:
      bname - the argument's name
      val - the value to which the argument should be bound
    • bindPredicate

      public Predicate bindPredicate(Symbol orig)
      Given the original Predicate, for each argument that is an unbound variable, create a binding and put it in a new Predicate.
      Parameters:
      orig -
      Returns:
      New Predicate with unbound arguments bound, if possible.
    • redistributeArguments

      protected void redistributeArguments()
    • bindText

      protected String bindText(String bName, String inText)
      Parses text and replaces args with their values.
      Parameters:
      inText - text to parse
      Returns:
      text with args replaced by their values