Dependency Injection
RDF4J Repositories and Connections
Package rdf4j.repository
and rdf4j.repository.impl
provide an implementation of RDF4J Repository
and RepositoryConnection
API based on an underlying OntopQueryEngine
.
Specifically, interface OntopRepository
extends interface Repository
adding an httpCacheHeaders
property(which is used in the endpoint
module) and a factory method defaultRepository()
. This method takes an OntopSystemConfiguration
providing access to settings and GUICE injection facilities, which are used to obtain an OntopQueryEngine
and related beans (e.g., RDF4JInputQueryFactory
) which are then wrapped by the implementation class OntopVirtualRepository
. This class returns RDF4J connections by creating OntopRepositoryConnection
instances, which reject RDF4J manipulation methods (repository is read-only) and map RDF4J query methods to calls to a wrapped OntopConnection
.
RDF4J Queries
RDF4J RepositoryConnection
s have prepareXXXQuery
methods that return Query
(and sub-interfaces) objects with evaluate()
methods. Query
implementation classes for Ontop are provided in package rdf4j.query.impl
.
Abstract class AbstractOntopQuery
wraps the OntopConnection
used to execute the query and implement shared features for controlling query timeouts, bindings, and base IRI, while it does not support controlling datasets and inclusion of inferred statements (always enabled, cannot be changed).
Implementation classes OntopTupleQuery
, OntopGraphQuery
, and OntopBooleanQuery
extend AbstractOntopQuery
and provide implementations of RDF4J TupleQuery
, GraphQuery
and BooleanQuery
. Their evaluate()
methods obtain an OntopStatement
from the wrapped OntopConnection
, and then translate (via RDF4JInputQueryFactory
) the <query string, parsed query> pair into a matching Ontop query (i.e., SelectQuery
, ConstructQuery
, DescribeQuery
, AskQuery
) that is executed via the statement. In case of OntopTupleQuery
, the Ontop result -- a TupleResultSet
-- is wrapped in a OntopTupleQueryResult
that adapts it to the expected RDF4J result, which returns binding sets here implemented by OntopRDF4JBindingSet
.
Materialization
The rdf4j
module provides also an RDF4JMaterializer
component used by upper level modules that provides the same functionalities of OntopRDFMaterializer
but using an API compliant with the RDF4J one (e.g., Statement
instead of Assertion
).
Interface RDF4JMaterializer
is the main interface, which contains factory methods defaultMaterializer()
that instantiate implementation class DefaultRDF4JMaterializer
starting from an OntopSystemConfiguration
. This configuration is used to obtain the OntopRDFMaterializer
to which materialization is delegated to. Materialization is triggered by methods RDF4JMaterializer.materialize()
that optionally take a list of concepts (classes, properties) to materialize, and return a MaterializationGraphQuery
that allows streaming through materialized triples while monitoring materialization status.
Remarks
- method
OntopRepository.defaultRepository()
should not reference implementation classOntopVirtualRepository
(if access toOntopRepositoryConnection.reformulate()
is needed, then a connection interface including this method should be defined in therepository
package) - it is safer if
OntopVirtualRepository
tracks openOntopRepositoryConnection
s and closes them when it is closed - suggest adding default namespaces in
OntopVirtualRepository
and then inheriting/locally manipulate them inOntopRepositoryConnection
- materializing statements in a list in
OntopRepositoryConnection.getStatements()
will result in out-of-memory when trying to export all / a large amounts of statements - implementing
hasStatement()
in terms ofgetStatements()
is hugely inefficient if the latter materializes all results in a list, since it is enough to check whether a non-empty result is returned - method
OntopRepositoryConnection.getStatements()
should be implemented in terms of a tuple query to overcomeCONSTRUCT
limitations with returning named graphs (unless named graphs are not supported at all) - class
OntopGraphQuery
materializes all statements in a list with possible out-of-memory errors