Class PredicateKey

java.lang.Object
org.projog.core.predicate.PredicateKey
All Implemented Interfaces:
Comparable<PredicateKey>

public final class PredicateKey extends Object implements Comparable<PredicateKey>
Represents the structure of a Term.

Defines Terms by their name (functor) and number of arguments (arity). This "metadata" or "descriptor information" allows rules whose heads (consequences) share the same structure to be grouped together.

As terms of type TermType.ATOM and TermType.STRUCTURE are the only terms that can be the head (consequent) of a rule they are the only subclasses of Term that PredicateKey is intended to describe.

PredicateKeys are constant; their values cannot be changed after they are created.

  • Constructor Details

    • PredicateKey

      public PredicateKey(String name, int numArgs)
  • Method Details

    • createForTerm

      public static PredicateKey createForTerm(Term t)
      Returns a PredicateKey for the specified term.
      Parameters:
      t - a term the returned PredicateKey should represent (needs to have a Term.getType() value of TermType.ATOM or TermType.STRUCTURE)
      Returns:
      a PredicateKey for the specified term.
      Throws:
      ProjogException - if t is not of type TermType.ATOM or TermType.STRUCTURE
    • createFromNameAndArity

      public static PredicateKey createFromNameAndArity(Term t)
      Parameters:
      t - must be a structure named / where the first argument is the name of the predicate to represent and the second (and final) argument is the arity.
    • getName

      public String getName()
    • getNumArgs

      public int getNumArgs()
    • toTerm

      public Term toTerm()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      Parameters:
      o - the reference object with which to compare.
      Returns:
      true if o is an instanceof PredicateKey and has the same name and number of arguments as this instance
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      name+"/"+numArgs
    • compareTo

      public int compareTo(PredicateKey o)
      Ordered on name or, if names identical, number of arguments.
      Specified by:
      compareTo in interface Comparable<PredicateKey>