A containerised Fuseki configurable and loaded with data.
Build parameters:
config: Fuseki config (config.ttland the files it imports, such astext-indexing.ttlfor full-text search andspatial-indexing.ttlfor GeoSPARQL),full-text-search-defaults.ru(the properties searched by full-text queries that name no property; empty for none), log4j2 properties and the optionalreasoner.ttl(defaults toconfig). Whenreasoner.ttlis present, the default graph is run through its reasoner (OWL Micro by default) at build time and the inferred triples are stored with it, so queries don't pay for reasoning. Named graphs are stored as loaded, without inference. Without it, the data is served as loaded;data: Location of the RDF files to load, searched recursively (defaults todata). Files ending in.ttl,.nt,.nq,.trig,.rdf,.owlor.jsonld, optionally gzipped, are loaded; anything else is ignored.
docker build --file Containerfile --tag triplestore .To use other folders, pass them as build contexts:
docker build --file Containerfile --build-context config=path/to/config --build-context data=path/to/data --tag triplestore .For example, to load the volunteering data ontology (add --branch <tag or branch> to the clone to load another version than the default branch):
git clone --depth 1 https://github.com/volunteeringdata/ontology.git data/volunteeringdata/ontology
docker build --file Containerfile --tag triplestore .The reasoner holds its inferences in memory and gets 75% of the build container's memory by default. To set its heap explicitly, pass JVM options as a build argument:
docker build --file Containerfile --build-arg INFERENCE_JAVA_OPTIONS=-Xmx8g --tag triplestore .Podman finds the Containerfile without --file and accepts the same options.
To build for several platforms, pass them with --platform. Data loading, inference and indexing run once, natively on the build machine, as their output is the same on every platform: only the final image is built for each platform. Docker needs a builder that supports multi-platform images (the containerd image store, or docker buildx create) and emulation for platforms other than the build machine's (QEMU, included in Docker Desktop):
docker build --file Containerfile --platform linux/amd64,linux/arm64 --tag triplestore .Podman builds them into a manifest list:
podman build --platform linux/amd64,linux/arm64 --manifest triplestore .docker run --rm -p 3030:3030 triplestoreSPARQL endpoint accessible at http://localhost:3030/sparql.
The server is read-only and exposes only the endpoints defined in config.ttl: /sparql (SPARQL query) and /graph (Graph Store Protocol, read).
Example requests:
- Get all statements
CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o } LIMIT 100 - Get the vocabulary
CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o ; <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <https://example.org/ns/> . }
Queries can search text with Jena text. The text index is built with the image, from the properties mapped in text-indexing.ttl: RDFS, SKOS, Dublin Core (elements 1.1 and terms) and schema.org (https://schema.org/) labels, names, titles and descriptions. Search is case and accent insensitive ("elan" matches "Élan"). Labels, names and titles match singular and plural forms ("example" matches "Examples"); descriptions also match other word forms ("volunteer" matches "Volunteering").
PREFIX text: <http://jena.apache.org/text#>
PREFIX fts: <urn:triple-store:text-index:>
SELECT ?s ?score ?literal WHERE {
(?s ?score ?literal) text:query (fts:labels "example") .
}
ORDER BY DESC(?score)What to search:
?s text:query "example": the default search, which covers the properties declared infull-text-search-defaults.ru(rdfs:labelandrdfs:commentby default);?s text:query (rdfs:label "example"): one property;?s text:query (fts:labels "example"): all labels, names and titles;?s text:query (fts:descriptions "example"): all descriptions;?s text:query (fts:skos "example"): SKOS labels and definitions.
The search string uses Lucene query syntax: wildcards ("volunt*"), phrases ('"open data"'), AND/OR/NOT, and fuzzy matches ("bicycel~").
After the search string, the list can take:
- a maximum number of results:
(fts:labels "example" 10); - a language:
(rdfs:label "example" "lang:en")only matches literals tagged@en, and uses Lucene's analyzer for that language. Unlike other searches, it doesn't fold accents:(skos:altLabel "velo" "lang:fr")doesn't match "vélo"@fr, but"vélo"does. Leave outlang:to match without accents; - highlighting:
(rdfs:comment "volunteer" "highlight:")returns?literalwith the matches marked:↦Volunteering↤ opportunities.
(?s ?score ?literal) text:query (…) also returns each match's relevance score and the matching text. A subject is returned once for each value that matches: use SELECT DISTINCT ?s to get each subject once.
Searches respect graphs: outside GRAPH, they only match values in the default graph; inside GRAPH <g> { … } or GRAPH ?g { … }, only values in that named graph.
Queries can use GeoSPARQL. The spatial index is built with the image, from the geometries in the data (geo:asWKT or geo:asGML literals of features linked by geo:hasGeometry). For example, features within 10 km of a point:
PREFIX spatial: <http://jena.apache.org/spatial#>
SELECT ?feature WHERE { ?feature spatial:nearby (51.5072 -0.1276 10 <http://www.opengis.net/def/uom/OGC/1.0/kilometre>) }To turn spatial indexing off, remove the import of spatial-indexing.ttl from config.ttl and point text:dataset at the store, as the comment there shows.
The workflow .github/workflows/CD.yml builds the image for linux/amd64 and linux/arm64 and pushes it tagged latest, on each push to main and when run manually.
The public repositories whose RDF files are loaded, at any depth, are the entries of the data job's matrix, each with an optional ref (tag, branch or commit SHA; the default branch if omitted):
include:
- repository: volunteeringdata/ontology
ref: v0.1.0
- repository: theodi/dataEach repository is checked out in its own job, including files stored with Git LFS, and the image is built with them as its data build context, in place of this repository's example data folder.
Changes to the data are made to this list, so they are reviewed in pull requests and published when merged. Pin a ref to publish a known version of a repository; without one, its latest default branch is loaded on each publish. To load several versions of a repository, list it once per ref: each version is loaded from its own folder.
The registries to push to are the entries of the publish job's matrix, each with a registry host, an image name, and a username (or the name of the secret holding it) and the name of the secret holding the password or token. It pushes to GitHub Container Registry with the workflow's GITHUB_TOKEN by default.