Class ContextUtils
java.lang.Object
edu.tufts.hrilab.action.execution.util.ContextUtils
Utility methods for exploring, searching, analyzing, etc the Context tree.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ActionContextgetActionContext(Context rootContext, Term stepPredicate, ActionStatus actionStatus) Use the step predicate to find the matching action, or closest parent to the matching context, in the context tree.static ContextgetFailureContext(Context context) get the context which caused the failurestatic ContextgetMatchingContext(Context rootContext, Term stepPredicate, ActionStatus actionStatus) Find the Context in the context tree that matches the stepPredicate.static ContextgetMatchingContext(Context rootContext, Term stepPredicate, ActionStatus actionStatus, Term locationReference) Find the Context in the context tree that matches the stepPredicate.static booleanisActionScript(Context context) Helper method to check if Context is an action script context.
-
Constructor Details
-
ContextUtils
public ContextUtils()
-
-
Method Details
-
getActionContext
public static ActionContext getActionContext(Context rootContext, Term stepPredicate, ActionStatus actionStatus) Use the step predicate to find the matching action, or closest parent to the matching context, in the context tree.TODO: there's an interesting question here about what depth in the context tree should be reported: (1) the deepest matching action which could be a primitive, (2) the deepest script, since primitives can't really be modified dynamically, (3) the top-most action, or (4) something in between.
Currently, (2) is being returned if a script is found, otherwise fall back to (1). That is, once the matching context has been found, return it's closest parent that is an ActionContext and is a script. If no script can be found, return the closest parent that is an ActionContext (which will be a primitive).
- Parameters:
rootContext- - Context to start searching from. Will only search rootContext and deeper.stepPredicate- - step of context trying to matchactionStatus- - status of context- Returns:
-
getMatchingContext
public static Context getMatchingContext(Context rootContext, Term stepPredicate, ActionStatus actionStatus) Find the Context in the context tree that matches the stepPredicate. The context getSignatureInPredicateForm must exactly match the stepPredicate. Will return null when no match is found.- Parameters:
rootContext- - Context to start searching from. Will only search rootContext and deeper.stepPredicate- - step of context trying to matchactionStatus- - status of context- Returns:
-
getMatchingContext
public static Context getMatchingContext(Context rootContext, Term stepPredicate, ActionStatus actionStatus, Term locationReference) Find the Context in the context tree that matches the stepPredicate. The context getSignatureInPredicateForm must exactly match the stepPredicate. Will return null when no match is found.- Parameters:
rootContext- - Context to start searching from. Will only search rootContext and deeper.stepPredicate- - step of context trying to matchactionStatus- - status of contextlocationReference- - reference step used to locate correct step- Returns:
-
isActionScript
Helper method to check if Context is an action script context.- Parameters:
context-- Returns:
-
getFailureContext
get the context which caused the failure- Parameters:
context- failed context- Returns:
- the child which caused the failure, or null if no failure found
-