|
|
|
@ -70,7 +70,12 @@ impl<'a, S: StoreConnection + 'a> SimplePreparedQuery<S> { |
|
|
|
|
SimplePreparedQueryAction::Select { |
|
|
|
|
plan, |
|
|
|
|
variables, |
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler, options.custom_functions_handler), |
|
|
|
|
evaluator: SimpleEvaluator::new( |
|
|
|
|
dataset, |
|
|
|
|
base_iri, |
|
|
|
|
options.service_handler, |
|
|
|
|
options.custom_functions_handler, |
|
|
|
|
), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
QueryVariants::Ask { |
|
|
|
@ -81,7 +86,12 @@ impl<'a, S: StoreConnection + 'a> SimplePreparedQuery<S> { |
|
|
|
|
let (plan, _) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
|
SimplePreparedQueryAction::Ask { |
|
|
|
|
plan, |
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler, options.custom_functions_handler), |
|
|
|
|
evaluator: SimpleEvaluator::new( |
|
|
|
|
dataset, |
|
|
|
|
base_iri, |
|
|
|
|
options.service_handler, |
|
|
|
|
options.custom_functions_handler, |
|
|
|
|
), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
QueryVariants::Construct { |
|
|
|
@ -98,7 +108,12 @@ impl<'a, S: StoreConnection + 'a> SimplePreparedQuery<S> { |
|
|
|
|
&construct, |
|
|
|
|
variables, |
|
|
|
|
)?, |
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler, options.custom_functions_handler), |
|
|
|
|
evaluator: SimpleEvaluator::new( |
|
|
|
|
dataset, |
|
|
|
|
base_iri, |
|
|
|
|
options.service_handler, |
|
|
|
|
options.custom_functions_handler, |
|
|
|
|
), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
QueryVariants::Describe { |
|
|
|
@ -109,7 +124,12 @@ impl<'a, S: StoreConnection + 'a> SimplePreparedQuery<S> { |
|
|
|
|
let (plan, _) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
|
SimplePreparedQueryAction::Describe { |
|
|
|
|
plan, |
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler, options.custom_functions_handler), |
|
|
|
|
evaluator: SimpleEvaluator::new( |
|
|
|
|
dataset, |
|
|
|
|
base_iri, |
|
|
|
|
options.service_handler, |
|
|
|
|
options.custom_functions_handler, |
|
|
|
|
), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
})) |
|
|
|
@ -131,7 +151,12 @@ impl<'a, S: StoreConnection + 'a> SimplePreparedQuery<S> { |
|
|
|
|
Ok(Self(SimplePreparedQueryAction::Select { |
|
|
|
|
plan, |
|
|
|
|
variables, |
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler, options.custom_functions_handler), |
|
|
|
|
evaluator: SimpleEvaluator::new( |
|
|
|
|
dataset, |
|
|
|
|
base_iri, |
|
|
|
|
options.service_handler, |
|
|
|
|
options.custom_functions_handler, |
|
|
|
|
), |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -185,7 +210,6 @@ impl ServiceHandler for EmptyServiceHandler { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Handler for custom functions.
|
|
|
|
|
///
|
|
|
|
|
/// For example, the following query uses a custom function to reverse a string:
|
|
|
|
@ -207,14 +231,14 @@ pub trait CustomFunctionsHandler { |
|
|
|
|
/// 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<Term>>) -> Option<Term>;
|
|
|
|
|
fn handle(&self, node: &NamedNode, parameters: &[Option<Term>]) -> Option<Term>; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Default)] |
|
|
|
|
struct EmptyCustomFunctionsHandler {} |
|
|
|
|
|
|
|
|
|
impl CustomFunctionsHandler for EmptyCustomFunctionsHandler { |
|
|
|
|
fn handle(&self, _node: &NamedNode, _parameters: &Vec<Option<Term>>) -> Option<Term> { |
|
|
|
|
fn handle(&self, _node: &NamedNode, _parameters: &[Option<Term>]) -> Option<Term> { |
|
|
|
|
None |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -258,12 +282,13 @@ impl<'a> QueryOptions<'a> { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Set a CustomFunctionHandler to add your own functions
|
|
|
|
|
pub fn with_custom_functions_handler(mut self, custom_functions_handler: Box<dyn CustomFunctionsHandler>) -> Self { |
|
|
|
|
pub fn with_custom_functions_handler( |
|
|
|
|
mut self, |
|
|
|
|
custom_functions_handler: Box<dyn CustomFunctionsHandler>, |
|
|
|
|
) -> Self { |
|
|
|
|
self.custom_functions_handler = custom_functions_handler; |
|
|
|
|
self |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// A parsed [SPARQL query](https://www.w3.org/TR/sparql11-query/)
|
|
|
|
|