Module Rdf_sparql

module Rdf_sparql: sig .. end
Sparql queries.


Error handling


type error = 
| Parse_error of Rdf_loc.loc * string
| Value_error of Rdf_dt.error
| Eval_error of Rdf_sparql_eval.error
| Algebra_error of Rdf_sparql_algebra.error
| Not_select
| Not_ask
| Not_construct
| Not_describe
exception Error of error
val string_of_error : error -> string

Parsing and printing Sparql queries


type query = Rdf_sparql_types.query 
val parse_from_string : string -> query
val parse_from_file : string -> query
val string_of_query : query -> string

Executing queries



Solutions


type solution 
val get_term : solution -> string -> Rdf_node.node
get_term solution varname returns the Rdf_node.node bound to varname in the solution.
Raises Not_found if the variable is not bound.
val is_bound : solution -> string -> bool
is_bound solution varname returns whether the given variable name is bound in the solution.
val solution_fold : (string -> Rdf_node.node -> 'a -> 'a) -> solution -> 'a -> 'a
solution_fold f sol acc is f var1 term1 (f var2 term2 (...) acc), folding over the bindings of the solution.
val solution_iter : (string -> Rdf_node.node -> unit) -> solution -> unit
solution_iter f solution calls f on each pair (varname, term) of the solution.

Querying


type query_result = 
| Bool of bool
| Solutions of solution list
| Graph of Rdf_graph.graph
val execute : ?graph:Rdf_graph.graph ->
base:Rdf_uri.uri ->
Rdf_ds.dataset -> query -> query_result
execute ~base dataset q executes the sparql query q on dataset, using base as base uri. The form of the result depends on the kind of query: For Construct and Describe queries, if a graph is provided, it is filled and the same graph is returned; else a new graph (in memory) is created, filled and returned. If the graph is created, it uri is the base uri provided.

Warning: Describe queries are not implemented yet.
Raises Error in case of error.


Convenient functions for querying


val select : base:Rdf_uri.uri ->
Rdf_ds.dataset -> query -> solution list
Execute the given SELECT query.
Raises Not_select is the query is not a SELECT.
val construct : ?graph:Rdf_graph.graph ->
base:Rdf_uri.uri -> Rdf_ds.dataset -> query -> Rdf_graph.graph
Execute the given CONSTRUCT query.
Raises Not_construct is the query is not a CONSTRUCT.
val ask : base:Rdf_uri.uri -> Rdf_ds.dataset -> query -> bool
Execute the given ASK query.
Raises Not_ask is the query is not a ASK.
val describe : ?graph:Rdf_graph.graph ->
base:Rdf_uri.uri -> Rdf_ds.dataset -> query -> Rdf_graph.graph
Execute the given DESCRIBE query.
Raises Not_describe is the query is not a DESCRIBE.

Predefined functions

These are the functions named by an URI, see details here.

type uri_fun = Rdf_dt.value list -> Rdf_dt.value 
A function takes a list of values and return a value.
val uri_funs : unit -> uri_fun Rdf_uri.Urimap.t
val add_uri_fun : Rdf_uri.uri -> uri_fun -> unit