Knora provides an API for parsing and formatting RDF data and for working with RDF graphs. This allows Knora developers to use a single, idiomatic Scala API as a façade for a Java RDF library. By using a feature toggle, you can choose either Jena or RDF4J as the underlying implementation.
The API is in the package org.knora.webapi.messages.util.rdf
. It includes:
-
RdfModel
, which represents a set of RDF graphs (a default graph and/or one or more named graphs). A model can be constructed from scratch, modified, and searched. -
RdfNode
and its subclasses, which represent RDF nodes (IRIs, blank nodes, and literals). -
Statement
, which represents a triple or quad. -
RdfNodeFactory
, which creates nodes and statements. -
RdfModelFactory
, which creates empty RDF models. -
RdfFormatUtil
, which parses and formats RDF models. -
JsonLDUtil
, which provides specialised functionality for working with RDF in JSON-LD format, and for converting between RDF models and JSON-LD documents.RdfFormatUtil
usesJsonLDUtil
when appropriate.
To work with RDF models, start with RdfFeatureFactory
, which returns instances
of RdfNodeFactory
, RdfModelFactory
, and RdfFormatUtil
, using feature toggle
configuration.
JsonLDUtil
does not need a feature factory.
-
The Jena-based implementation, in package
org.knora.webapi.messages.util.rdf.jenaimpl
. -
The RDF4J-based implementation, in package
org.knora.webapi.messages.util.rdf.rdf4jimpl
.
For an overview of feature toggles, see Feature Toggles.
The RDF API uses the feature toggle jena-rdf-library
:
-
on
: use the Jena implementation. -
off
(the default): use the RDF4J implementation.
The default setting is used on startup, e.g. to read ontologies from the repository. After startup, the per-request setting is used.
Before this API was added, Knora mainly used the RDF4J API directly, and still does in some places:
-
Code that uses RDF4J's streaming API to process large amounts of data, especially to avoid constructing a large string in TriG format:
-
ProjectsResponderADM.projectDataGetRequestADM
-
HttpTriplestoreConnector.turtleToTrig
-
RepositoryUpdater
-
-
The repository update plugin tests, which use SPARQL.
-
TEIHeader
: uses XSLT that depends on the exact format of the RDF/XML generated by RDF4J. The XSLT would need to be improved to handlerdf:Description
. -
GravsearchParser
: uses RDF4J's SPARQL parser. This is probably not worth changing.
-
SHACL validation.
-
SPARQL querying.
-
A streaming parsing/formatting API for processing large graphs.