diff --git a/lib/src/sparql/mod.rs b/lib/src/sparql/mod.rs index 6420e944..b1071a60 100644 --- a/lib/src/sparql/mod.rs +++ b/lib/src/sparql/mod.rs @@ -185,7 +185,28 @@ impl ServiceHandler for EmptyServiceHandler { } } + +/// Handler for custom functions. +/// +/// For example, the following query uses a custom function to reverse a string: +/// +///```sparql +/// PREFIX ex: +/// PREFIX foaf: +/// SELECT ?name ?reverse +/// WHERE +/// { +/// ?s foaf:name ?name . +/// BIND(ex:REVERSE(?name) as ?reverse) +/// } +/// ``` pub trait CustomFunctionsHandler { + /// Handles all custom functions for a given query + /// + /// For the example above node would have the value http://example.com#REVERSE + /// and would recieve one parameter with the value mapped to ?name + /// + /// Returns `None` if there is an error or the given NamedNode isn't recognized fn handle(&self, node: &NamedNode, parameters: &Vec>) -> Option; } diff --git a/lib/tests/custom_functions_test_cases.rs b/lib/tests/custom_functions_test_cases.rs index 8c9d8374..c12eeb0e 100644 --- a/lib/tests/custom_functions_test_cases.rs +++ b/lib/tests/custom_functions_test_cases.rs @@ -30,10 +30,11 @@ fn simple_custom_function_test() { let query = r#" PREFIX ex: + PREFIX foaf: SELECT ?name ?reverse WHERE { - ?s ?name . + ?s foaf:name ?name . BIND(ex:REVERSE(?name) as ?reverse) } ORDER BY ?name