grafter.rdf

Functions and macros for creating RDF data.  Includes a small
DSL for creating turtle-like templated forms.

add

(add target triples)(add target graph triples)(add target graph format triple-stream)(add target graph base-uri format triple-stream)
Adds a sequence of statements to the specified datasink.  Supports
all the same targets as add-statement.

Takes an optional string/URI to use as a graph.

add-properties

(add-properties triple-template hash-map)
Appends the key/value pairs from the supplied hash-map into the
triple-template form.  Assumes it is given a vector representing a
single subject.

add-statement

(add-statement target statement)(add-statement target graph statement)
Add an RDF statement to the target datasink.  Datasinks must
implement grafter.rdf.protocols/ITripleWriteable.

Datasinks include sesame RDF repositories, connections and anything
built by rdf-serializer.

Takes an optional string/URI to use as a graph.

context

(context statement)
Return the RDF context from a statement.

format-rdf-jsonld

FIXME: write docs

format-rdf-n3

FIXME: write docs

format-rdf-nquads

FIXME: write docs

format-rdf-ntriples

FIXME: write docs

format-rdf-trig

FIXME: write docs

format-rdf-trix

FIXME: write docs

format-rdf-turtle

FIXME: write docs

format-rdf-xml

FIXME: write docs

graph

(graph graph-uri & triples)
Takes a graph-uri and a turtle-like template of vectors and returns
a lazy-sequence of quad Statements.  A turtle-like template should
be structured like this:

[subject [predicate1 object1]
         [predicate2 object2]
         [predicate3 [[blank-node-predicate blank-node-object]]]]

Subjects, predicates and objects can be strings, URI's or URL's,
whilst objects can also be literal types such as java numeric types,
Dates etc.

For convenience strings in these templates are assumed to be URI's
and are cast as such, as URI's are the most common type in linked
data.  If you want an RDF string you should use the s function to
build one.

graph-fn

macro

(graph-fn [row-bindings] & forms)
A macro that defines an anonymous function to convert a tabular
dataset into a graph of RDF quads.  Ultimately it converts a
lazy-seq of rows inside a dataset, into a lazy-seq of RDF
Statements.

The function body should be composed of any number of forms, each of
which should return a sequence of RDF quads.  These will then be
concatenated together into a flattened lazy-seq of RDF statements.

Rows are passed to the function one at a time as hash-maps, which
can be destructured via Clojure's standard destructuring syntax.

Additionally destructuring can be done on row-indicies (when a
vector form is supplied) or column names (when a hash-map form is
supplied).

object

(object statement)
Return the RDF object from a statement.

predicate

(predicate statement)
Return the RDF predicate from a statement.

prefixer

(prefixer uri-prefix)
Takes the base prefix of a URI string and returns a function that
concatenates its argument onto the end of it e.g.
((prefixer "http://example.org/") "foo") ;; => "http://example.org/foo";

quad

(quad graph triple)
Build a quad from a graph and a grafter.rdf.protocols/Triple.

s

(s str)(s str lang-or-uri)
Cast a string to an RDF literal.  The second optional argument can
either be a keyword corresponding to an RDF language tag
e.g. :en, :en-gb, or :fr or a string or URI in which case it is
assumed to be a URI identifying the RDF type of the literal.

statements

(statements this & {:keys [format buffer-size], :as options})
Attempts to coerce an arbitrary source of RDF statements into a
sequence of grafter Statements.

If the source is a quad store quads from all the named graphs will
be returned.  Any triples in an unnamed graph will be ignored.

Takes optional parameters which may be used depending on the
context e.g. specifiying the format of the source triples.

The :format option is supplied by the wrapping function and may be
nil, or act as an indicator about the format of the triples to read.
Implementers can choose whether or not to ignore or require the
format parameter.

The :buffer-size option can be used to configure the buffer size at
which statements are parsed from an RDF stream.  Its default value
of 32 was found to work well in practice, and also aligns with chunk
size of Clojure's lazy sequences.

subject

(subject statement)
Return the RDF subject from a statement.

triplify

(triplify & subjects)
Takes many turtle like structures and converts them to a lazy-seq
of grafter.rdf.protocols.IStatement's.  Users should generally tend
to prefer to using graph to triplify.