java.lang.Object
org.apache.jena.reasoner.rulesys.Functor
All Implemented Interfaces:
ClauseEntry

public class Functor extends Object implements ClauseEntry
A functor comprises a functor name and a list of arguments. The arguments are Nodes of any type except functor nodes (there is no functor nesting). Functors play three roles in rules - in heads they represent actions (procedural attachment); in bodies they represent builtin predicates; in TriplePatterns they represent embedded structured literals that are used to cache matched subgraphs such as restriction specifications.
  • Field Details

    • acceptFilter

      public static final Predicate<Triple> acceptFilter
      A static Predicate instance that detects triples with Functor objects
  • Constructor Details

    • Functor

      public Functor(String name, Node[] args)
      Constructor.
      Parameters:
      name - the name of the functor
      args - an array of nodes defining the arguments, this will not be copied so beware of accidental structure sharing
    • Functor

      public Functor(String name, List<Node> args, BuiltinRegistry registry)
      Constructor
      Parameters:
      name - the name of the functor
      args - a list of nodes defining the arguments
      registry - a table of builtins to consult to check for implementations of this functor when used as a rule clause
    • Functor

      public Functor(String name, Node[] args, BuiltinRegistry registry)
      Constructor
      Parameters:
      name - the name of the functor
      args - an array of nodes defining the arguments
      registry - a table of builtins to consult to check for implementations of this functor when used as a rule clause
    • Functor

      public Functor(String name, List<Node> args, Builtin impl)
      Constructor
      Parameters:
      name - the name of the functor
      args - a list of nodes defining the arguments
      impl - a specific builtin implementation of this functor
    • Functor

      public Functor(String name, Node[] args, Builtin impl)
      Constructor
      Parameters:
      name - the name of the functor
      args - a list of nodes defining the arguments
      impl - a specific builtin implementation of this functor
  • Method Details

    • getName

      public String getName()
      Return the functor name
    • getArgs

      public Node[] getArgs()
      Return the functor arguments as an array of nodes
    • getArgLength

      public int getArgLength()
      Return the length of the functor argument array.
    • isGround

      public boolean isGround()
      Returns true if the functor is fully ground, no variables
    • isGround

      public boolean isGround(BindingEnvironment env)
      Returns true if the functor is fully ground in the given environment
    • evalAsBodyClause

      public boolean evalAsBodyClause(RuleContext context)
      Execute the given built in as a body clause.
      Parameters:
      context - an execution context giving access to other relevant data
      Returns:
      true if the functor has an implementation and that implementation returns true when evaluated
    • safeEvalAsBodyClause

      public boolean safeEvalAsBodyClause(RuleContext context)
      Execute the given built in as a body clause, only if it is side-effect-free.
      Parameters:
      context - an execution context giving access to other relevant data
      Returns:
      true if the functor has an implementation and that implementation returns true when evaluated
    • getBoundArgs

      public Node[] getBoundArgs(BindingEnvironment env)
      Return a new Node array containing the bound versions of this Functor's arguments
    • getImplementor

      public Builtin getImplementor()
      Return the Builtin that implements this functor
      Returns:
      the Builtin or null if there isn't one
    • setImplementor

      public void setImplementor(Builtin implementor)
      Set the Builtin that implements this functor.
    • toString

      public String toString()
      Printable string describing the functor
      Overrides:
      toString in class Object
    • isFunctor

      public static boolean isFunctor(Node n)
      tests that a given Node represents a functor
    • equals

      public boolean equals(Object obj)
      Equality is based on structural comparison
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      hash function override
      Overrides:
      hashCode in class Object
    • sameAs

      public boolean sameAs(Object o)
      Compare Functors, taking into account variable indices. The equality function ignores differences between variables.
      Specified by:
      sameAs in interface ClauseEntry
    • makeFunctorNode

      public static Node makeFunctorNode(String name, Node[] args)
      Create a functor and wrap it up as a Literal node
      Parameters:
      name - the name of the functor
      args - an array of nodes defining the arguments, this will not be copied so beware of accidental structure sharing
    • makeFunctorNode

      public static Node makeFunctorNode(Functor f)
      Wrap a functor as a Literal node
      Parameters:
      f - the functor data structure to be wrapped in a node.