Skip to content

SparqlSource

Dave Reynolds edited this page May 27, 2014 · 5 revisions

The SparqlSource notion provides wrappers to hide the slight Jena API differences between memory, local TDB and remote sources. They arrange for suitable locking/transactions to be done transparently, which means that most of the methods return memory copies of data or a stream that must be safely closed in order to close the transaction/release the lock.

SparqlSource

The core internal abstraction for RDF data sources is SparqlSource which provides methods for running select, describe and construct queries.

Implementations of SparqlSource currently provide for memory based datasets, TDB datasets and remote SPARQL endpoints (e.g. Fuseki).

ssource              = com.epimorphics.appbase.data.impl.FileSparqlSource
ssource.files        = load
ssource.textIndex    = default

configures a memory-based dataset which is initialized by reading files at app startup. The files value can be a comma separated list of file names, all of which will be loaded into a single combined model. If any file name is a directory then all RDF files (files with suffix ttl, rdf, owl, nt, n3 or xml) in that directory will be loaded.

The textIndex parameter is optional. If present then an in-memory Lucene index will be built to support jena-text free text queries. If its value is "default" then a text index over rdfs:label will be created. Otherwise it should be a comma-separated list of properties to be indexed (which can be curies using the app's prefix settings).

rsource              = com.epimorphics.appbase.data.impl.RemoteSparqlSource
rsource.endpoint     = http://localhost:3030/test/query

configures access to a remote SPARQL endpoint at the given URL.

tsource              = com.epimorphics.appbase.data.impl.TDBSparqlSource
tsource.location     = /home/der/projects/data/test/tdb
tsource.index        = /home/der/projects/data/test/text

configures a local TDB data store with optional jena-text index.

Update access to SparqlSources

SparqlSources also support update (update(UpdateRequest)) if isUpdateable() is true.

A DatasetAccessor for graph level update may be available through getAccessor() but read-only sources will return null for this.

The update handler and/or accessor will perform the necessary wrapping to handle the type of sources. So for in-memory sources locking is done, for TDB sources the accessor supports transactions, for remote sources a remote accessor or used.

Method summary

See Javadoc for definitive versions:

Method Meaning
select(String query) Selector query, in-memory result set returned
streamableSelect(String query) Streamable query, keeps read transaction/lock open, must be safely closed
selectVar(String query, String varname, Class<T> cls) Query for set of Literal, Resource or RDFNode values for a single variable
describe(String query) General describe query
describeAll(String... uris) Fetch a description of a set of resources
describeEach(String... uris) Fetch a description of each of a set of resources seperately
construct(String query) Construct query
isUpdateable() Return true of the source supports update
update(UpdateRequest update) Perform a sparql update
getAccessor() Return a dataset accessor for graph level update to this source
getPrefixes() Return a set of prefix mappings to use with this source. By default these will be app wide mappings specified by a PrefixService but specific sources may override that

Clone this wiki locally