Package org.apache.jena.reasoner.rulesys
Class Functor
- java.lang.Object
-
- org.apache.jena.reasoner.rulesys.Functor
-
- All Implemented Interfaces:
ClauseEntry
public class Functor extends java.lang.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 Summary
Fields Modifier and Type Field Description static java.util.function.Predicate<Triple>
acceptFilter
A static Predicate instance that detects triples with Functor objects
-
Constructor Summary
Constructors Constructor Description Functor(java.lang.String name, java.util.List<Node> args, Builtin impl)
ConstructorFunctor(java.lang.String name, java.util.List<Node> args, BuiltinRegistry registry)
ConstructorFunctor(java.lang.String name, Node[] args)
Constructor.Functor(java.lang.String name, Node[] args, Builtin impl)
ConstructorFunctor(java.lang.String name, Node[] args, BuiltinRegistry registry)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Equality is based on structural comparisonboolean
evalAsBodyClause(RuleContext context)
Execute the given built in as a body clause.int
getArgLength()
Return the length of the functor argument array.Node[]
getArgs()
Return the functor arguments as an array of nodesNode[]
getBoundArgs(BindingEnvironment env)
Return a new Node array containing the bound versions of this Functor's argumentsBuiltin
getImplementor()
Return the Builtin that implements this functorjava.lang.String
getName()
Return the functor nameint
hashCode()
hash function overridestatic boolean
isFunctor(Node n)
tests that a given Node represents a functorboolean
isGround()
Returns true if the functor is fully ground, no variablesboolean
isGround(BindingEnvironment env)
Returns true if the functor is fully ground in the given environmentstatic Node
makeFunctorNode(java.lang.String name, Node[] args)
Create a functor and wrap it up as a Literal nodestatic Node
makeFunctorNode(Functor f)
Wrap a functor as a Literal nodeboolean
safeEvalAsBodyClause(RuleContext context)
Execute the given built in as a body clause, only if it is side-effect-free.boolean
sameAs(java.lang.Object o)
Compare Functors, taking into account variable indices.void
setImplementor(Builtin implementor)
Set the Builtin that implements this functor.java.lang.String
toString()
Printable string describing the functor
-
-
-
Field Detail
-
acceptFilter
public static final java.util.function.Predicate<Triple> acceptFilter
A static Predicate instance that detects triples with Functor objects
-
-
Constructor Detail
-
Functor
public Functor(java.lang.String name, Node[] args)
Constructor.- Parameters:
name
- the name of the functorargs
- an array of nodes defining the arguments, this will not be copied so beware of accidental structure sharing
-
Functor
public Functor(java.lang.String name, java.util.List<Node> args, BuiltinRegistry registry)
Constructor- Parameters:
name
- the name of the functorargs
- a list of nodes defining the argumentsregistry
- a table of builtins to consult to check for implementations of this functor when used as a rule clause
-
Functor
public Functor(java.lang.String name, Node[] args, BuiltinRegistry registry)
Constructor- Parameters:
name
- the name of the functorargs
- an array of nodes defining the argumentsregistry
- a table of builtins to consult to check for implementations of this functor when used as a rule clause
-
Functor
public Functor(java.lang.String name, java.util.List<Node> args, Builtin impl)
Constructor- Parameters:
name
- the name of the functorargs
- a list of nodes defining the argumentsimpl
- a specific builtin implementation of this functor
-
-
Method Detail
-
getName
public java.lang.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 java.lang.String toString()
Printable string describing the functor- Overrides:
toString
in classjava.lang.Object
-
isFunctor
public static boolean isFunctor(Node n)
tests that a given Node represents a functor
-
equals
public boolean equals(java.lang.Object obj)
Equality is based on structural comparison- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
hash function override- Overrides:
hashCode
in classjava.lang.Object
-
sameAs
public boolean sameAs(java.lang.Object o)
Compare Functors, taking into account variable indices. The equality function ignores differences between variables.- Specified by:
sameAs
in interfaceClauseEntry
-
makeFunctorNode
public static Node makeFunctorNode(java.lang.String name, Node[] args)
Create a functor and wrap it up as a Literal node- Parameters:
name
- the name of the functorargs
- an array of nodes defining the arguments, this will not be copied so beware of accidental structure sharing
-
-