Rdf.GraphSourceGraph 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");
...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.
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.
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;copy : unit -> graph;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.
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.
to_list g t builds of list by following Rdf_.first and Rdf_.rest nodes in g, starting from term t.
add_list g l adds blank nodes and triples to insert the given list into the graph, returning the blank node at the head of the list.
types_of g sub is a shorthand for iri_objects_of g ~sub ~pred:Rdf_.type_.
root_opt g returns the first root term found in the graph, i.e. a node present in the graph which does not appear as object of a triple. If there are more than one root node, only the first one is returned. If the search falls into a cycle, a node of the cycle is returned. If the graph is empty, None is returned.
Same as root_opt but in case no root is found, return the name of the graph.
type diff = | Cardinals of int * int| Missing_triple of Term.triple| Extra_triple of Term.tripleDifferences when checking if two graphs are isomorphic.
Return None when the two given graphs are isomorphic or the first difference.
copy_from ?keep g term returns a new graph with the same name as g, keeping only triples reachable from term, and only following blank nodes or IRIs when keep iri returns true, i.e. when an IRI is encountered, we do not add triples with this IRI as subject if keep iri returns false. Default keep always returns false. The new graph is created in memory (no options passed).