Class Term

All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
Predicate

public class Term extends Symbol implements Cloneable, Serializable
Representation of term logical form.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • add

      @Deprecated public boolean add(Symbol a)
      Deprecated.
    • get

      public Symbol get(int i)
      Returns the i-th argument, null if the i is out of range.
      Parameters:
      i -
      Returns:
    • getArgs

      public List<Symbol> getArgs()
      Get arguments as a shallow copy.
      Returns:
    • getArgsRef

      @Deprecated public List<Symbol> getArgsRef()
      Deprecated.
    • getArgsCopy

      public List<Symbol> getArgsCopy()
      Gets arguments as a deep copy.
      Returns:
    • getVars

      public Set<Variable> getVars()
      Get all Variable instances contained in this Term.
      Returns:
    • getOrderedVars

      public List<Variable> getOrderedVars()
      Get all Variable instances in the order in which they appear (depth first in cases of nested Terms).
      Returns:
    • getOrderedLeaves

      public List<Symbol> getOrderedLeaves()
      Get leaves in order in which they appear (depth first in cases of nested Terms).
      Returns:
    • getBindings

      public Map<Variable,Symbol> getBindings(Term other)
      Gets variable bindings from this Term to another. Supports nested terms (and will return those bindings as well).
      Parameters:
      other - Term providing the bindings for variables in this term
      Returns:
      bindings map
    • instanceOf

      public boolean instanceOf(Term template)
      Compares "instantiated" term to a template. TODO: FIXME: this is broken when a variable appears more than once in the template and different values are used for that variable
      Parameters:
      template -
      Returns:
      true if this predicate matches the template.
    • copyWithNewBindings

      public Term copyWithNewBindings(Map<Variable,? extends Symbol> bindings)
      Similar to applyBindingMap, except this Term is not bound. Instead, a cloned version is bound and returned.
      Parameters:
      bindings -
    • copyWithNewBindings

      public Set<Term> copyWithNewBindings(List<? extends Map<Variable,? extends Symbol>> bindings)
    • applyBindingMap

      protected void applyBindingMap(Map<Variable,? extends Symbol> bindings)
      Protected helper method for copyWithNewBindings. Replaces Variables with Symbols from the bindings map. Note that not all Variables need to be bound.
      Parameters:
      bindings -
    • copyWithNewVariableTypes

      public Term copyWithNewVariableTypes(Collection<Variable> typedVariables)
      Returns a clone with replaced variables' types with passed in variables' types.
      Parameters:
      typedVariables -
      Returns:
    • applyVariableTypes

      protected void applyVariableTypes(Collection<Variable> typedVariables)
      Replaces variables' types with passed in variables' types.
    • set

      @Deprecated public void set(int i, Symbol newArg)
      Deprecated.
    • size

      public int size()
      Return the number of arguments.
      Returns:
    • equalsIgnoreType

      public boolean equalsIgnoreType(Object o)
      Compare without checking semantic type information.
      Overrides:
      equalsIgnoreType in class Symbol
      Parameters:
      o -
      Returns:
    • equals

      public boolean equals(Object o)
      Check whether the given object is equal to this one. Two Symbols are equal if they're of the same class, their names are the same, and their args are the same.
      Overrides:
      equals in class Symbol
      Parameters:
      o - the Object to compare this with
      Returns:
      true if they're equal, false otherwise
    • hashCode

      public int hashCode()
      Calculate hash code for this Term.
      Overrides:
      hashCode in class Symbol
      Returns:
      the hash code
    • toString

      public String toString()
      Constructs a String representation of the Term. If the term is negated, then it is wrapped in a not().
      Overrides:
      toString in class Symbol
      Returns:
      String of the form name(args...) or not(name(args...))
    • toUntypedString

      public String toUntypedString()
      Description copied from class: Symbol
      Constructs a String representation that does not include type information.
      Overrides:
      toUntypedString in class Symbol
      Returns:
      String of the form "name(arg0,..., argN)"
    • toUnnegatedForm

      public Term toUnnegatedForm()
      Description copied from class: Symbol
      Returns a FOL instance that is not negated (i.e., drops outer "not" if it exists). This doesn't apply to the Symbol class which can't be negated, but is here as a convenience so that Term/Predicate instances passed as Symbols (e.g., via getArgs) don't need to be cast to Term/Predicate.
      Overrides:
      toUnnegatedForm in class Symbol
      Returns:
      Un-negated form of this FOL class.
    • toNegatedForm

      public Term toNegatedForm()
    • isNegated

      public boolean isNegated()
      Check if this Term is negated (i.e., functor name is "not").
      Returns:
    • clone

      public Term clone()
      Overrides:
      clone in class Symbol
    • hasArgs

      public boolean hasArgs()
      Checks if this symbol has arguments.
      Overrides:
      hasArgs in class Symbol
      Returns:
      true if Term has arguments.
    • isTerm

      public boolean isTerm()
      Overrides:
      isTerm in class Symbol