grafter.rdf.sesame

Grafter support and wrappers for RDF processing, built on top of
the Sesame API (http://www.openrdf.org/).

->connection

(->connection repo)
Given a sesame repository return a connection to it.

filename->rdf-format

(filename->rdf-format fname)
Given a filename we attempt to return an appropriate RDFFormat
object based on the files extension.

http-repo

(http-repo repo-url)
Given a URL as a String return a Sesame HTTPRepository for e.g.
interacting with the OpenRDF Workbench.

IQueryEvaluator

protocol

members

evaluate

(evaluate this)
Low level protocol to evaluate a sesame RDF Query
object, and convert the results into a grafter representation.

ISesameRDFConverter

protocol

members

->sesame-rdf-type

(->sesame-rdf-type this)
Convert a native type into a Sesame RDF Type

sesame-rdf-type->type

(sesame-rdf-type->type this)
Convert a Sesame RDF Type into a Native Type

ISPARQLable

protocol

NOTE this protocol is intended for low-level access.  End users
should use query instead.

Run an arbitrary SPARQL query.  Works with ASK, DESCRIBE, CONSTRUCT
and SELECT queries.

You can call this on a Repository however if you do you may in some
cases cause a resource leak, for example if the sequence of results
isn't fully consumed.

To use this without leaking resources it is recommended that you
call ->connection on your repository, inside a with-open; and then
consume all your results inside of a nested doseq/dorun/etc...

e.g.

(with-open [conn (->connection repo)]
   (doseq [res (query conn "SELECT * WHERE { ?s ?p ?o .}")]
      (println res)))

members

query-dataset

(query-dataset this sparql-string model)

update!

(update! this sparql-string)

IStatement->sesame-statement

(IStatement->sesame-statement is)
Convert a grafter IStatement into a Sesame statement.

literal-datatype->type

multimethod

A multimethod to convert an RDF literal into a corresponding
Clojure type.  This method can be extended to provide custom
conversions.

load-rdf

(load-rdf connection file base-uri-str format)
Loads the specified RDF file into the supplied repository.

Takes a String or File (specifying a path to an RDF file) a base-uri
String and an RDFFormat.

make-restricted-dataset

(make-restricted-dataset & {:as options})
Build a dataset to act as a graph restriction.  You can specify for
both :default-graph and :named-graphs.  Both of which take sequences
of URI strings.

memory-store

(memory-store)
Instantiate a sesame RDF MemoryStore.

mimetype->rdf-format

(mimetype->rdf-format mime-type)
Given a mimetype string we attempt to return an appropriate
RDFFormat object based on the files extension.

native-store

(native-store datadir)(native-store datadir indexes)
Instantiate a sesame RDF NativeStore.

prepare-query

(prepare-query repo sparql-string)(prepare-query repo sparql-string dataset)
Low level function to prepare (parse, but not process) a sesame RDF
query.  Takes a repository a query string and an optional sesame
Dataset to act as a query restriction.

Prepared queries still need to be evaluated with evaluate.

prepare-update

(prepare-update repo sparql-update-str)(prepare-update repo sparql-update-str dataset)
Prepare (parse but don't process) a SPARQL update request.

Prepared updates still need to be evaluated with evaluate.

query

(query repo sparql & {:as options})
Run an arbitrary SPARQL query.  Works with ASK, DESCRIBE, CONSTRUCT
and SELECT queries.

You can call this on a Repository however if you do you may in some
cases cause a resource leak, for example if the sequence of results
isn't fully consumed.

To use this without leaking resources it is recommended that you
call ->connection on your repository, inside a with-open; and then
consume all your results inside of a nested doseq/dorun/etc...

e.g.

(with-open [conn (->connection repo)]
   (doseq [res (query conn "SELECT * WHERE { ?s ?p ?o .}")]
      (println res)))


Takes a repo and sparql string and an optional set of k/v argument
pairs, and executes the sparql query on the repository.

Options are:

:default-graph a seq of URI strings representing named graphs to be set
               as the default union graph for the query.

:named-graphs a seq of URI strings representing the named graphs in
to be used in the query.

If no options are passed then we use the default of no graph
restrictions whilst the union graph is the union of all graphs.

rdf-serializer

(rdf-serializer destination & {:keys [append format encoding], :or {append false, encoding "UTF-8"}})
Coerces destination into an java.io.Writer using
clojure.java.io/writer and returns an RDFSerializer.

Accepts also the following optional options:

:append          If set to true it will append new values to the end of
                 the file destination (default: false).

:format          If a String or a File are provided the format parameter
                 can be optional (in which case it will be infered from
                 the file extension).  This should be a sesame RDFFormat
                 object.

:encoding        The character encoding to be used (default: UTF-8)

repo

(repo)(repo store)
Given a sesame Store of some type, return a sesame SailRepository.

resource-array

(resource-array & rs)
FIXME: write docs

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.

sesame-statement->IStatement

(sesame-statement->IStatement st)
Convert a sesame Statement into a grafter Quad.

shutdown

(shutdown repo)
Cleanly shutsdown the repository.

sparql-repo

(sparql-repo query-url)(sparql-repo query-url update-url)
Given a query-url and an optional update-url String return a Sesame
SPARQLRepository for communicating with remote repositories.

with-transaction

macro

(with-transaction repo & forms)
Wraps the given forms in a transaction on the supplied repository.
Exceptions are rolled back on failure.