package rdf
Install
Dune Dependency
Authors
Maintainers
Sources
md5=98a004fb30bb175b9b50cbe99f48f15e
sha512=ffc1a0e67683773294d73d0dfa6aa32a046e5bcdc54c9879c16fd375a0d8269048a5600f91dd9af7af981214d1704fb86ce8713cfeba042d11ebae5457ed2ee5
doc/rdf/Rdf/Graph/index.html
Module Rdf.Graph
Source
Graph abstraction.
The graph provides an abstraction of the storage used (memory, database, ...). The graph is modified in place.
Example of usage:
let options =
[
"storage", "mysql" ;
"database", "mydb";
"user", "john" ;
]
in
let graph = Graph.open_graph ~options (Iri.iri "http://hello.fr") in
graph.add_triple
~sub: (Term.term_of_iri_string "http://john.net")
~pred: (Iri.iri "http://relations.org/hasMailbox")
~obj: (Term.term_of_literal_string "john\@john.net");
...
Options
get_options name options
returns the value associated to the option with the given name, in option list. If the option name is not found in the list, the function raises the Failure
exception with a message about the missing option.
Creating storages
This is useful only to create your own storage.
Interface to query Basic Graph Patterns (BGP) in a graph. Here the term representation is abstracted, so that it can be for example an id in a database table, which will make triple matching and joining faster when matching a BGP by querying the real terms only for the result of the whole BGP, instead of retrieving terms and joining results of each triple.
This is the exception raised by the module we get when applying Make
on a storage.
Each call to a Storage
function is embedded so that the Storage_error
exception is raised when an error occurs in a storage function. The exception provides the name of the storage, the error message (obtained with Storage.string_of_error
) and the original exception.
Refer to the documentation of Storage
for information about the functions provided by the resulting module.
Registering storages
type graph = {
name : unit -> Iri.t;
size : unit -> int;
add_triple : sub:Term.term -> pred:Iri.t -> obj:Term.term -> unit;
rem_triple : sub:Term.term -> pred:Iri.t -> obj:Term.term -> unit;
add_triple_t : Term.triple -> unit;
rem_triple_t : Term.triple -> unit;
subjects_of : pred:Iri.t -> obj:Term.term -> Term.term list;
predicates_of : sub:Term.term -> obj:Term.term -> Iri.t list;
objects_of : sub:Term.term -> pred:Iri.t -> Term.term list;
find : ?sub:Term.term -> ?pred:Iri.t -> ?obj:Term.term -> unit -> Term.triple list;
exists : ?sub:Term.term -> ?pred:Iri.t -> ?obj:Term.term -> unit -> bool;
exists_t : Term.triple -> bool;
subjects : unit -> Term.term list;
predicates : unit -> Iri.t list;
objects : unit -> Term.term list;
folder : unit -> Term.TSet.t Iri.Map.t Term.TMap.t option;
transaction_start : unit -> unit;
transaction_commit : unit -> unit;
transaction_rollback : unit -> unit;
new_blank_id : unit -> Term.blank_id;
namespaces : unit -> (Iri.t * string) list;
add_namespace : Iri.t -> string -> unit;
rem_namespace : string -> unit;
set_namespaces : (Iri.t * string) list -> unit;
bgp : (module Bgp.S);
}
This is the structure returned by open_graph
. It contains the same functions as in Graph
, except the graph data is hidden, like in a class interface. Refer to the documentation of Storage
for information about the functions in the fields.
Graph creation
open_graph ~options iri_name
creates a new graph. The storage used is specified by the "storage" option. For example, having ("storage", "mysql")
in the options indicates to use the storage "mysql".
If the specified storage is not registered, the function raises Failure
. Other options may be used by each storage.
To make sure the storage you want to use is registered, beware of linking the corresponding module in your executable, either by using the -linkall
option or by adding a reference to the module in your code.
The "rdf"
namespace is automatically added at creation time, associated to http://www.w3.org/1999/02/22-rdf-syntax-ns#
.
merge g1 g2
add triples from g2
to g1
.