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


(->Quad s p o c)

Positional factory function for class grafter.rdf.protocols.Quad.


(->Triple s p o)

Constructs a Quad with a nil graph (context).


(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.

Depending on the target, this function will also write any prefixes associated with the rdf-serialiser to the target.

Returns target.


(add-batched target triples)(add-batched target graph-or-triples triples-or-batch-size)(add-batched target graph triples batch-size)

Adds a collection of statements to a repository in batches. The batch size is optional and default-batch-size will be used if not specified. Some repository implementations cache added statements in memory until explicitly flushed which can cause out-of-memory errors if a large number of statements are added through add. Spliting the input sequence into batches limits the number of cached statements and therefore can reduce memory pressure.


(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 statement)

Return the RDF context from a statement.


FIXME: write docs


(delete target quads)(delete target graph triples)

Deletes a sequence of statements from the specified repository.

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

Returns target.


(delete-batched target quads)(delete-batched target graph-or-quads triples-or-batch-size)(delete-batched target graph triples batch-size)

Deletes a collection of statements from a repository in batches. The batch size is optional and default-batch-size will be used if not specified.


(language s lang)

Create an RDF langauge string out of a value string and a given language tag. Language tags should be keywords representing the country code, e.g.

(language “Bonsoir” :fr)


(literal val datatype-uri)

You can use this to declare an RDF typed literal value along with its URI. Note that there are implicit coercions already defined for many core clojure/java datatypes, so for common datatypes you shounld’t need this.


(object statement)

Return the RDF object from a statement.


(predicate statement)

Return the RDF predicate from a statement.


(statements this & {:keys [format buffer-size base-uri], :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.

The :base-uri option can be supplied to automatically re@base URI’s on a new prefix when reading.


(subject statement)

Return the RDF subject from a statement.


(triple= & quads)

Equality test for an RDF triple or quad, that checks whether the supplied RDF statements are equal in terms of RDFs semantics i.e. two quads will be equal regardless of their graph/context providing their subject, predicate and objects are equal.

Like clojure.core/= this function can be applied to any number of statements.


(triple? t)

Predicate function to test if object is a valid RDF triple.