Class PredicateHelper

java.lang.Object
edu.tufts.hrilab.vision.util.PredicateHelper

public class PredicateHelper extends Object
Helper methods to deal with Predicates in VisionComponent.
  • Field Details

  • Constructor Details

    • PredicateHelper

      public PredicateHelper()
  • Method Details

    • getRepresentativeString

      public static String getRepresentativeString(Term term)
      Get the representative string from a Predicate. This is pretty much a hack in order to pass the appropriate string to the native side and to look up the associated VisionProcess via the hashmaps they are stored in. This can hopefully be made more general and non-hacky once Predicates have been standardized in DIARC, and if Predicates can be handled directly on the native side. Vision assumes all predicates have descriptor as functor name. Examples: red(X) -> red, near(A,B) -> near
      Parameters:
      term -
      Returns:
    • getNativeStringRepresentation

      public static String getNativeStringRepresentation(Symbol symbol)
      Basically a customized toString method for the Symbol class hierarchy. Does not retain Variable type, and also converts bound Variables to their bound value, disregarding the Variable name and type (e.g., name/binding = A/red(X) --> red(X)).
      Parameters:
      symbol -
      Returns:
    • splitIntoEntities

      public static Map<List<Variable>,List<Term>> splitIntoEntities(List<? extends Term> predicates)
    • convertToVisionForm

      public static List<Term> convertToVisionForm(List<? extends Symbol> symbols)
    • convertToVisionForm

      public static List<Term> convertToVisionForm(Symbol symbol)
    • removeDuplicates

      public static void removeDuplicates(List<? extends Symbol> symbols)
    • orderVariables

      public static List<Variable> orderVariables(List<? extends Term> terms)
      Order the variables contained in the list of terms using the relation terms (i.e., Term with 2 variables) as the ordering constraints where the second variable of a relation needs to come first in the ordering. For example, handle(Y), on(Y,X), mug(X), would produce the ordering X -> Y.
      Parameters:
      terms -
      Returns:
    • orderVariableLists

      public static List<List<Variable>> orderVariableLists(Set<List<Variable>> unorderedVars)
      Order the set of variable lists using relations (i.e., list with 2 variables) as the ordering constraints where the second variable of a relation needs to come first in the ordering. For example, handle(Y) & on(Y,X) & mug(X), which produces the following lists of variables [Y],[Y,X],[X] would produce the ordering X -> Y -> X,Y.
      Parameters:
      unorderedVars -
      Returns:
    • replace

      public static Predicate replace(Term term, Symbol argOld, Symbol argNew)
      Replace all occurences of argOld with argNew in term and return a new Predicate with the specified replacements.
      Parameters:
      term -
      argOld -
      argNew -
      Returns:
    • setVariableType

      public static void setVariableType(Symbol symbol, String type)
      Sets the 'type' field of every Variable contained in the symbol.
      Parameters:
      symbol -
      type -
    • createPredicate

      public static Predicate createPredicate(String s)
      Wrapper around Factory.createPredicate that sets all variables to varType (e.g., "object").
      Parameters:
      s -
      Returns:
    • createPredicate

      public static Predicate createPredicate(String s, String type)
      Wrapper around Util.createPredicate that sets all variables to varType (e.g., type).
      Parameters:
      s -
      Returns:
    • isObjectRef

      public static boolean isObjectRef(List<? extends Symbol> descriptors)
      Check if a list a descriptors is specifying a POWER object ref. Basically, that there's a single descriptor that matches "[kbName]_[number]" (e.g., object_3).
      Parameters:
      descriptors -
      Returns:
    • isObjectRef

      public static boolean isObjectRef(Symbol descriptor)
      Check if a single descriptor is a POWER object ref that matches "[kbName]_[number]" (e.g., object_3).
      Parameters:
      descriptor -
      Returns: