Skip to content

Commit

Permalink
Add argument for media type to Qlever::query and Qlever::pinNamed
Browse files Browse the repository at this point in the history
Also: remove some debug output
  • Loading branch information
Hannah Bast committed Feb 9, 2025
1 parent 4a65bb5 commit c0b7a44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/libqlever/Qlever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void Qlever::buildIndex(QleverConfig config) {
}

// ___________________________________________________________________________
std::string Qlever::query(std::string query) {
std::string Qlever::query(std::string query, ad_utility::MediaType mediaType) {
QueryExecutionContext qec{index_, &cache_, allocator_,
sortPerformanceEstimator_, &namedQueryCache_};
auto parsedQuery = SparqlParser::parseQuery(query);
Expand Down Expand Up @@ -151,18 +151,17 @@ std::string Qlever::query(std::string query) {

ad_utility::Timer timer{ad_utility::Timer::Started};
auto responseGenerator = ExportQueryExecutionTrees::computeResult(
parsedQuery, qet, ad_utility::MediaType::sparqlJson, timer,
std::move(handle));
parsedQuery, qet, mediaType, timer, std::move(handle));
std::string result;
std::cout << "Writing the result:" << std::endl;
for (const auto& batch : responseGenerator) {
result += batch;
}
return result;
}
// ___________________________________________________________________________
// TODO<joka921> A lot of code duplication here.
void Qlever::pinNamed(std::string query, std::string name) {
std::string Qlever::pinNamed(std::string query, std::string name,
ad_utility::MediaType mediaType) {
QueryExecutionContext qec{index_, &cache_, allocator_,
sortPerformanceEstimator_, &namedQueryCache_};
qec.pinWithExplicitName() = std::move(name);
Expand Down Expand Up @@ -191,12 +190,11 @@ void Qlever::pinNamed(std::string query, std::string name) {

ad_utility::Timer timer{ad_utility::Timer::Started};
auto responseGenerator = ExportQueryExecutionTrees::computeResult(
parsedQuery, qet, ad_utility::MediaType::sparqlJson, timer,
std::move(handle));
parsedQuery, qet, mediaType, timer, std::move(handle));
std::string result;
std::cout << "Writing the result:" << std::endl;
for (const auto& batch : responseGenerator) {
result += batch;
}
return result;
}
} // namespace qlever
7 changes: 5 additions & 2 deletions src/libqlever/Qlever.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ class Qlever {
// supported, and the result will always be in sparql-results+json format.
// TODO<joka921> Support other formats + CONSTRUCT queries, support
// cancellation, time limits, and observable queries.
std::string query(std::string query);
std::string query(std::string query, ad_utility::MediaType mediaType =
ad_utility::MediaType::sparqlJson);

// Pin a query to the named query cache. In a subsequent query, this cache can
// be accessed via `SERVICE ql:
void pinNamed(std::string query, std::string name);
[[maybe_unused]] std::string pinNamed(
std::string query, std::string name,
ad_utility::MediaType mediaType = ad_utility::MediaType::sparqlJson);

// TODO<joka921> Give access to the RuntimeParameters() which allow for
// further tweaking of the qlever instance.
Expand Down

0 comments on commit c0b7a44

Please sign in to comment.