OCaml library to manipulate RDF graphs; implements SPARQL
Module Rdf . Xml
exception Invalid_rdf of string
module SMap : Map.S with type key = string
type tree =
| E of Xmlm.tag * tree list
| D of string

The type of XML tree walked through to fill the graph.

val xml_of_string : string -> tree
  • raises Failure

    in case of invalid XML.

val get_first_child : tree -> (string * string) -> tree option

get_first tree tag returns the first child with tag s of the given xml tree or None if the given node has no such child.

type state = {
subject : Term.term option;
predicate : Iri.t option;
xml_base : Iri.t;
xml_lang : string option;
datatype : Iri.t option;
namespaces : string Iri.Map.t;

Type of current state when walking through the xml tree.

type global_state = {
blanks : Term.blank_id SMap.t;
gnamespaces : string Iri.Map.t;

Global state of the analysis.

val get_blank_node : Graph.graph -> global_state -> SMap.key -> Term.term * global_state
val input_node : Graph.graph -> state -> global_state -> tree -> global_state
val input_prop : Graph.graph -> state -> (global_state * int) -> tree -> global_state * int

Fill a graph from a current state, a pair (global state, li counter), and a property node.

val from_string : Graph.graph -> ?base:Iri.t -> string -> unit

Input graph from string. Default base is the graph name.

val from_file : Graph.graph -> ?base:Iri.t -> string -> unit

Same as from_string but read from the given file.

val from_input : Graph.graph -> ?base:Iri.t -> Xmlm.input -> unit

Same as from_string but read from the given Xmlm.input handle.

val from_xml : Graph.graph -> ?base:Iri.t -> tree -> unit

Same as from_string but read from the given Xml tree.

val to_string : ?compact:bool -> ?namespaces:(Iri.t * string) list -> Graph.graph -> string

Return a RDF/XML representation of the graph in a string.

  • parameter compact

    Default is true. If true and if the graph storage allows it, the returned XML is more compact, with only one node for each subject appearing in the graph triples.

val to_file : ?compact:bool -> ?namespaces:(Iri.t * string) list -> Graph.graph -> string -> unit

Same as to_string but writes to the given file.