package rdf

  1. Overview
  2. Docs
OCaml library to manipulate RDF graphs; implements SPARQL

Install

Dune Dependency

Authors

Maintainers

Sources

ocaml-rdf-0.14.0.tar.gz
md5=430a2d24537cac2d48b0c5f5a51794b8
sha512=8f6d0416477890716bf7e9179fca971fc55b0f0cb75972d0d485cb8700361f4fba627a512f123615ef722bdaa5e694ccf84d58497d238067b94269ab99c48264

doc/rdf/Rdf/Sparql/index.html

Module Rdf.SparqlSource

Sparql queries.

Error handling

Sourcetype error =
  1. | Parse_error of Loc.loc * string
  2. | Value_error of Dt.error
  3. | Eval_error of Sparql_eval.error
  4. | Algebra_error of Sparql_algebra.error
  5. | Not_select
  6. | Not_ask
  7. | Not_construct
  8. | Not_describe
  9. | Not_get
  10. | Not_update
  11. | Not_implemented of string
Sourceexception Error of error
Sourceval string_of_error : error -> string

Parsing and printing Sparql queries

Sourceval query_from_string : string -> query
Sourceval query_from_file : string -> query
Sourceval string_of_query : query -> string

Executing queries

Solutions

Sourcetype solution
Sourceval get_term : solution -> string -> Term.term

get_term solution varname returns the Term.term bound to varname in the solution.

  • raises Not_found

    if the variable is not bound.

Sourceval is_bound : solution -> string -> bool

is_bound solution varname returns whether the given variable name is bound in the solution.

Sourceval solution_fold : (string -> Term.term -> '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.

Sourceval solution_iter : (string -> Term.term -> unit) -> solution -> unit

solution_iter f solution calls f on each pair (varname, term) of the solution.

Convenient functions to access solution bindings.

All these functions can raise Dt.Error exceptions in case the term bounded to the variable name is not compatible with the asked type.

The functions are just calls to Dt functions. For example, get_int retrieve the bounded term with get_term, then calls Dt.of_term to get a Dt.value, than calls Dt.int to retrieve an Int n value, then return n.

Sourceval get_string : solution -> string -> string
Sourceval get_iri : solution -> Iri.t -> string -> Iri.t

See comment of Dt.iri.

Sourceval get_int : solution -> string -> int
Sourceval get_float : solution -> string -> float
Sourceval get_bool : solution -> string -> bool
Sourceval get_datetime : solution -> string -> Term.datetime
Sourceval get_ltrl : solution -> string -> string * string option

Same as get_string but the associated language tag is kep, if any.

Querying

Sourcetype query_result =
  1. | Bool of bool
  2. | Solutions of solution list
  3. | Graph of Graph.graph
Sourceval execute : ?graph:Graph.graph -> base:Iri.t -> Ds.dataset -> query -> query_result

execute ~base dataset q executes the sparql query q on dataset, using base as base iri. The form of the result depends on the kind of query:

  • Select queries return a Solution solutions
  • Ask queries return a Bool bool
  • Construct queries return Graph g.
  • Describe queries return a description graph.

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 iri is the base iri provided.

Warning: Describe queries are not implemented yet.

  • raises Error

    in case of error.

Sourceval execute_update : graph:Graph.graph -> query -> query_result

Convenient functions for querying

Sourceval select : base:Iri.t -> Ds.dataset -> query -> solution list

Execute the given SELECT query.

Sourceval construct : ?graph:Graph.graph -> base:Iri.t -> Ds.dataset -> query -> Graph.graph

Execute the given CONSTRUCT query.

Sourceval ask : base:Iri.t -> Ds.dataset -> query -> bool

Execute the given ASK query.

  • raises Not_ask

    is the query is not a ASK.

Sourceval describe : ?graph:Graph.graph -> base:Iri.t -> Ds.dataset -> query -> Graph.graph

Execute the given DESCRIBE query.

Predefined functions

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

Sourcetype iri_fun = Dt.value list -> Dt.value

A function takes a list of values and returns a value.

Sourceval iri_funs : unit -> iri_fun Iri.Map.t
Sourceval add_iri_fun : Iri.t -> iri_fun -> unit
OCaml

Innovation. Community. Security.