|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.hp.hpl.jena.sparql.function.user.UserDefinedFunctionFactory
public class UserDefinedFunctionFactory
A function factory for managing user defined functions aka function macros.
User defined functions provide a simple mechanism for a user to inject custom functions into SPARQL processing without the need to write any code. These functions essentially act as macros/aliases for another SPARQL expression and serve as a means to aid users in simplifying their SPARQL queries.
For example we can define a square function like so:
List<Var> args = new ArrayList<Var>(Var.alloc("x")); UserDefinedFunctionFactory.getFactory().add("http://example/square", "?x * ?x", args);
We can then use this in queries like so:
SELECT (<http://example/square>(3) AS ?ThreeSquared) { }
Internally the call to the square function is translated into its equivalent SPARQL expression and executed in that form.
User defined functions may rely on each other but this has some risks,
therefore the default behaviour is to not preserve these dependencies but
rather to expand the function definitions to give the resulting expression
associated with a function. Please see getPreserveDependencies()
for
more information on this.
Method Summary | |
---|---|
void |
add(String uri,
Expr e,
List<Var> args)
Adds a function |
void |
add(String uri,
String expr,
List<Var> args)
Adds a function |
void |
clear()
Clears all function definitions |
Function |
create(String uri)
Creates a function for the given URI |
UserDefinedFunctionDefinition |
get(String uri)
Gets the definition of the function (if registered) |
static UserDefinedFunctionFactory |
getFactory()
Gets the static instance of the factory |
boolean |
getPreserveDependencies()
Gets whether user defined functions may preserve dependencies on each other (default false) |
boolean |
isRegistered(String uri)
Gets whether a function with the given URI has been registered |
void |
remove(String uri)
Removes a function definition |
void |
setPreserveDependencies(boolean allow)
Sets whether user functions may explicitly depend on each other, see getPreserveDependencies() for explanation of this behavior |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static UserDefinedFunctionFactory getFactory()
public boolean getPreserveDependencies()
When this is disabled (as it is by default) function definitions are fully expanded at registration time. So if you add a function that references an existing user defined function it will be expanded to include the resulting expression rather than left with a reference to another function. This protects the user from depending on other functions whose definitions are later removed or changed.
However it may sometimes be desirable to have dependencies preserved
in which case this option may be disabled with the corresponding
setPreserveDependencies(boolean)
setter
public void setPreserveDependencies(boolean allow)
getPreserveDependencies()
for explanation of this behavior
allow
- Whether to preserve dependenciespublic Function create(String uri)
create
in interface FunctionFactory
uri
- URI
ExprBuildException
- Thrown if the given URI is not a known functionpublic void add(String uri, Expr e, List<Var> args)
uri
- URIe
- Expressionargs
- Argumentspublic void add(String uri, String expr, List<Var> args) throws ParseException
This method will build the expression to use based on the expression string given, strings must match the SPARQL expression syntax e.g.
(?x * ?y) + 5
uri
- URIexpr
- Expression String (in SPARQL syntax)args
- Arguments
ParseException
- Thrown if the expression string is not valid syntaxpublic void remove(String uri)
uri
- URI
NoSuchElementException
- Thrown if a function with the given URI does not existpublic UserDefinedFunctionDefinition get(String uri)
uri
- URI
public boolean isRegistered(String uri)
uri
- URI
public void clear()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |