Package ai.chatur.cortex.core.jena
Class Sparql
java.lang.Object
ai.chatur.cortex.core.jena.Sparql
Runs a
Query against a Dataset inside a read transaction.
Every query runs in its own QueryExecution, opened and closed around a single read
transaction on the dataset: forEachSolution(java.util.function.Consumer<org.apache.jena.query.QuerySolution>) for queries whose results are accumulated
into a value the caller already holds, execute(java.util.function.Function<org.apache.jena.query.QueryExecution, T>) for anything that needs the QueryExecution itself — to distinguish SELECT/ASK/DESCRIBE, for
instance. QuerySolutions are only valid while the execution is open, so neither method
lets one escape the transaction.
-
Method Summary
Modifier and TypeMethodDescriptionBinds a variable of the query to a value.<T> TRuns the query, applying the mapper to the execution inside the transaction.voidforEachSolution(Consumer<org.apache.jena.query.QuerySolution> action) Runs the query as aSELECT, applying the action to each solution inside the transaction.static Sparqlon(org.apache.jena.query.Dataset dataset, org.apache.jena.query.Query query) Prepares the query to run against the dataset.
-
Method Details
-
on
Prepares the query to run against the dataset.- Parameters:
dataset- the dataset to queryquery- the query to run- Returns:
- the prepared query, ready to bind variables and run
-
bind
Binds a variable of the query to a value.- Parameters:
var- the name of the variable, without the leading?value- the value to substitute- Returns:
- this query, for chaining
-
forEachSolution
Runs the query as aSELECT, applying the action to each solution inside the transaction.- Parameters:
action- applied to every solution in order, while the query execution is still open
-
execute
Runs the query, applying the mapper to the execution inside the transaction.- Type Parameters:
T- the type of the result- Parameters:
mapper- computes the result from the query execution, while it is still open- Returns:
- the value the mapper computed
-